• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 3929938005

pending completion
3929938005

push

github

GitHub
Merge #713

84930 of 96741 relevant lines covered (87.79%)

79640.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.18
/operators/src/engine/operator.rs
1
use serde::{Deserialize, Serialize};
2

3
use crate::error;
4
use crate::util::Result;
5
use async_trait::async_trait;
6
use geoengine_datatypes::dataset::DataId;
7

8
use super::{
9
    query_processor::{TypedRasterQueryProcessor, TypedVectorQueryProcessor},
10
    CloneablePlotOperator, CloneableRasterOperator, CloneableVectorOperator, CreateSpan,
11
    ExecutionContext, PlotResultDescriptor, RasterResultDescriptor, TypedPlotQueryProcessor,
12
    VectorResultDescriptor,
13
};
14

15
pub trait OperatorData {
16
    /// Get the ids of all the data involoved in this operator and its sources
17
    fn data_ids(&self) -> Vec<DataId> {
2✔
18
        let mut datasets = vec![];
2✔
19
        self.data_ids_collect(&mut datasets);
2✔
20
        datasets
2✔
21
    }
2✔
22

23
    fn data_ids_collect(&self, data_ids: &mut Vec<DataId>);
24
}
25

26
/// Common methods for `RasterOperator`s
27
#[typetag::serde(tag = "type")]
36✔
28
#[async_trait]
29
pub trait RasterOperator:
30
    CloneableRasterOperator + OperatorData + Send + Sync + std::fmt::Debug
31
{
32
    /// Internal initialization logic of the operator
33
    async fn _initialize(
34
        self: Box<Self>,
35
        context: &dyn ExecutionContext,
36
    ) -> Result<Box<dyn InitializedRasterOperator>>;
37

38
    /// Initialize the operator
39
    ///
40
    /// This method should not be overriden because it handles wrapping the operator using the
41
    /// execution context. Instead, `_initialize` should be implemented.
42
    async fn initialize(
268✔
43
        self: Box<Self>,
268✔
44
        context: &dyn ExecutionContext,
268✔
45
    ) -> Result<Box<dyn InitializedRasterOperator>> {
268✔
46
        let span = self.span();
268✔
47
        let op = self._initialize(context).await?;
268✔
48
        Ok(context.wrap_initialized_raster_operator(op, span))
259✔
49
    }
536✔
50

51
    /// Wrap a box around a `RasterOperator`
52
    fn boxed(self) -> Box<dyn RasterOperator>
380✔
53
    where
380✔
54
        Self: Sized + 'static,
380✔
55
    {
380✔
56
        Box::new(self)
380✔
57
    }
380✔
58

59
    fn span(&self) -> CreateSpan;
60
}
61

62
/// Common methods for `VectorOperator`s
63
#[typetag::serde(tag = "type")]
56✔
64
#[async_trait]
65
pub trait VectorOperator:
66
    CloneableVectorOperator + OperatorData + Send + Sync + std::fmt::Debug
67
{
68
    async fn _initialize(
69
        self: Box<Self>,
70
        context: &dyn ExecutionContext,
71
    ) -> Result<Box<dyn InitializedVectorOperator>>;
72

73
    async fn initialize(
159✔
74
        self: Box<Self>,
159✔
75
        context: &dyn ExecutionContext,
159✔
76
    ) -> Result<Box<dyn InitializedVectorOperator>> {
159✔
77
        let span = self.span();
159✔
78
        let op = self._initialize(context).await?;
159✔
79
        Ok(context.wrap_initialized_vector_operator(op, span))
155✔
80
    }
318✔
81

82
    /// Wrap a box around a `VectorOperator`
83
    fn boxed(self) -> Box<dyn VectorOperator>
202✔
84
    where
202✔
85
        Self: Sized + 'static,
202✔
86
    {
202✔
87
        Box::new(self)
202✔
88
    }
202✔
89

90
    fn span(&self) -> CreateSpan;
91
}
92

93
/// Common methods for `PlotOperator`s
94
#[typetag::serde(tag = "type")]
8✔
95
#[async_trait]
96
pub trait PlotOperator:
97
    CloneablePlotOperator + OperatorData + Send + Sync + std::fmt::Debug
98
{
99
    async fn _initialize(
100
        self: Box<Self>,
101
        context: &dyn ExecutionContext,
102
    ) -> Result<Box<dyn InitializedPlotOperator>>;
103

104
    async fn initialize(
66✔
105
        self: Box<Self>,
66✔
106
        context: &dyn ExecutionContext,
66✔
107
    ) -> Result<Box<dyn InitializedPlotOperator>> {
66✔
108
        let span = self.span();
66✔
109
        let op = self._initialize(context).await?;
66✔
110
        Ok(context.wrap_initialized_plot_operator(op, span))
55✔
111
    }
132✔
112

113
    /// Wrap a box around a `PlotOperator`
114
    fn boxed(self) -> Box<dyn PlotOperator>
76✔
115
    where
76✔
116
        Self: Sized + 'static,
76✔
117
    {
76✔
118
        Box::new(self)
76✔
119
    }
76✔
120

121
    fn span(&self) -> CreateSpan;
122
}
123

124
pub trait InitializedRasterOperator: Send + Sync {
125
    /// Get the result descriptor of the `Operator`
126
    fn result_descriptor(&self) -> &RasterResultDescriptor;
127

128
    /// Instantiate a `TypedVectorQueryProcessor` from a `RasterOperator`
129
    fn query_processor(&self) -> Result<TypedRasterQueryProcessor>;
130

131
    /// Wrap a box around a `RasterOperator`
132
    fn boxed(self) -> Box<dyn InitializedRasterOperator>
255✔
133
    where
255✔
134
        Self: Sized + 'static,
255✔
135
    {
255✔
136
        Box::new(self)
255✔
137
    }
255✔
138
}
139

140
pub trait InitializedVectorOperator: Send + Sync {
141
    /// Get the result descriptor of the `Operator`
142
    fn result_descriptor(&self) -> &VectorResultDescriptor;
143

144
    /// Instantiate a `TypedVectorQueryProcessor` from a `RasterOperator`
145
    fn query_processor(&self) -> Result<TypedVectorQueryProcessor>;
146

147
    /// Wrap a box around a `RasterOperator`
148
    fn boxed(self) -> Box<dyn InitializedVectorOperator>
153✔
149
    where
153✔
150
        Self: Sized + 'static,
153✔
151
    {
153✔
152
        Box::new(self)
153✔
153
    }
153✔
154
}
155

156
pub trait InitializedPlotOperator: Send + Sync {
157
    /// Get the result descriptor of the `Operator`
158
    fn result_descriptor(&self) -> &PlotResultDescriptor;
159

160
    /// Instantiate a `TypedVectorQueryProcessor` from a `RasterOperator`
161
    fn query_processor(&self) -> Result<TypedPlotQueryProcessor>;
162

163
    /// Wrap a box around a `RasterOperator`
164
    fn boxed(self) -> Box<dyn InitializedPlotOperator>
55✔
165
    where
55✔
166
        Self: Sized + 'static,
55✔
167
    {
55✔
168
        Box::new(self)
55✔
169
    }
55✔
170
}
171

172
impl InitializedRasterOperator for Box<dyn InitializedRasterOperator> {
173
    fn result_descriptor(&self) -> &RasterResultDescriptor {
167✔
174
        self.as_ref().result_descriptor()
167✔
175
    }
167✔
176

177
    fn query_processor(&self) -> Result<TypedRasterQueryProcessor> {
176✔
178
        self.as_ref().query_processor()
176✔
179
    }
176✔
180
}
181

182
impl InitializedVectorOperator for Box<dyn InitializedVectorOperator> {
183
    fn result_descriptor(&self) -> &VectorResultDescriptor {
165✔
184
        self.as_ref().result_descriptor()
165✔
185
    }
165✔
186

187
    fn query_processor(&self) -> Result<TypedVectorQueryProcessor> {
116✔
188
        self.as_ref().query_processor()
116✔
189
    }
116✔
190
}
191

192
impl InitializedPlotOperator for Box<dyn InitializedPlotOperator> {
193
    fn result_descriptor(&self) -> &PlotResultDescriptor {
×
194
        self.as_ref().result_descriptor()
×
195
    }
×
196

197
    fn query_processor(&self) -> Result<TypedPlotQueryProcessor> {
51✔
198
        self.as_ref().query_processor()
51✔
199
    }
51✔
200
}
201

202
/// An enum to differentiate between `Operator` variants
203
#[derive(Clone, Debug, Serialize, Deserialize)]
128✔
204
#[serde(tag = "type", content = "operator")]
205
pub enum TypedOperator {
206
    Vector(Box<dyn VectorOperator>),
207
    Raster(Box<dyn RasterOperator>),
208
    Plot(Box<dyn PlotOperator>),
209
}
210

211
impl TypedOperator {
212
    pub fn get_vector(self) -> Result<Box<dyn VectorOperator>> {
213
        if let TypedOperator::Vector(o) = self {
4✔
214
            return Ok(o);
4✔
215
        }
×
216
        Err(error::Error::InvalidOperatorType {
×
217
            expected: "Vector".to_owned(),
×
218
            found: self.type_name().to_owned(),
×
219
        })
×
220
    }
4✔
221

222
    pub fn get_raster(self) -> Result<Box<dyn RasterOperator>> {
223
        if let TypedOperator::Raster(o) = self {
11✔
224
            return Ok(o);
11✔
225
        }
×
226
        Err(error::Error::InvalidOperatorType {
×
227
            expected: "Raster".to_owned(),
×
228
            found: self.type_name().to_owned(),
×
229
        })
×
230
    }
11✔
231

232
    pub fn get_plot(self) -> Result<Box<dyn PlotOperator>> {
233
        if let TypedOperator::Plot(o) = self {
2✔
234
            return Ok(o);
2✔
235
        }
×
236
        Err(error::Error::InvalidOperatorType {
×
237
            expected: "Plot".to_owned(),
×
238
            found: self.type_name().to_owned(),
×
239
        })
×
240
    }
2✔
241

242
    fn type_name(&self) -> &str {
×
243
        match self {
×
244
            TypedOperator::Vector(_) => "Vector",
×
245
            TypedOperator::Raster(_) => "Raster",
×
246
            TypedOperator::Plot(_) => "Plot",
×
247
        }
248
    }
×
249
}
250

251
impl From<Box<dyn VectorOperator>> for TypedOperator {
252
    fn from(operator: Box<dyn VectorOperator>) -> Self {
22✔
253
        Self::Vector(operator)
22✔
254
    }
22✔
255
}
256

257
impl From<Box<dyn RasterOperator>> for TypedOperator {
258
    fn from(operator: Box<dyn RasterOperator>) -> Self {
1✔
259
        Self::Raster(operator)
1✔
260
    }
1✔
261
}
262

263
impl From<Box<dyn PlotOperator>> for TypedOperator {
264
    fn from(operator: Box<dyn PlotOperator>) -> Self {
13✔
265
        Self::Plot(operator)
13✔
266
    }
13✔
267
}
268

269
/// An enum to differentiate between `InitializedOperator` variants
270
pub enum TypedInitializedOperator {
271
    Vector(Box<dyn InitializedVectorOperator>),
272
    Raster(Box<dyn InitializedRasterOperator>),
273
    Plot(Box<dyn InitializedPlotOperator>),
274
}
275

276
impl From<Box<dyn InitializedVectorOperator>> for TypedInitializedOperator {
277
    fn from(operator: Box<dyn InitializedVectorOperator>) -> Self {
×
278
        TypedInitializedOperator::Vector(operator)
×
279
    }
×
280
}
281

282
impl From<Box<dyn InitializedRasterOperator>> for TypedInitializedOperator {
283
    fn from(operator: Box<dyn InitializedRasterOperator>) -> Self {
×
284
        TypedInitializedOperator::Raster(operator)
×
285
    }
×
286
}
287

288
impl From<Box<dyn InitializedPlotOperator>> for TypedInitializedOperator {
289
    fn from(operator: Box<dyn InitializedPlotOperator>) -> Self {
×
290
        TypedInitializedOperator::Plot(operator)
×
291
    }
×
292
}
293

294
#[macro_export]
295
macro_rules! call_on_typed_operator {
296
    ($typed_operator:expr, $operator_var:ident => $function_call:expr) => {
297
        match $typed_operator {
298
            $crate::engine::TypedOperator::Vector($operator_var) => $function_call,
299
            $crate::engine::TypedOperator::Raster($operator_var) => $function_call,
300
            $crate::engine::TypedOperator::Plot($operator_var) => $function_call,
301
        }
302
    };
303
}
304

305
impl OperatorData for TypedOperator {
306
    fn data_ids_collect(&self, data_ids: &mut Vec<DataId>) {
2✔
307
        match self {
2✔
308
            TypedOperator::Vector(v) => v.data_ids_collect(data_ids),
×
309
            TypedOperator::Raster(r) => r.data_ids_collect(data_ids),
2✔
310
            TypedOperator::Plot(p) => p.data_ids_collect(data_ids),
×
311
        }
312
    }
2✔
313
}
314

315
pub trait OperatorName {
316
    const TYPE_NAME: &'static str;
317
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc