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

geo-engine / geoengine / 6629739953

24 Oct 2023 04:24PM UTC coverage: 89.498% (+0.003%) from 89.495%
6629739953

push

github

web-flow
Merge pull request #889 from geo-engine/array-impls

add array-impls to postgres-types

109191 of 122004 relevant lines covered (89.5%)

59523.28 hits per line

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

98.12
/services/src/contexts/postgres.rs
1
use super::migrations::{all_migrations, migrate_database, MigrationResult};
2
use super::{ExecutionContextImpl, Session, SimpleApplicationContext};
3
use crate::api::cli::{add_datasets_from_directory, add_providers_from_directory};
4
use crate::contexts::{ApplicationContext, QueryContextImpl, SessionId, SimpleSession};
5
use crate::contexts::{GeoEngineDb, SessionContext};
6
use crate::datasets::upload::{Volume, Volumes};
7
use crate::datasets::DatasetName;
8
use crate::error::{self, Error, Result};
9
use crate::layers::add_from_directory::{
10
    add_layer_collections_from_directory, add_layers_from_directory,
11
};
12
use crate::projects::{ProjectId, STRectangle};
13
use crate::tasks::{SimpleTaskManager, SimpleTaskManagerBackend, SimpleTaskManagerContext};
14
use crate::util::config;
15
use crate::util::config::get_config_element;
16
use async_trait::async_trait;
17
use bb8_postgres::{
18
    bb8::Pool,
19
    bb8::PooledConnection,
20
    tokio_postgres::{error::SqlState, tls::MakeTlsConnect, tls::TlsConnect, Config, Socket},
21
    PostgresConnectionManager,
22
};
23
use geoengine_datatypes::raster::TilingSpecification;
24
use geoengine_operators::engine::ChunkByteSize;
25
use geoengine_operators::util::create_rayon_thread_pool;
26
use log::info;
27
use rayon::ThreadPool;
28
use snafu::ensure;
29
use std::path::PathBuf;
30
use std::sync::Arc;
31

32
// TODO: distinguish user-facing errors from system-facing error messages
33

34
/// A context with references to Postgres backends of the database.
35
#[derive(Clone)]
717✔
36
pub struct PostgresContext<Tls>
37
where
38
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
39
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
40
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
41
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
42
{
43
    default_session_id: SessionId,
44
    thread_pool: Arc<ThreadPool>,
45
    exe_ctx_tiling_spec: TilingSpecification,
46
    query_ctx_chunk_size: ChunkByteSize,
47
    task_manager: Arc<SimpleTaskManagerBackend>,
48
    pool: Pool<PostgresConnectionManager<Tls>>,
49
    volumes: Volumes,
50
}
51

52
enum DatabaseStatus {
53
    Unitialized,
54
    InitializedClearDatabase,
55
    InitializedKeepDatabase,
56
}
57

58
impl<Tls> PostgresContext<Tls>
59
where
60
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
61
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
62
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
63
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
64
{
65
    pub async fn new_with_context_spec(
136✔
66
        config: Config,
136✔
67
        tls: Tls,
136✔
68
        exe_ctx_tiling_spec: TilingSpecification,
136✔
69
        query_ctx_chunk_size: ChunkByteSize,
136✔
70
    ) -> Result<Self> {
136✔
71
        let pg_mgr = PostgresConnectionManager::new(config, tls);
136✔
72

73
        let pool = Pool::builder().build(pg_mgr).await?;
136✔
74
        let created_schema = Self::create_database(pool.get().await?).await?;
2,312✔
75

76
        let session = if created_schema {
136✔
77
            let session = SimpleSession::default();
136✔
78
            Self::create_default_session(pool.get().await?, session.id()).await?;
272✔
79
            session
136✔
80
        } else {
81
            Self::load_default_session(pool.get().await?).await?
×
82
        };
83

84
        Ok(PostgresContext {
136✔
85
            default_session_id: session.id(),
136✔
86
            task_manager: Default::default(),
136✔
87
            thread_pool: create_rayon_thread_pool(0),
136✔
88
            exe_ctx_tiling_spec,
136✔
89
            query_ctx_chunk_size,
136✔
90
            pool,
136✔
91
            volumes: Default::default(),
136✔
92
        })
136✔
93
    }
136✔
94

95
    // TODO: check if the datasets exist already and don't output warnings when skipping them
96
    #[allow(clippy::too_many_arguments)]
97
    pub async fn new_with_data(
×
98
        config: Config,
×
99
        tls: Tls,
×
100
        dataset_defs_path: PathBuf,
×
101
        provider_defs_path: PathBuf,
×
102
        layer_defs_path: PathBuf,
×
103
        layer_collection_defs_path: PathBuf,
×
104
        exe_ctx_tiling_spec: TilingSpecification,
×
105
        query_ctx_chunk_size: ChunkByteSize,
×
106
    ) -> Result<Self> {
×
107
        let pg_mgr = PostgresConnectionManager::new(config, tls);
×
108

109
        let pool = Pool::builder().build(pg_mgr).await?;
×
110
        let created_schema = Self::create_database(pool.get().await?).await?;
×
111

112
        let session = if created_schema {
×
113
            let session = SimpleSession::default();
×
114
            Self::create_default_session(pool.get().await?, session.id()).await?;
×
115
            session
×
116
        } else {
117
            Self::load_default_session(pool.get().await?).await?
×
118
        };
119

120
        let app_ctx = PostgresContext {
×
121
            default_session_id: session.id(),
×
122
            task_manager: Default::default(),
×
123
            thread_pool: create_rayon_thread_pool(0),
×
124
            exe_ctx_tiling_spec,
×
125
            query_ctx_chunk_size,
×
126
            pool,
×
127
            volumes: Default::default(),
×
128
        };
×
129

×
130
        if created_schema {
×
131
            info!("Populating database with initial data...");
×
132

133
            let ctx = app_ctx.session_context(session);
×
134

×
135
            let mut db = ctx.db();
×
136
            add_layers_from_directory(&mut db, layer_defs_path).await;
×
137
            add_layer_collections_from_directory(&mut db, layer_collection_defs_path).await;
×
138

139
            add_datasets_from_directory(&mut db, dataset_defs_path).await;
×
140

141
            add_providers_from_directory(&mut db, provider_defs_path).await;
×
142
        }
×
143

144
        Ok(app_ctx)
×
145
    }
×
146

147
    async fn check_schema_status(
218✔
148
        conn: &PooledConnection<'_, PostgresConnectionManager<Tls>>,
218✔
149
    ) -> Result<DatabaseStatus> {
218✔
150
        let stmt = match conn
218✔
151
            .prepare("SELECT clear_database_on_start from geoengine;")
218✔
152
            .await
218✔
153
        {
154
            Ok(stmt) => stmt,
×
155
            Err(e) => {
218✔
156
                if let Some(code) = e.code() {
218✔
157
                    if *code == SqlState::UNDEFINED_TABLE {
218✔
158
                        info!("Initializing schema.");
×
159
                        return Ok(DatabaseStatus::Unitialized);
218✔
160
                    }
×
161
                }
×
162
                return Err(error::Error::TokioPostgres { source: e });
×
163
            }
164
        };
165

166
        let row = conn.query_one(&stmt, &[]).await?;
×
167

168
        if row.get(0) {
×
169
            Ok(DatabaseStatus::InitializedClearDatabase)
×
170
        } else {
171
            Ok(DatabaseStatus::InitializedKeepDatabase)
×
172
        }
173
    }
218✔
174

175
    /// Clears the database if the Settings demand and the database properties allows it.
176
    pub(crate) async fn maybe_clear_database(
218✔
177
        conn: &PooledConnection<'_, PostgresConnectionManager<Tls>>,
218✔
178
    ) -> Result<()> {
218✔
179
        let postgres_config = get_config_element::<crate::util::config::Postgres>()?;
218✔
180
        let database_status = Self::check_schema_status(conn).await?;
218✔
181
        let schema_name = postgres_config.schema;
218✔
182

183
        match database_status {
×
184
            DatabaseStatus::InitializedClearDatabase
×
185
                if postgres_config.clear_database_on_start && schema_name != "pg_temp" =>
×
186
            {
187
                info!("Clearing schema {}.", schema_name);
×
188
                conn.batch_execute(&format!("DROP SCHEMA {schema_name} CASCADE;"))
×
189
                    .await?;
×
190
            }
191
            DatabaseStatus::InitializedKeepDatabase if postgres_config.clear_database_on_start => {
×
192
                return Err(Error::ClearDatabaseOnStartupNotAllowed)
×
193
            }
194
            DatabaseStatus::InitializedClearDatabase
195
            | DatabaseStatus::InitializedKeepDatabase
196
            | DatabaseStatus::Unitialized => (),
218✔
197
        };
198

199
        Ok(())
218✔
200
    }
218✔
201

202
    /// Creates the database schema. Returns true if the schema was created, false if it already existed.
203
    pub(crate) async fn create_database(
136✔
204
        mut conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
136✔
205
    ) -> Result<bool> {
136✔
206
        Self::maybe_clear_database(&conn).await?;
136✔
207

208
        let migration = migrate_database(&mut conn, &all_migrations()).await?;
2,176✔
209

210
        Ok(migration == MigrationResult::CreatedDatabase)
136✔
211
    }
136✔
212

213
    async fn create_default_session(
136✔
214
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
136✔
215
        session_id: SessionId,
136✔
216
    ) -> Result<()> {
136✔
217
        let stmt = conn
136✔
218
            .prepare("INSERT INTO sessions (id, project_id, view) VALUES ($1, NULL ,NULL);")
136✔
219
            .await?;
136✔
220

221
        conn.execute(&stmt, &[&session_id]).await?;
136✔
222

223
        Ok(())
136✔
224
    }
136✔
225
    async fn load_default_session(
66✔
226
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
66✔
227
    ) -> Result<SimpleSession> {
66✔
228
        let stmt = conn
66✔
229
            .prepare("SELECT id, project_id, view FROM sessions LIMIT 1;")
66✔
230
            .await?;
375✔
231

232
        let row = conn.query_one(&stmt, &[]).await?;
66✔
233

234
        Ok(SimpleSession::new(row.get(0), row.get(1), row.get(2)))
66✔
235
    }
66✔
236
}
237

238
#[async_trait]
239
impl<Tls> SimpleApplicationContext for PostgresContext<Tls>
240
where
241
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
242
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
243
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
244
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
245
{
246
    async fn default_session_id(&self) -> SessionId {
78✔
247
        self.default_session_id
78✔
248
    }
78✔
249

250
    async fn default_session(&self) -> Result<SimpleSession> {
66✔
251
        Self::load_default_session(self.pool.get().await?).await
435✔
252
    }
132✔
253

254
    async fn update_default_session_project(&self, project: ProjectId) -> Result<()> {
1✔
255
        let conn = self.pool.get().await?;
1✔
256

257
        let stmt = conn
1✔
258
            .prepare("UPDATE sessions SET project_id = $1 WHERE id = $2;")
1✔
259
            .await?;
1✔
260

261
        conn.execute(&stmt, &[&project, &self.default_session_id])
1✔
262
            .await?;
1✔
263

264
        Ok(())
1✔
265
    }
2✔
266

267
    async fn update_default_session_view(&self, view: STRectangle) -> Result<()> {
1✔
268
        let conn = self.pool.get().await?;
1✔
269

270
        let stmt = conn
1✔
271
            .prepare("UPDATE sessions SET view = $1 WHERE id = $2;")
1✔
272
            .await?;
×
273

274
        conn.execute(&stmt, &[&view, &self.default_session_id])
1✔
275
            .await?;
1✔
276

277
        Ok(())
1✔
278
    }
2✔
279

280
    async fn default_session_context(&self) -> Result<Self::SessionContext> {
273✔
281
        Ok(self.session_context(self.session_by_id(self.default_session_id).await?))
2,479✔
282
    }
546✔
283
}
284

285
#[async_trait]
286
impl<Tls> ApplicationContext for PostgresContext<Tls>
287
where
288
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
289
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
290
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
291
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
292
{
293
    type SessionContext = PostgresSessionContext<Tls>;
294
    type Session = SimpleSession;
295

296
    fn session_context(&self, session: Self::Session) -> Self::SessionContext {
437✔
297
        PostgresSessionContext {
437✔
298
            session,
437✔
299
            context: self.clone(),
437✔
300
        }
437✔
301
    }
437✔
302

303
    async fn session_by_id(&self, session_id: SessionId) -> Result<Self::Session> {
375✔
304
        let mut conn = self.pool.get().await?;
375✔
305

306
        let tx = conn.build_transaction().start().await?;
370✔
307

308
        let stmt = tx
369✔
309
            .prepare(
369✔
310
                "
369✔
311
            SELECT           
369✔
312
                project_id,
369✔
313
                view
369✔
314
            FROM sessions
369✔
315
            WHERE id = $1;",
369✔
316
            )
369✔
317
            .await?;
1,934✔
318

319
        let row = tx
369✔
320
            .query_one(&stmt, &[&session_id])
369✔
321
            .await
291✔
322
            .map_err(|_error| error::Error::InvalidSession)?;
369✔
323

324
        Ok(SimpleSession::new(session_id, row.get(0), row.get(1)))
369✔
325
    }
744✔
326
}
327

328
#[derive(Clone)]
×
329
pub struct PostgresSessionContext<Tls>
330
where
331
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
332
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
333
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
334
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
335
{
336
    session: SimpleSession,
337
    context: PostgresContext<Tls>,
338
}
339

340
#[async_trait]
341
impl<Tls> SessionContext for PostgresSessionContext<Tls>
342
where
343
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
344
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
345
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
346
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
347
{
348
    type Session = SimpleSession;
349
    type GeoEngineDB = PostgresDb<Tls>;
350

351
    type TaskContext = SimpleTaskManagerContext;
352
    type TaskManager = SimpleTaskManager; // this does not persist across restarts
353
    type QueryContext = QueryContextImpl;
354
    type ExecutionContext = ExecutionContextImpl<Self::GeoEngineDB>;
355

356
    fn db(&self) -> Self::GeoEngineDB {
440✔
357
        PostgresDb::new(self.context.pool.clone())
440✔
358
    }
440✔
359

360
    fn tasks(&self) -> Self::TaskManager {
36✔
361
        SimpleTaskManager::new(self.context.task_manager.clone())
36✔
362
    }
36✔
363

364
    fn query_context(&self) -> Result<Self::QueryContext> {
27✔
365
        Ok(QueryContextImpl::new(
27✔
366
            self.context.query_ctx_chunk_size,
27✔
367
            self.context.thread_pool.clone(),
27✔
368
        ))
27✔
369
    }
27✔
370

371
    fn execution_context(&self) -> Result<Self::ExecutionContext> {
46✔
372
        Ok(ExecutionContextImpl::<PostgresDb<Tls>>::new(
46✔
373
            self.db(),
46✔
374
            self.context.thread_pool.clone(),
46✔
375
            self.context.exe_ctx_tiling_spec,
46✔
376
        ))
46✔
377
    }
46✔
378

379
    fn volumes(&self) -> Result<Vec<Volume>> {
×
380
        Ok(self.context.volumes.volumes.clone())
×
381
    }
×
382

383
    fn session(&self) -> &Self::Session {
110✔
384
        &self.session
110✔
385
    }
110✔
386
}
387

388
pub struct PostgresDb<Tls>
389
where
390
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
391
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
392
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
393
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
394
{
395
    pub(crate) conn_pool: Pool<PostgresConnectionManager<Tls>>,
396
}
397

398
impl<Tls> PostgresDb<Tls>
399
where
400
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
401
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
402
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
403
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
404
{
405
    pub fn new(conn_pool: Pool<PostgresConnectionManager<Tls>>) -> Self {
441✔
406
        Self { conn_pool }
441✔
407
    }
441✔
408

409
    /// Check whether the namespace of the given dataset is allowed for insertion
410
    pub(crate) fn check_namespace(id: &DatasetName) -> Result<()> {
68✔
411
        // due to a lack of users, etc., we only allow one namespace for now
68✔
412
        if id.namespace.is_none() {
68✔
413
            Ok(())
68✔
414
        } else {
415
            Err(Error::InvalidDatasetIdNamespace)
×
416
        }
417
    }
68✔
418
}
419

420
impl<Tls> GeoEngineDb for PostgresDb<Tls>
421
where
422
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
423
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
424
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
425
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
426
{
427
}
428

429
impl TryFrom<config::Postgres> for Config {
430
    type Error = Error;
431

432
    fn try_from(db_config: config::Postgres) -> Result<Self> {
6✔
433
        ensure!(
6✔
434
            db_config.schema != "public",
6✔
435
            crate::error::InvalidDatabaseSchema
×
436
        );
437

438
        let mut pg_config = Config::new();
6✔
439
        pg_config
6✔
440
            .user(&db_config.user)
6✔
441
            .password(&db_config.password)
6✔
442
            .host(&db_config.host)
6✔
443
            .dbname(&db_config.database)
6✔
444
            .port(db_config.port)
6✔
445
            // fix schema by providing `search_path` option
6✔
446
            .options(&format!("-c search_path={}", db_config.schema));
6✔
447
        Ok(pg_config)
6✔
448
    }
6✔
449
}
450

451
#[cfg(test)]
452
mod tests {
453
    use super::*;
454
    use crate::datasets::external::aruna::ArunaDataProviderDefinition;
455
    use crate::datasets::external::gbif::GbifDataProviderDefinition;
456
    use crate::datasets::external::gfbio_abcd::GfbioAbcdDataProviderDefinition;
457
    use crate::datasets::external::gfbio_collections::GfbioCollectionsDataProviderDefinition;
458
    use crate::datasets::external::netcdfcf::{
459
        EbvPortalDataProviderDefinition, NetCdfCfDataProviderDefinition,
460
    };
461
    use crate::datasets::external::pangaea::PangaeaDataProviderDefinition;
462
    use crate::datasets::listing::{DatasetListOptions, DatasetListing, ProvenanceOutput};
463
    use crate::datasets::listing::{DatasetProvider, Provenance};
464
    use crate::datasets::storage::{DatasetStore, MetaDataDefinition};
465
    use crate::datasets::upload::{FileId, UploadId};
466
    use crate::datasets::upload::{FileUpload, Upload, UploadDb};
467
    use crate::datasets::{AddDataset, DatasetIdAndName};
468
    use crate::ge_context;
469
    use crate::layers::add_from_directory::UNSORTED_COLLECTION_ID;
470
    use crate::layers::external::TypedDataProviderDefinition;
471
    use crate::layers::layer::{
472
        AddLayer, AddLayerCollection, CollectionItem, LayerCollection, LayerCollectionListOptions,
473
        LayerCollectionListing, LayerListing, Property, ProviderLayerCollectionId, ProviderLayerId,
474
    };
475
    use crate::layers::listing::{LayerCollectionId, LayerCollectionProvider};
476
    use crate::layers::storage::{
477
        LayerDb, LayerProviderDb, LayerProviderListing, LayerProviderListingOptions,
478
        INTERNAL_PROVIDER_ID,
479
    };
480
    use crate::projects::{
481
        ColorParam, CreateProject, DerivedColor, DerivedNumber, LayerUpdate, LineSymbology,
482
        LoadVersion, NumberParam, OrderBy, Plot, PlotUpdate, PointSymbology, PolygonSymbology,
483
        ProjectDb, ProjectId, ProjectLayer, ProjectListOptions, ProjectListing, RasterSymbology,
484
        STRectangle, StrokeParam, Symbology, TextSymbology, UpdateProject,
485
    };
486
    use crate::util::postgres::{assert_sql_type, DatabaseConnectionConfig};
487
    use crate::util::tests::register_ndvi_workflow_helper;
488
    use crate::workflows::registry::WorkflowRegistry;
489
    use crate::workflows::workflow::Workflow;
490
    use bb8_postgres::tokio_postgres::NoTls;
491
    use futures::join;
492
    use geoengine_datatypes::collections::VectorDataType;
493
    use geoengine_datatypes::dataset::{DataProviderId, LayerId};
494
    use geoengine_datatypes::operations::image::{Breakpoint, Colorizer, DefaultColors, RgbaColor};
495
    use geoengine_datatypes::primitives::{
496
        BoundingBox2D, ClassificationMeasurement, ContinuousMeasurement, Coordinate2D,
497
        DateTimeParseFormat, FeatureDataType, MultiLineString, MultiPoint, MultiPolygon,
498
        NoGeometry, RasterQueryRectangle, SpatialPartition2D, SpatialResolution, TimeGranularity,
499
        TimeInstance, TimeInterval, TimeStep, TypedGeometry, VectorQueryRectangle,
500
    };
501
    use geoengine_datatypes::primitives::{CacheTtlSeconds, Measurement};
502
    use geoengine_datatypes::raster::{
503
        RasterDataType, RasterPropertiesEntryType, RasterPropertiesKey,
504
    };
505
    use geoengine_datatypes::spatial_reference::{SpatialReference, SpatialReferenceOption};
506
    use geoengine_datatypes::test_data;
507
    use geoengine_datatypes::util::{NotNanF64, StringPair};
508
    use geoengine_operators::engine::{
509
        MetaData, MetaDataProvider, MultipleRasterOrSingleVectorSource, PlotOperator,
510
        PlotResultDescriptor, RasterResultDescriptor, StaticMetaData, TypedOperator,
511
        TypedResultDescriptor, VectorColumnInfo, VectorOperator, VectorResultDescriptor,
512
    };
513
    use geoengine_operators::mock::{
514
        MockDatasetDataSourceLoadingInfo, MockPointSource, MockPointSourceParams,
515
    };
516
    use geoengine_operators::plot::{Statistics, StatisticsParams};
517
    use geoengine_operators::source::{
518
        CsvHeader, FileNotFoundHandling, FormatSpecifics, GdalDatasetGeoTransform,
519
        GdalDatasetParameters, GdalLoadingInfo, GdalLoadingInfoTemporalSlice, GdalMetaDataList,
520
        GdalMetaDataRegular, GdalMetaDataStatic, GdalMetadataMapping, GdalMetadataNetCdfCf,
521
        GdalRetryOptions, GdalSourceTimePlaceholder, OgrSourceColumnSpec, OgrSourceDataset,
522
        OgrSourceDatasetTimeType, OgrSourceDurationSpec, OgrSourceErrorSpec, OgrSourceTimeFormat,
523
        TimeReference, UnixTimeStampType,
524
    };
525
    use geoengine_operators::util::input::MultiRasterOrVectorOperator::Raster;
526
    use ordered_float::NotNan;
527
    use serde_json::json;
528
    use std::marker::PhantomData;
529
    use std::str::FromStr;
530
    use tokio_postgres::config::Host;
531

532
    #[ge_context::test]
2✔
533
    async fn test(app_ctx: PostgresContext<NoTls>) {
1✔
534
        let session = app_ctx.default_session().await.unwrap();
18✔
535

1✔
536
        create_projects(&app_ctx, &session).await;
74✔
537

538
        let projects = list_projects(&app_ctx, &session).await;
14✔
539

540
        let project_id = projects[0].id;
1✔
541

1✔
542
        update_projects(&app_ctx, &session, project_id).await;
164✔
543

544
        delete_project(&app_ctx, &session, project_id).await;
7✔
545
    }
1✔
546

547
    async fn delete_project(
1✔
548
        app_ctx: &PostgresContext<NoTls>,
1✔
549
        session: &SimpleSession,
1✔
550
        project_id: ProjectId,
1✔
551
    ) {
1✔
552
        let db = app_ctx.session_context(session.clone()).db();
1✔
553

1✔
554
        db.delete_project(project_id).await.unwrap();
3✔
555

1✔
556
        assert!(db.load_project(project_id).await.is_err());
4✔
557
    }
1✔
558

559
    #[allow(clippy::too_many_lines)]
560
    async fn update_projects(
1✔
561
        app_ctx: &PostgresContext<NoTls>,
1✔
562
        session: &SimpleSession,
1✔
563
        project_id: ProjectId,
1✔
564
    ) {
1✔
565
        let db = app_ctx.session_context(session.clone()).db();
1✔
566

567
        let project = db
1✔
568
            .load_project_version(project_id, LoadVersion::Latest)
1✔
569
            .await
39✔
570
            .unwrap();
1✔
571

572
        let layer_workflow_id = db
1✔
573
            .register_workflow(Workflow {
1✔
574
                operator: TypedOperator::Vector(
1✔
575
                    MockPointSource {
1✔
576
                        params: MockPointSourceParams {
1✔
577
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
578
                        },
1✔
579
                    }
1✔
580
                    .boxed(),
1✔
581
                ),
1✔
582
            })
1✔
583
            .await
3✔
584
            .unwrap();
1✔
585

1✔
586
        assert!(db.load_workflow(&layer_workflow_id).await.is_ok());
3✔
587

588
        let plot_workflow_id = db
1✔
589
            .register_workflow(Workflow {
1✔
590
                operator: Statistics {
1✔
591
                    params: StatisticsParams {
1✔
592
                        column_names: vec![],
1✔
593
                    },
1✔
594
                    sources: MultipleRasterOrSingleVectorSource {
1✔
595
                        source: Raster(vec![]),
1✔
596
                    },
1✔
597
                }
1✔
598
                .boxed()
1✔
599
                .into(),
1✔
600
            })
1✔
601
            .await
3✔
602
            .unwrap();
1✔
603

1✔
604
        assert!(db.load_workflow(&plot_workflow_id).await.is_ok());
3✔
605

606
        // add a plot
607
        let update = UpdateProject {
1✔
608
            id: project.id,
1✔
609
            name: Some("Test9 Updated".into()),
1✔
610
            description: None,
1✔
611
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
612
                workflow: layer_workflow_id,
1✔
613
                name: "TestLayer".into(),
1✔
614
                symbology: PointSymbology::default().into(),
1✔
615
                visibility: Default::default(),
1✔
616
            })]),
1✔
617
            plots: Some(vec![PlotUpdate::UpdateOrInsert(Plot {
1✔
618
                workflow: plot_workflow_id,
1✔
619
                name: "Test Plot".into(),
1✔
620
            })]),
1✔
621
            bounds: None,
1✔
622
            time_step: None,
1✔
623
        };
1✔
624
        db.update_project(update).await.unwrap();
67✔
625

626
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
627
        assert_eq!(versions.len(), 2);
1✔
628

629
        // add second plot
630
        let update = UpdateProject {
1✔
631
            id: project.id,
1✔
632
            name: Some("Test9 Updated".into()),
1✔
633
            description: None,
1✔
634
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
635
                workflow: layer_workflow_id,
1✔
636
                name: "TestLayer".into(),
1✔
637
                symbology: PointSymbology::default().into(),
1✔
638
                visibility: Default::default(),
1✔
639
            })]),
1✔
640
            plots: Some(vec![
1✔
641
                PlotUpdate::UpdateOrInsert(Plot {
1✔
642
                    workflow: plot_workflow_id,
1✔
643
                    name: "Test Plot".into(),
1✔
644
                }),
1✔
645
                PlotUpdate::UpdateOrInsert(Plot {
1✔
646
                    workflow: plot_workflow_id,
1✔
647
                    name: "Test Plot".into(),
1✔
648
                }),
1✔
649
            ]),
1✔
650
            bounds: None,
1✔
651
            time_step: None,
1✔
652
        };
1✔
653
        db.update_project(update).await.unwrap();
21✔
654

655
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
656
        assert_eq!(versions.len(), 3);
1✔
657

658
        // delete plots
659
        let update = UpdateProject {
1✔
660
            id: project.id,
1✔
661
            name: None,
1✔
662
            description: None,
1✔
663
            layers: None,
1✔
664
            plots: Some(vec![]),
1✔
665
            bounds: None,
1✔
666
            time_step: None,
1✔
667
        };
1✔
668
        db.update_project(update).await.unwrap();
16✔
669

670
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
671
        assert_eq!(versions.len(), 4);
1✔
672
    }
1✔
673

674
    async fn list_projects(
1✔
675
        app_ctx: &PostgresContext<NoTls>,
1✔
676
        session: &SimpleSession,
1✔
677
    ) -> Vec<ProjectListing> {
1✔
678
        let options = ProjectListOptions {
1✔
679
            order: OrderBy::NameDesc,
1✔
680
            offset: 0,
1✔
681
            limit: 2,
1✔
682
        };
1✔
683

1✔
684
        let db = app_ctx.session_context(session.clone()).db();
1✔
685

686
        let projects = db.list_projects(options).await.unwrap();
14✔
687

1✔
688
        assert_eq!(projects.len(), 2);
1✔
689
        assert_eq!(projects[0].name, "Test9");
1✔
690
        assert_eq!(projects[1].name, "Test8");
1✔
691
        projects
1✔
692
    }
1✔
693

694
    async fn create_projects(app_ctx: &PostgresContext<NoTls>, session: &SimpleSession) {
1✔
695
        let db = app_ctx.session_context(session.clone()).db();
1✔
696

697
        for i in 0..10 {
11✔
698
            let create = CreateProject {
10✔
699
                name: format!("Test{i}"),
10✔
700
                description: format!("Test{}", 10 - i),
10✔
701
                bounds: STRectangle::new(
10✔
702
                    SpatialReferenceOption::Unreferenced,
10✔
703
                    0.,
10✔
704
                    0.,
10✔
705
                    1.,
10✔
706
                    1.,
10✔
707
                    0,
10✔
708
                    1,
10✔
709
                )
10✔
710
                .unwrap(),
10✔
711
                time_step: None,
10✔
712
            };
10✔
713
            db.create_project(create).await.unwrap();
74✔
714
        }
715
    }
1✔
716

717
    #[ge_context::test]
2✔
718
    async fn it_persists_workflows(app_ctx: PostgresContext<NoTls>) {
1✔
719
        let workflow = Workflow {
1✔
720
            operator: TypedOperator::Vector(
1✔
721
                MockPointSource {
1✔
722
                    params: MockPointSourceParams {
1✔
723
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
724
                    },
1✔
725
                }
1✔
726
                .boxed(),
1✔
727
            ),
1✔
728
        };
1✔
729

730
        let session = app_ctx.default_session().await.unwrap();
18✔
731
        let ctx = app_ctx.session_context(session);
1✔
732

1✔
733
        let db = ctx.db();
1✔
734
        let id = db.register_workflow(workflow).await.unwrap();
3✔
735

1✔
736
        drop(ctx);
1✔
737

738
        let workflow = db.load_workflow(&id).await.unwrap();
3✔
739

1✔
740
        let json = serde_json::to_string(&workflow).unwrap();
1✔
741
        assert_eq!(
1✔
742
            json,
1✔
743
            r#"{"type":"Vector","operator":{"type":"MockPointSource","params":{"points":[{"x":1.0,"y":2.0},{"x":1.0,"y":2.0},{"x":1.0,"y":2.0}]}}}"#
1✔
744
        );
1✔
745
    }
1✔
746

747
    #[allow(clippy::too_many_lines)]
748
    #[ge_context::test]
2✔
749
    async fn it_persists_datasets(app_ctx: PostgresContext<NoTls>) {
1✔
750
        let loading_info = OgrSourceDataset {
1✔
751
            file_name: PathBuf::from("test.csv"),
1✔
752
            layer_name: "test.csv".to_owned(),
1✔
753
            data_type: Some(VectorDataType::MultiPoint),
1✔
754
            time: OgrSourceDatasetTimeType::Start {
1✔
755
                start_field: "start".to_owned(),
1✔
756
                start_format: OgrSourceTimeFormat::Auto,
1✔
757
                duration: OgrSourceDurationSpec::Zero,
1✔
758
            },
1✔
759
            default_geometry: None,
1✔
760
            columns: Some(OgrSourceColumnSpec {
1✔
761
                format_specifics: Some(FormatSpecifics::Csv {
1✔
762
                    header: CsvHeader::Auto,
1✔
763
                }),
1✔
764
                x: "x".to_owned(),
1✔
765
                y: None,
1✔
766
                int: vec![],
1✔
767
                float: vec![],
1✔
768
                text: vec![],
1✔
769
                bool: vec![],
1✔
770
                datetime: vec![],
1✔
771
                rename: None,
1✔
772
            }),
1✔
773
            force_ogr_time_filter: false,
1✔
774
            force_ogr_spatial_filter: false,
1✔
775
            on_error: OgrSourceErrorSpec::Ignore,
1✔
776
            sql_query: None,
1✔
777
            attribute_query: None,
1✔
778
            cache_ttl: CacheTtlSeconds::default(),
1✔
779
        };
1✔
780

1✔
781
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
782
            OgrSourceDataset,
1✔
783
            VectorResultDescriptor,
1✔
784
            VectorQueryRectangle,
1✔
785
        > {
1✔
786
            loading_info: loading_info.clone(),
1✔
787
            result_descriptor: VectorResultDescriptor {
1✔
788
                data_type: VectorDataType::MultiPoint,
1✔
789
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
790
                columns: [(
1✔
791
                    "foo".to_owned(),
1✔
792
                    VectorColumnInfo {
1✔
793
                        data_type: FeatureDataType::Float,
1✔
794
                        measurement: Measurement::Unitless,
1✔
795
                    },
1✔
796
                )]
1✔
797
                .into_iter()
1✔
798
                .collect(),
1✔
799
                time: None,
1✔
800
                bbox: None,
1✔
801
            },
1✔
802
            phantom: Default::default(),
1✔
803
        });
1✔
804

805
        let session = app_ctx.default_session().await.unwrap();
18✔
806

1✔
807
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
808

1✔
809
        let db = app_ctx.session_context(session.clone()).db();
1✔
810
        let wrap = db.wrap_meta_data(meta_data);
1✔
811
        let DatasetIdAndName {
812
            id: dataset_id,
1✔
813
            name: dataset_name,
1✔
814
        } = db
1✔
815
            .add_dataset(
1✔
816
                AddDataset {
1✔
817
                    name: Some(dataset_name.clone()),
1✔
818
                    display_name: "Ogr Test".to_owned(),
1✔
819
                    description: "desc".to_owned(),
1✔
820
                    source_operator: "OgrSource".to_owned(),
1✔
821
                    symbology: None,
1✔
822
                    provenance: Some(vec![Provenance {
1✔
823
                        citation: "citation".to_owned(),
1✔
824
                        license: "license".to_owned(),
1✔
825
                        uri: "uri".to_owned(),
1✔
826
                    }]),
1✔
827
                },
1✔
828
                wrap,
1✔
829
            )
1✔
830
            .await
154✔
831
            .unwrap();
1✔
832

833
        let datasets = db
1✔
834
            .list_datasets(DatasetListOptions {
1✔
835
                filter: None,
1✔
836
                order: crate::datasets::listing::OrderBy::NameAsc,
1✔
837
                offset: 0,
1✔
838
                limit: 10,
1✔
839
            })
1✔
840
            .await
3✔
841
            .unwrap();
1✔
842

1✔
843
        assert_eq!(datasets.len(), 1);
1✔
844

845
        assert_eq!(
1✔
846
            datasets[0],
1✔
847
            DatasetListing {
1✔
848
                id: dataset_id,
1✔
849
                name: dataset_name,
1✔
850
                display_name: "Ogr Test".to_owned(),
1✔
851
                description: "desc".to_owned(),
1✔
852
                source_operator: "OgrSource".to_owned(),
1✔
853
                symbology: None,
1✔
854
                tags: vec![],
1✔
855
                result_descriptor: TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
856
                    data_type: VectorDataType::MultiPoint,
1✔
857
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
858
                    columns: [(
1✔
859
                        "foo".to_owned(),
1✔
860
                        VectorColumnInfo {
1✔
861
                            data_type: FeatureDataType::Float,
1✔
862
                            measurement: Measurement::Unitless
1✔
863
                        }
1✔
864
                    )]
1✔
865
                    .into_iter()
1✔
866
                    .collect(),
1✔
867
                    time: None,
1✔
868
                    bbox: None,
1✔
869
                })
1✔
870
            },
1✔
871
        );
1✔
872

873
        let provenance = db.load_provenance(&dataset_id).await.unwrap();
3✔
874

1✔
875
        assert_eq!(
1✔
876
            provenance,
1✔
877
            ProvenanceOutput {
1✔
878
                data: dataset_id.into(),
1✔
879
                provenance: Some(vec![Provenance {
1✔
880
                    citation: "citation".to_owned(),
1✔
881
                    license: "license".to_owned(),
1✔
882
                    uri: "uri".to_owned(),
1✔
883
                }])
1✔
884
            }
1✔
885
        );
1✔
886

887
        let meta_data: Box<dyn MetaData<OgrSourceDataset, _, _>> =
1✔
888
            db.meta_data(&dataset_id.into()).await.unwrap();
4✔
889

1✔
890
        assert_eq!(
1✔
891
            meta_data
1✔
892
                .loading_info(VectorQueryRectangle {
1✔
893
                    spatial_bounds: BoundingBox2D::new_unchecked(
1✔
894
                        (-180., -90.).into(),
1✔
895
                        (180., 90.).into()
1✔
896
                    ),
1✔
897
                    time_interval: TimeInterval::default(),
1✔
898
                    spatial_resolution: SpatialResolution::zero_point_one(),
1✔
899
                })
1✔
900
                .await
×
901
                .unwrap(),
1✔
902
            loading_info
903
        );
904
    }
1✔
905

906
    #[ge_context::test]
2✔
907
    async fn it_persists_uploads(app_ctx: PostgresContext<NoTls>) {
1✔
908
        let id = UploadId::from_str("2de18cd8-4a38-4111-a445-e3734bc18a80").unwrap();
1✔
909
        let input = Upload {
1✔
910
            id,
1✔
911
            files: vec![FileUpload {
1✔
912
                id: FileId::from_str("e80afab0-831d-4d40-95d6-1e4dfd277e72").unwrap(),
1✔
913
                name: "test.csv".to_owned(),
1✔
914
                byte_size: 1337,
1✔
915
            }],
1✔
916
        };
1✔
917

918
        let session = app_ctx.default_session().await.unwrap();
18✔
919

1✔
920
        let db = app_ctx.session_context(session.clone()).db();
1✔
921

1✔
922
        db.create_upload(input.clone()).await.unwrap();
6✔
923

924
        let upload = db.load_upload(id).await.unwrap();
3✔
925

1✔
926
        assert_eq!(upload, input);
1✔
927
    }
1✔
928

929
    #[allow(clippy::too_many_lines)]
930
    #[ge_context::test]
2✔
931
    async fn it_persists_layer_providers(app_ctx: PostgresContext<NoTls>) {
1✔
932
        let db = app_ctx.default_session_context().await.unwrap().db();
19✔
933

1✔
934
        let provider = NetCdfCfDataProviderDefinition {
1✔
935
            name: "netcdfcf".to_string(),
1✔
936
            path: test_data!("netcdf4d/").into(),
1✔
937
            overviews: test_data!("netcdf4d/overviews/").into(),
1✔
938
            cache_ttl: CacheTtlSeconds::new(0),
1✔
939
        };
1✔
940

941
        let provider_id = db.add_layer_provider(provider.into()).await.unwrap();
28✔
942

943
        let providers = db
1✔
944
            .list_layer_providers(LayerProviderListingOptions {
1✔
945
                offset: 0,
1✔
946
                limit: 10,
1✔
947
            })
1✔
948
            .await
3✔
949
            .unwrap();
1✔
950

1✔
951
        assert_eq!(providers.len(), 1);
1✔
952

953
        assert_eq!(
1✔
954
            providers[0],
1✔
955
            LayerProviderListing {
1✔
956
                id: provider_id,
1✔
957
                name: "netcdfcf".to_owned(),
1✔
958
                description: "NetCdfCfProviderDefinition".to_owned(),
1✔
959
            }
1✔
960
        );
1✔
961

962
        let provider = db.load_layer_provider(provider_id).await.unwrap();
3✔
963

964
        let datasets = provider
1✔
965
            .load_layer_collection(
966
                &provider.get_root_layer_collection_id().await.unwrap(),
1✔
967
                LayerCollectionListOptions {
1✔
968
                    offset: 0,
1✔
969
                    limit: 10,
1✔
970
                },
1✔
971
            )
972
            .await
4✔
973
            .unwrap();
1✔
974

1✔
975
        assert_eq!(datasets.items.len(), 3);
1✔
976
    }
1✔
977

978
    #[allow(clippy::too_many_lines)]
979
    #[ge_context::test]
2✔
980
    async fn it_loads_all_meta_data_types(app_ctx: PostgresContext<NoTls>) {
1✔
981
        let session = app_ctx.default_session().await.unwrap();
18✔
982

1✔
983
        let db = app_ctx.session_context(session.clone()).db();
1✔
984

1✔
985
        let vector_descriptor = VectorResultDescriptor {
1✔
986
            data_type: VectorDataType::Data,
1✔
987
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
988
            columns: Default::default(),
1✔
989
            time: None,
1✔
990
            bbox: None,
1✔
991
        };
1✔
992

1✔
993
        let raster_descriptor = RasterResultDescriptor {
1✔
994
            data_type: RasterDataType::U8,
1✔
995
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
996
            measurement: Default::default(),
1✔
997
            time: None,
1✔
998
            bbox: None,
1✔
999
            resolution: None,
1✔
1000
        };
1✔
1001

1✔
1002
        let vector_ds = AddDataset {
1✔
1003
            name: None,
1✔
1004
            display_name: "OgrDataset".to_string(),
1✔
1005
            description: "My Ogr dataset".to_string(),
1✔
1006
            source_operator: "OgrSource".to_string(),
1✔
1007
            symbology: None,
1✔
1008
            provenance: None,
1✔
1009
        };
1✔
1010

1✔
1011
        let raster_ds = AddDataset {
1✔
1012
            name: None,
1✔
1013
            display_name: "GdalDataset".to_string(),
1✔
1014
            description: "My Gdal dataset".to_string(),
1✔
1015
            source_operator: "GdalSource".to_string(),
1✔
1016
            symbology: None,
1✔
1017
            provenance: None,
1✔
1018
        };
1✔
1019

1✔
1020
        let gdal_params = GdalDatasetParameters {
1✔
1021
            file_path: Default::default(),
1✔
1022
            rasterband_channel: 0,
1✔
1023
            geo_transform: GdalDatasetGeoTransform {
1✔
1024
                origin_coordinate: Default::default(),
1✔
1025
                x_pixel_size: 0.0,
1✔
1026
                y_pixel_size: 0.0,
1✔
1027
            },
1✔
1028
            width: 0,
1✔
1029
            height: 0,
1✔
1030
            file_not_found_handling: FileNotFoundHandling::NoData,
1✔
1031
            no_data_value: None,
1✔
1032
            properties_mapping: None,
1✔
1033
            gdal_open_options: None,
1✔
1034
            gdal_config_options: None,
1✔
1035
            allow_alphaband_as_mask: false,
1✔
1036
            retry: None,
1✔
1037
        };
1✔
1038

1✔
1039
        let meta = StaticMetaData {
1✔
1040
            loading_info: OgrSourceDataset {
1✔
1041
                file_name: Default::default(),
1✔
1042
                layer_name: String::new(),
1✔
1043
                data_type: None,
1✔
1044
                time: Default::default(),
1✔
1045
                default_geometry: None,
1✔
1046
                columns: None,
1✔
1047
                force_ogr_time_filter: false,
1✔
1048
                force_ogr_spatial_filter: false,
1✔
1049
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1050
                sql_query: None,
1✔
1051
                attribute_query: None,
1✔
1052
                cache_ttl: CacheTtlSeconds::default(),
1✔
1053
            },
1✔
1054
            result_descriptor: vector_descriptor.clone(),
1✔
1055
            phantom: Default::default(),
1✔
1056
        };
1✔
1057

1✔
1058
        let meta = db.wrap_meta_data(MetaDataDefinition::OgrMetaData(meta));
1✔
1059

1060
        let id = db.add_dataset(vector_ds, meta).await.unwrap().id;
155✔
1061

1062
        let meta: geoengine_operators::util::Result<
1✔
1063
            Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>>,
1✔
1064
        > = db.meta_data(&id.into()).await;
3✔
1065

1066
        assert!(meta.is_ok());
1✔
1067

1068
        let meta = GdalMetaDataRegular {
1✔
1069
            result_descriptor: raster_descriptor.clone(),
1✔
1070
            params: gdal_params.clone(),
1✔
1071
            time_placeholders: Default::default(),
1✔
1072
            data_time: Default::default(),
1✔
1073
            step: TimeStep {
1✔
1074
                granularity: TimeGranularity::Millis,
1✔
1075
                step: 0,
1✔
1076
            },
1✔
1077
            cache_ttl: CacheTtlSeconds::default(),
1✔
1078
        };
1✔
1079

1✔
1080
        let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetaDataRegular(meta));
1✔
1081

1082
        let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1083

1084
        let meta: geoengine_operators::util::Result<
1✔
1085
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1086
        > = db.meta_data(&id.into()).await;
3✔
1087

1088
        assert!(meta.is_ok());
1✔
1089

1090
        let meta = GdalMetaDataStatic {
1✔
1091
            time: None,
1✔
1092
            params: gdal_params.clone(),
1✔
1093
            result_descriptor: raster_descriptor.clone(),
1✔
1094
            cache_ttl: CacheTtlSeconds::default(),
1✔
1095
        };
1✔
1096

1✔
1097
        let meta = db.wrap_meta_data(MetaDataDefinition::GdalStatic(meta));
1✔
1098

1099
        let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1100

1101
        let meta: geoengine_operators::util::Result<
1✔
1102
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1103
        > = db.meta_data(&id.into()).await;
3✔
1104

1105
        assert!(meta.is_ok());
1✔
1106

1107
        let meta = GdalMetaDataList {
1✔
1108
            result_descriptor: raster_descriptor.clone(),
1✔
1109
            params: vec![],
1✔
1110
        };
1✔
1111

1✔
1112
        let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetaDataList(meta));
1✔
1113

1114
        let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1115

1116
        let meta: geoengine_operators::util::Result<
1✔
1117
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1118
        > = db.meta_data(&id.into()).await;
3✔
1119

1120
        assert!(meta.is_ok());
1✔
1121

1122
        let meta = GdalMetadataNetCdfCf {
1✔
1123
            result_descriptor: raster_descriptor.clone(),
1✔
1124
            params: gdal_params.clone(),
1✔
1125
            start: TimeInstance::MIN,
1✔
1126
            end: TimeInstance::MAX,
1✔
1127
            step: TimeStep {
1✔
1128
                granularity: TimeGranularity::Millis,
1✔
1129
                step: 0,
1✔
1130
            },
1✔
1131
            band_offset: 0,
1✔
1132
            cache_ttl: CacheTtlSeconds::default(),
1✔
1133
        };
1✔
1134

1✔
1135
        let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetadataNetCdfCf(meta));
1✔
1136

1137
        let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1138

1139
        let meta: geoengine_operators::util::Result<
1✔
1140
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1141
        > = db.meta_data(&id.into()).await;
3✔
1142

1143
        assert!(meta.is_ok());
1✔
1144
    }
1✔
1145

1146
    #[allow(clippy::too_many_lines)]
1147
    #[ge_context::test]
2✔
1148
    async fn it_collects_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1149
        let session = app_ctx.default_session().await.unwrap();
18✔
1150

1✔
1151
        let layer_db = app_ctx.session_context(session).db();
1✔
1152

1✔
1153
        let workflow = Workflow {
1✔
1154
            operator: TypedOperator::Vector(
1✔
1155
                MockPointSource {
1✔
1156
                    params: MockPointSourceParams {
1✔
1157
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1158
                    },
1✔
1159
                }
1✔
1160
                .boxed(),
1✔
1161
            ),
1✔
1162
        };
1✔
1163

1164
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1165

1166
        let layer1 = layer_db
1✔
1167
            .add_layer(
1✔
1168
                AddLayer {
1✔
1169
                    name: "Layer1".to_string(),
1✔
1170
                    description: "Layer 1".to_string(),
1✔
1171
                    symbology: None,
1✔
1172
                    workflow: workflow.clone(),
1✔
1173
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1174
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1175
                },
1✔
1176
                &root_collection_id,
1✔
1177
            )
1✔
1178
            .await
43✔
1179
            .unwrap();
1✔
1180

1✔
1181
        assert_eq!(
1✔
1182
            layer_db.load_layer(&layer1).await.unwrap(),
3✔
1183
            crate::layers::layer::Layer {
1✔
1184
                id: ProviderLayerId {
1✔
1185
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1186
                    layer_id: layer1.clone(),
1✔
1187
                },
1✔
1188
                name: "Layer1".to_string(),
1✔
1189
                description: "Layer 1".to_string(),
1✔
1190
                symbology: None,
1✔
1191
                workflow: workflow.clone(),
1✔
1192
                metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1193
                properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1194
            }
1✔
1195
        );
1196

1197
        let collection1_id = layer_db
1✔
1198
            .add_layer_collection(
1✔
1199
                AddLayerCollection {
1✔
1200
                    name: "Collection1".to_string(),
1✔
1201
                    description: "Collection 1".to_string(),
1✔
1202
                    properties: Default::default(),
1✔
1203
                },
1✔
1204
                &root_collection_id,
1✔
1205
            )
1✔
1206
            .await
7✔
1207
            .unwrap();
1✔
1208

1209
        let layer2 = layer_db
1✔
1210
            .add_layer(
1✔
1211
                AddLayer {
1✔
1212
                    name: "Layer2".to_string(),
1✔
1213
                    description: "Layer 2".to_string(),
1✔
1214
                    symbology: None,
1✔
1215
                    workflow: workflow.clone(),
1✔
1216
                    metadata: Default::default(),
1✔
1217
                    properties: Default::default(),
1✔
1218
                },
1✔
1219
                &collection1_id,
1✔
1220
            )
1✔
1221
            .await
9✔
1222
            .unwrap();
1✔
1223

1224
        let collection2_id = layer_db
1✔
1225
            .add_layer_collection(
1✔
1226
                AddLayerCollection {
1✔
1227
                    name: "Collection2".to_string(),
1✔
1228
                    description: "Collection 2".to_string(),
1✔
1229
                    properties: Default::default(),
1✔
1230
                },
1✔
1231
                &collection1_id,
1✔
1232
            )
1✔
1233
            .await
7✔
1234
            .unwrap();
1✔
1235

1✔
1236
        layer_db
1✔
1237
            .add_collection_to_parent(&collection2_id, &collection1_id)
1✔
1238
            .await
3✔
1239
            .unwrap();
1✔
1240

1241
        let root_collection = layer_db
1✔
1242
            .load_layer_collection(
1✔
1243
                &root_collection_id,
1✔
1244
                LayerCollectionListOptions {
1✔
1245
                    offset: 0,
1✔
1246
                    limit: 20,
1✔
1247
                },
1✔
1248
            )
1✔
1249
            .await
5✔
1250
            .unwrap();
1✔
1251

1✔
1252
        assert_eq!(
1✔
1253
            root_collection,
1✔
1254
            LayerCollection {
1✔
1255
                id: ProviderLayerCollectionId {
1✔
1256
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1257
                    collection_id: root_collection_id,
1✔
1258
                },
1✔
1259
                name: "Layers".to_string(),
1✔
1260
                description: "All available Geo Engine layers".to_string(),
1✔
1261
                items: vec![
1✔
1262
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1263
                        id: ProviderLayerCollectionId {
1✔
1264
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1265
                            collection_id: collection1_id.clone(),
1✔
1266
                        },
1✔
1267
                        name: "Collection1".to_string(),
1✔
1268
                        description: "Collection 1".to_string(),
1✔
1269
                        properties: Default::default(),
1✔
1270
                    }),
1✔
1271
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1272
                        id: ProviderLayerCollectionId {
1✔
1273
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1274
                            collection_id: LayerCollectionId(UNSORTED_COLLECTION_ID.to_string()),
1✔
1275
                        },
1✔
1276
                        name: "Unsorted".to_string(),
1✔
1277
                        description: "Unsorted Layers".to_string(),
1✔
1278
                        properties: Default::default(),
1✔
1279
                    }),
1✔
1280
                    CollectionItem::Layer(LayerListing {
1✔
1281
                        id: ProviderLayerId {
1✔
1282
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1283
                            layer_id: layer1,
1✔
1284
                        },
1✔
1285
                        name: "Layer1".to_string(),
1✔
1286
                        description: "Layer 1".to_string(),
1✔
1287
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1288
                    })
1✔
1289
                ],
1✔
1290
                entry_label: None,
1✔
1291
                properties: vec![],
1✔
1292
            }
1✔
1293
        );
1✔
1294

1295
        let collection1 = layer_db
1✔
1296
            .load_layer_collection(
1✔
1297
                &collection1_id,
1✔
1298
                LayerCollectionListOptions {
1✔
1299
                    offset: 0,
1✔
1300
                    limit: 20,
1✔
1301
                },
1✔
1302
            )
1✔
1303
            .await
5✔
1304
            .unwrap();
1✔
1305

1✔
1306
        assert_eq!(
1✔
1307
            collection1,
1✔
1308
            LayerCollection {
1✔
1309
                id: ProviderLayerCollectionId {
1✔
1310
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1311
                    collection_id: collection1_id,
1✔
1312
                },
1✔
1313
                name: "Collection1".to_string(),
1✔
1314
                description: "Collection 1".to_string(),
1✔
1315
                items: vec![
1✔
1316
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1317
                        id: ProviderLayerCollectionId {
1✔
1318
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1319
                            collection_id: collection2_id,
1✔
1320
                        },
1✔
1321
                        name: "Collection2".to_string(),
1✔
1322
                        description: "Collection 2".to_string(),
1✔
1323
                        properties: Default::default(),
1✔
1324
                    }),
1✔
1325
                    CollectionItem::Layer(LayerListing {
1✔
1326
                        id: ProviderLayerId {
1✔
1327
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1328
                            layer_id: layer2,
1✔
1329
                        },
1✔
1330
                        name: "Layer2".to_string(),
1✔
1331
                        description: "Layer 2".to_string(),
1✔
1332
                        properties: vec![],
1✔
1333
                    })
1✔
1334
                ],
1✔
1335
                entry_label: None,
1✔
1336
                properties: vec![],
1✔
1337
            }
1✔
1338
        );
1✔
1339
    }
1✔
1340

1341
    #[allow(clippy::too_many_lines)]
1342
    #[ge_context::test]
2✔
1343
    async fn it_removes_layer_collections(app_ctx: PostgresContext<NoTls>) {
1✔
1344
        let session = app_ctx.default_session().await.unwrap();
18✔
1345

1✔
1346
        let layer_db = app_ctx.session_context(session).db();
1✔
1347

1✔
1348
        let layer = AddLayer {
1✔
1349
            name: "layer".to_string(),
1✔
1350
            description: "description".to_string(),
1✔
1351
            workflow: Workflow {
1✔
1352
                operator: TypedOperator::Vector(
1✔
1353
                    MockPointSource {
1✔
1354
                        params: MockPointSourceParams {
1✔
1355
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1356
                        },
1✔
1357
                    }
1✔
1358
                    .boxed(),
1✔
1359
                ),
1✔
1360
            },
1✔
1361
            symbology: None,
1✔
1362
            metadata: Default::default(),
1✔
1363
            properties: Default::default(),
1✔
1364
        };
1✔
1365

1366
        let root_collection = &layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1367

1✔
1368
        let collection = AddLayerCollection {
1✔
1369
            name: "top collection".to_string(),
1✔
1370
            description: "description".to_string(),
1✔
1371
            properties: Default::default(),
1✔
1372
        };
1✔
1373

1374
        let top_c_id = layer_db
1✔
1375
            .add_layer_collection(collection, root_collection)
1✔
1376
            .await
10✔
1377
            .unwrap();
1✔
1378

1379
        let l_id = layer_db.add_layer(layer, &top_c_id).await.unwrap();
40✔
1380

1✔
1381
        let collection = AddLayerCollection {
1✔
1382
            name: "empty collection".to_string(),
1✔
1383
            description: "description".to_string(),
1✔
1384
            properties: Default::default(),
1✔
1385
        };
1✔
1386

1387
        let empty_c_id = layer_db
1✔
1388
            .add_layer_collection(collection, &top_c_id)
1✔
1389
            .await
7✔
1390
            .unwrap();
1✔
1391

1392
        let items = layer_db
1✔
1393
            .load_layer_collection(
1✔
1394
                &top_c_id,
1✔
1395
                LayerCollectionListOptions {
1✔
1396
                    offset: 0,
1✔
1397
                    limit: 20,
1✔
1398
                },
1✔
1399
            )
1✔
1400
            .await
5✔
1401
            .unwrap();
1✔
1402

1✔
1403
        assert_eq!(
1✔
1404
            items,
1✔
1405
            LayerCollection {
1✔
1406
                id: ProviderLayerCollectionId {
1✔
1407
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1408
                    collection_id: top_c_id.clone(),
1✔
1409
                },
1✔
1410
                name: "top collection".to_string(),
1✔
1411
                description: "description".to_string(),
1✔
1412
                items: vec![
1✔
1413
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1414
                        id: ProviderLayerCollectionId {
1✔
1415
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1416
                            collection_id: empty_c_id.clone(),
1✔
1417
                        },
1✔
1418
                        name: "empty collection".to_string(),
1✔
1419
                        description: "description".to_string(),
1✔
1420
                        properties: Default::default(),
1✔
1421
                    }),
1✔
1422
                    CollectionItem::Layer(LayerListing {
1✔
1423
                        id: ProviderLayerId {
1✔
1424
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1425
                            layer_id: l_id.clone(),
1✔
1426
                        },
1✔
1427
                        name: "layer".to_string(),
1✔
1428
                        description: "description".to_string(),
1✔
1429
                        properties: vec![],
1✔
1430
                    })
1✔
1431
                ],
1✔
1432
                entry_label: None,
1✔
1433
                properties: vec![],
1✔
1434
            }
1✔
1435
        );
1✔
1436

1437
        // remove empty collection
1438
        layer_db.remove_layer_collection(&empty_c_id).await.unwrap();
9✔
1439

1440
        let items = layer_db
1✔
1441
            .load_layer_collection(
1✔
1442
                &top_c_id,
1✔
1443
                LayerCollectionListOptions {
1✔
1444
                    offset: 0,
1✔
1445
                    limit: 20,
1✔
1446
                },
1✔
1447
            )
1✔
1448
            .await
5✔
1449
            .unwrap();
1✔
1450

1✔
1451
        assert_eq!(
1✔
1452
            items,
1✔
1453
            LayerCollection {
1✔
1454
                id: ProviderLayerCollectionId {
1✔
1455
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1456
                    collection_id: top_c_id.clone(),
1✔
1457
                },
1✔
1458
                name: "top collection".to_string(),
1✔
1459
                description: "description".to_string(),
1✔
1460
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1461
                    id: ProviderLayerId {
1✔
1462
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1463
                        layer_id: l_id.clone(),
1✔
1464
                    },
1✔
1465
                    name: "layer".to_string(),
1✔
1466
                    description: "description".to_string(),
1✔
1467
                    properties: vec![],
1✔
1468
                })],
1✔
1469
                entry_label: None,
1✔
1470
                properties: vec![],
1✔
1471
            }
1✔
1472
        );
1✔
1473

1474
        // remove top (not root) collection
1475
        layer_db.remove_layer_collection(&top_c_id).await.unwrap();
9✔
1476

1✔
1477
        layer_db
1✔
1478
            .load_layer_collection(
1✔
1479
                &top_c_id,
1✔
1480
                LayerCollectionListOptions {
1✔
1481
                    offset: 0,
1✔
1482
                    limit: 20,
1✔
1483
                },
1✔
1484
            )
1✔
1485
            .await
3✔
1486
            .unwrap_err();
1✔
1487

1✔
1488
        // should be deleted automatically
1✔
1489
        layer_db.load_layer(&l_id).await.unwrap_err();
3✔
1490

1✔
1491
        // it is not allowed to remove the root collection
1✔
1492
        layer_db
1✔
1493
            .remove_layer_collection(root_collection)
1✔
1494
            .await
2✔
1495
            .unwrap_err();
1✔
1496
        layer_db
1✔
1497
            .load_layer_collection(
1✔
1498
                root_collection,
1✔
1499
                LayerCollectionListOptions {
1✔
1500
                    offset: 0,
1✔
1501
                    limit: 20,
1✔
1502
                },
1✔
1503
            )
1✔
1504
            .await
5✔
1505
            .unwrap();
1✔
1506
    }
1✔
1507

1508
    #[ge_context::test]
2✔
1509
    #[allow(clippy::too_many_lines)]
1510
    async fn it_removes_collections_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
1511
        let session = app_ctx.default_session().await.unwrap();
18✔
1512

1✔
1513
        let db = app_ctx.session_context(session).db();
1✔
1514

1515
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
1516

1517
        let mid_collection_id = db
1✔
1518
            .add_layer_collection(
1✔
1519
                AddLayerCollection {
1✔
1520
                    name: "mid collection".to_string(),
1✔
1521
                    description: "description".to_string(),
1✔
1522
                    properties: Default::default(),
1✔
1523
                },
1✔
1524
                root_collection_id,
1✔
1525
            )
1✔
1526
            .await
10✔
1527
            .unwrap();
1✔
1528

1529
        let bottom_collection_id = db
1✔
1530
            .add_layer_collection(
1✔
1531
                AddLayerCollection {
1✔
1532
                    name: "bottom collection".to_string(),
1✔
1533
                    description: "description".to_string(),
1✔
1534
                    properties: Default::default(),
1✔
1535
                },
1✔
1536
                &mid_collection_id,
1✔
1537
            )
1✔
1538
            .await
7✔
1539
            .unwrap();
1✔
1540

1541
        let layer_id = db
1✔
1542
            .add_layer(
1✔
1543
                AddLayer {
1✔
1544
                    name: "layer".to_string(),
1✔
1545
                    description: "description".to_string(),
1✔
1546
                    workflow: Workflow {
1✔
1547
                        operator: TypedOperator::Vector(
1✔
1548
                            MockPointSource {
1✔
1549
                                params: MockPointSourceParams {
1✔
1550
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1551
                                },
1✔
1552
                            }
1✔
1553
                            .boxed(),
1✔
1554
                        ),
1✔
1555
                    },
1✔
1556
                    symbology: None,
1✔
1557
                    metadata: Default::default(),
1✔
1558
                    properties: Default::default(),
1✔
1559
                },
1✔
1560
                &mid_collection_id,
1✔
1561
            )
1✔
1562
            .await
36✔
1563
            .unwrap();
1✔
1564

1✔
1565
        // removing the mid collection…
1✔
1566
        db.remove_layer_collection_from_parent(&mid_collection_id, root_collection_id)
1✔
1567
            .await
11✔
1568
            .unwrap();
1✔
1569

1✔
1570
        // …should remove itself
1✔
1571
        db.load_layer_collection(&mid_collection_id, LayerCollectionListOptions::default())
1✔
1572
            .await
3✔
1573
            .unwrap_err();
1✔
1574

1✔
1575
        // …should remove the bottom collection
1✔
1576
        db.load_layer_collection(&bottom_collection_id, LayerCollectionListOptions::default())
1✔
1577
            .await
3✔
1578
            .unwrap_err();
1✔
1579

1✔
1580
        // … and should remove the layer of the bottom collection
1✔
1581
        db.load_layer(&layer_id).await.unwrap_err();
3✔
1582

1✔
1583
        // the root collection is still there
1✔
1584
        db.load_layer_collection(root_collection_id, LayerCollectionListOptions::default())
1✔
1585
            .await
5✔
1586
            .unwrap();
1✔
1587
    }
1✔
1588

1589
    #[ge_context::test]
2✔
1590
    #[allow(clippy::too_many_lines)]
1591
    async fn it_removes_layers_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
1592
        let session = app_ctx.default_session().await.unwrap();
18✔
1593

1✔
1594
        let db = app_ctx.session_context(session).db();
1✔
1595

1596
        let root_collection = &db.get_root_layer_collection_id().await.unwrap();
1✔
1597

1598
        let another_collection = db
1✔
1599
            .add_layer_collection(
1✔
1600
                AddLayerCollection {
1✔
1601
                    name: "top collection".to_string(),
1✔
1602
                    description: "description".to_string(),
1✔
1603
                    properties: Default::default(),
1✔
1604
                },
1✔
1605
                root_collection,
1✔
1606
            )
1✔
1607
            .await
10✔
1608
            .unwrap();
1✔
1609

1610
        let layer_in_one_collection = db
1✔
1611
            .add_layer(
1✔
1612
                AddLayer {
1✔
1613
                    name: "layer 1".to_string(),
1✔
1614
                    description: "description".to_string(),
1✔
1615
                    workflow: Workflow {
1✔
1616
                        operator: TypedOperator::Vector(
1✔
1617
                            MockPointSource {
1✔
1618
                                params: MockPointSourceParams {
1✔
1619
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1620
                                },
1✔
1621
                            }
1✔
1622
                            .boxed(),
1✔
1623
                        ),
1✔
1624
                    },
1✔
1625
                    symbology: None,
1✔
1626
                    metadata: Default::default(),
1✔
1627
                    properties: Default::default(),
1✔
1628
                },
1✔
1629
                &another_collection,
1✔
1630
            )
1✔
1631
            .await
41✔
1632
            .unwrap();
1✔
1633

1634
        let layer_in_two_collections = db
1✔
1635
            .add_layer(
1✔
1636
                AddLayer {
1✔
1637
                    name: "layer 2".to_string(),
1✔
1638
                    description: "description".to_string(),
1✔
1639
                    workflow: Workflow {
1✔
1640
                        operator: TypedOperator::Vector(
1✔
1641
                            MockPointSource {
1✔
1642
                                params: MockPointSourceParams {
1✔
1643
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1644
                                },
1✔
1645
                            }
1✔
1646
                            .boxed(),
1✔
1647
                        ),
1✔
1648
                    },
1✔
1649
                    symbology: None,
1✔
1650
                    metadata: Default::default(),
1✔
1651
                    properties: Default::default(),
1✔
1652
                },
1✔
1653
                &another_collection,
1✔
1654
            )
1✔
1655
            .await
9✔
1656
            .unwrap();
1✔
1657

1✔
1658
        db.add_layer_to_collection(&layer_in_two_collections, root_collection)
1✔
1659
            .await
3✔
1660
            .unwrap();
1✔
1661

1✔
1662
        // remove first layer --> should be deleted entirely
1✔
1663

1✔
1664
        db.remove_layer_from_collection(&layer_in_one_collection, &another_collection)
1✔
1665
            .await
7✔
1666
            .unwrap();
1✔
1667

1668
        let number_of_layer_in_collection = db
1✔
1669
            .load_layer_collection(
1✔
1670
                &another_collection,
1✔
1671
                LayerCollectionListOptions {
1✔
1672
                    offset: 0,
1✔
1673
                    limit: 20,
1✔
1674
                },
1✔
1675
            )
1✔
1676
            .await
5✔
1677
            .unwrap()
1✔
1678
            .items
1✔
1679
            .len();
1✔
1680
        assert_eq!(
1✔
1681
            number_of_layer_in_collection,
1✔
1682
            1 /* only the other collection should be here */
1✔
1683
        );
1✔
1684

1685
        db.load_layer(&layer_in_one_collection).await.unwrap_err();
3✔
1686

1✔
1687
        // remove second layer --> should only be gone in collection
1✔
1688

1✔
1689
        db.remove_layer_from_collection(&layer_in_two_collections, &another_collection)
1✔
1690
            .await
7✔
1691
            .unwrap();
1✔
1692

1693
        let number_of_layer_in_collection = db
1✔
1694
            .load_layer_collection(
1✔
1695
                &another_collection,
1✔
1696
                LayerCollectionListOptions {
1✔
1697
                    offset: 0,
1✔
1698
                    limit: 20,
1✔
1699
                },
1✔
1700
            )
1✔
1701
            .await
5✔
1702
            .unwrap()
1✔
1703
            .items
1✔
1704
            .len();
1✔
1705
        assert_eq!(
1✔
1706
            number_of_layer_in_collection,
1✔
1707
            0 /* both layers were deleted */
1✔
1708
        );
1✔
1709

1710
        db.load_layer(&layer_in_two_collections).await.unwrap();
3✔
1711
    }
1✔
1712

1713
    #[ge_context::test]
2✔
1714
    #[allow(clippy::too_many_lines)]
1715
    async fn it_deletes_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
1716
        let loading_info = OgrSourceDataset {
1✔
1717
            file_name: PathBuf::from("test.csv"),
1✔
1718
            layer_name: "test.csv".to_owned(),
1✔
1719
            data_type: Some(VectorDataType::MultiPoint),
1✔
1720
            time: OgrSourceDatasetTimeType::Start {
1✔
1721
                start_field: "start".to_owned(),
1✔
1722
                start_format: OgrSourceTimeFormat::Auto,
1✔
1723
                duration: OgrSourceDurationSpec::Zero,
1✔
1724
            },
1✔
1725
            default_geometry: None,
1✔
1726
            columns: Some(OgrSourceColumnSpec {
1✔
1727
                format_specifics: Some(FormatSpecifics::Csv {
1✔
1728
                    header: CsvHeader::Auto,
1✔
1729
                }),
1✔
1730
                x: "x".to_owned(),
1✔
1731
                y: None,
1✔
1732
                int: vec![],
1✔
1733
                float: vec![],
1✔
1734
                text: vec![],
1✔
1735
                bool: vec![],
1✔
1736
                datetime: vec![],
1✔
1737
                rename: None,
1✔
1738
            }),
1✔
1739
            force_ogr_time_filter: false,
1✔
1740
            force_ogr_spatial_filter: false,
1✔
1741
            on_error: OgrSourceErrorSpec::Ignore,
1✔
1742
            sql_query: None,
1✔
1743
            attribute_query: None,
1✔
1744
            cache_ttl: CacheTtlSeconds::default(),
1✔
1745
        };
1✔
1746

1✔
1747
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1748
            OgrSourceDataset,
1✔
1749
            VectorResultDescriptor,
1✔
1750
            VectorQueryRectangle,
1✔
1751
        > {
1✔
1752
            loading_info: loading_info.clone(),
1✔
1753
            result_descriptor: VectorResultDescriptor {
1✔
1754
                data_type: VectorDataType::MultiPoint,
1✔
1755
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1756
                columns: [(
1✔
1757
                    "foo".to_owned(),
1✔
1758
                    VectorColumnInfo {
1✔
1759
                        data_type: FeatureDataType::Float,
1✔
1760
                        measurement: Measurement::Unitless,
1✔
1761
                    },
1✔
1762
                )]
1✔
1763
                .into_iter()
1✔
1764
                .collect(),
1✔
1765
                time: None,
1✔
1766
                bbox: None,
1✔
1767
            },
1✔
1768
            phantom: Default::default(),
1✔
1769
        });
1✔
1770

1771
        let session = app_ctx.default_session().await.unwrap();
18✔
1772

1✔
1773
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
1774

1✔
1775
        let db = app_ctx.session_context(session.clone()).db();
1✔
1776
        let wrap = db.wrap_meta_data(meta_data);
1✔
1777
        let dataset_id = db
1✔
1778
            .add_dataset(
1✔
1779
                AddDataset {
1✔
1780
                    name: Some(dataset_name),
1✔
1781
                    display_name: "Ogr Test".to_owned(),
1✔
1782
                    description: "desc".to_owned(),
1✔
1783
                    source_operator: "OgrSource".to_owned(),
1✔
1784
                    symbology: None,
1✔
1785
                    provenance: Some(vec![Provenance {
1✔
1786
                        citation: "citation".to_owned(),
1✔
1787
                        license: "license".to_owned(),
1✔
1788
                        uri: "uri".to_owned(),
1✔
1789
                    }]),
1✔
1790
                },
1✔
1791
                wrap,
1✔
1792
            )
1✔
1793
            .await
154✔
1794
            .unwrap()
1✔
1795
            .id;
1✔
1796

1✔
1797
        assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
1798

1799
        db.delete_dataset(dataset_id).await.unwrap();
3✔
1800

1✔
1801
        assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
1802
    }
1✔
1803

1804
    #[ge_context::test]
2✔
1805
    #[allow(clippy::too_many_lines)]
1806
    async fn it_deletes_admin_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
1807
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
1808

1✔
1809
        let loading_info = OgrSourceDataset {
1✔
1810
            file_name: PathBuf::from("test.csv"),
1✔
1811
            layer_name: "test.csv".to_owned(),
1✔
1812
            data_type: Some(VectorDataType::MultiPoint),
1✔
1813
            time: OgrSourceDatasetTimeType::Start {
1✔
1814
                start_field: "start".to_owned(),
1✔
1815
                start_format: OgrSourceTimeFormat::Auto,
1✔
1816
                duration: OgrSourceDurationSpec::Zero,
1✔
1817
            },
1✔
1818
            default_geometry: None,
1✔
1819
            columns: Some(OgrSourceColumnSpec {
1✔
1820
                format_specifics: Some(FormatSpecifics::Csv {
1✔
1821
                    header: CsvHeader::Auto,
1✔
1822
                }),
1✔
1823
                x: "x".to_owned(),
1✔
1824
                y: None,
1✔
1825
                int: vec![],
1✔
1826
                float: vec![],
1✔
1827
                text: vec![],
1✔
1828
                bool: vec![],
1✔
1829
                datetime: vec![],
1✔
1830
                rename: None,
1✔
1831
            }),
1✔
1832
            force_ogr_time_filter: false,
1✔
1833
            force_ogr_spatial_filter: false,
1✔
1834
            on_error: OgrSourceErrorSpec::Ignore,
1✔
1835
            sql_query: None,
1✔
1836
            attribute_query: None,
1✔
1837
            cache_ttl: CacheTtlSeconds::default(),
1✔
1838
        };
1✔
1839

1✔
1840
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1841
            OgrSourceDataset,
1✔
1842
            VectorResultDescriptor,
1✔
1843
            VectorQueryRectangle,
1✔
1844
        > {
1✔
1845
            loading_info: loading_info.clone(),
1✔
1846
            result_descriptor: VectorResultDescriptor {
1✔
1847
                data_type: VectorDataType::MultiPoint,
1✔
1848
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1849
                columns: [(
1✔
1850
                    "foo".to_owned(),
1✔
1851
                    VectorColumnInfo {
1✔
1852
                        data_type: FeatureDataType::Float,
1✔
1853
                        measurement: Measurement::Unitless,
1✔
1854
                    },
1✔
1855
                )]
1✔
1856
                .into_iter()
1✔
1857
                .collect(),
1✔
1858
                time: None,
1✔
1859
                bbox: None,
1✔
1860
            },
1✔
1861
            phantom: Default::default(),
1✔
1862
        });
1✔
1863

1864
        let session = app_ctx.default_session().await.unwrap();
18✔
1865

1✔
1866
        let db = app_ctx.session_context(session).db();
1✔
1867
        let wrap = db.wrap_meta_data(meta_data);
1✔
1868
        let dataset_id = db
1✔
1869
            .add_dataset(
1✔
1870
                AddDataset {
1✔
1871
                    name: Some(dataset_name),
1✔
1872
                    display_name: "Ogr Test".to_owned(),
1✔
1873
                    description: "desc".to_owned(),
1✔
1874
                    source_operator: "OgrSource".to_owned(),
1✔
1875
                    symbology: None,
1✔
1876
                    provenance: Some(vec![Provenance {
1✔
1877
                        citation: "citation".to_owned(),
1✔
1878
                        license: "license".to_owned(),
1✔
1879
                        uri: "uri".to_owned(),
1✔
1880
                    }]),
1✔
1881
                },
1✔
1882
                wrap,
1✔
1883
            )
1✔
1884
            .await
155✔
1885
            .unwrap()
1✔
1886
            .id;
1✔
1887

1✔
1888
        assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
1889

1890
        db.delete_dataset(dataset_id).await.unwrap();
3✔
1891

1✔
1892
        assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
1893
    }
1✔
1894

1895
    #[ge_context::test]
2✔
1896
    async fn test_missing_layer_dataset_in_collection_listing(app_ctx: PostgresContext<NoTls>) {
1✔
1897
        let session = app_ctx.default_session().await.unwrap();
18✔
1898
        let db = app_ctx.session_context(session).db();
1✔
1899

1900
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
1901

1902
        let top_collection_id = db
1✔
1903
            .add_layer_collection(
1✔
1904
                AddLayerCollection {
1✔
1905
                    name: "top collection".to_string(),
1✔
1906
                    description: "description".to_string(),
1✔
1907
                    properties: Default::default(),
1✔
1908
                },
1✔
1909
                root_collection_id,
1✔
1910
            )
1✔
1911
            .await
10✔
1912
            .unwrap();
1✔
1913

1✔
1914
        let faux_layer = LayerId("faux".to_string());
1✔
1915

1✔
1916
        // this should fail
1✔
1917
        db.add_layer_to_collection(&faux_layer, &top_collection_id)
1✔
1918
            .await
×
1919
            .unwrap_err();
1✔
1920

1921
        let root_collection_layers = db
1✔
1922
            .load_layer_collection(
1✔
1923
                &top_collection_id,
1✔
1924
                LayerCollectionListOptions {
1✔
1925
                    offset: 0,
1✔
1926
                    limit: 20,
1✔
1927
                },
1✔
1928
            )
1✔
1929
            .await
5✔
1930
            .unwrap();
1✔
1931

1✔
1932
        assert_eq!(
1✔
1933
            root_collection_layers,
1✔
1934
            LayerCollection {
1✔
1935
                id: ProviderLayerCollectionId {
1✔
1936
                    provider_id: DataProviderId(
1✔
1937
                        "ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74".try_into().unwrap()
1✔
1938
                    ),
1✔
1939
                    collection_id: top_collection_id.clone(),
1✔
1940
                },
1✔
1941
                name: "top collection".to_string(),
1✔
1942
                description: "description".to_string(),
1✔
1943
                items: vec![],
1✔
1944
                entry_label: None,
1✔
1945
                properties: vec![],
1✔
1946
            }
1✔
1947
        );
1✔
1948
    }
1✔
1949

1950
    #[allow(clippy::too_many_lines)]
1951
    #[ge_context::test]
2✔
1952
    async fn it_updates_project_layer_symbology(app_ctx: PostgresContext<NoTls>) {
1✔
1953
        let session = app_ctx.default_session().await.unwrap();
18✔
1954

1955
        let (_, workflow_id) = register_ndvi_workflow_helper(&app_ctx).await;
165✔
1956

1957
        let db = app_ctx.session_context(session.clone()).db();
1✔
1958

1✔
1959
        let create_project: CreateProject = serde_json::from_value(json!({
1✔
1960
            "name": "Default",
1✔
1961
            "description": "Default project",
1✔
1962
            "bounds": {
1✔
1963
                "boundingBox": {
1✔
1964
                    "lowerLeftCoordinate": {
1✔
1965
                        "x": -180,
1✔
1966
                        "y": -90
1✔
1967
                    },
1✔
1968
                    "upperRightCoordinate": {
1✔
1969
                        "x": 180,
1✔
1970
                        "y": 90
1✔
1971
                    }
1✔
1972
                },
1✔
1973
                "spatialReference": "EPSG:4326",
1✔
1974
                "timeInterval": {
1✔
1975
                    "start": 1_396_353_600_000i64,
1✔
1976
                    "end": 1_396_353_600_000i64
1✔
1977
                }
1✔
1978
            },
1✔
1979
            "timeStep": {
1✔
1980
                "step": 1,
1✔
1981
                "granularity": "months"
1✔
1982
            }
1✔
1983
        }))
1✔
1984
        .unwrap();
1✔
1985

1986
        let project_id = db.create_project(create_project).await.unwrap();
7✔
1987

1✔
1988
        let update: UpdateProject = serde_json::from_value(json!({
1✔
1989
            "id": project_id.to_string(),
1✔
1990
            "layers": [{
1✔
1991
                "name": "NDVI",
1✔
1992
                "workflow": workflow_id.to_string(),
1✔
1993
                "visibility": {
1✔
1994
                    "data": true,
1✔
1995
                    "legend": false
1✔
1996
                },
1✔
1997
                "symbology": {
1✔
1998
                    "type": "raster",
1✔
1999
                    "opacity": 1,
1✔
2000
                    "colorizer": {
1✔
2001
                        "type": "linearGradient",
1✔
2002
                        "breakpoints": [{
1✔
2003
                            "value": 1,
1✔
2004
                            "color": [0, 0, 0, 255]
1✔
2005
                        }, {
1✔
2006
                            "value": 255,
1✔
2007
                            "color": [255, 255, 255, 255]
1✔
2008
                        }],
1✔
2009
                        "noDataColor": [0, 0, 0, 0],
1✔
2010
                        "overColor": [255, 255, 255, 127],
1✔
2011
                        "underColor": [255, 255, 255, 127]
1✔
2012
                    }
1✔
2013
                }
1✔
2014
            }]
1✔
2015
        }))
1✔
2016
        .unwrap();
1✔
2017

1✔
2018
        db.update_project(update).await.unwrap();
67✔
2019

1✔
2020
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2021
            "id": project_id.to_string(),
1✔
2022
            "layers": [{
1✔
2023
                "name": "NDVI",
1✔
2024
                "workflow": workflow_id.to_string(),
1✔
2025
                "visibility": {
1✔
2026
                    "data": true,
1✔
2027
                    "legend": false
1✔
2028
                },
1✔
2029
                "symbology": {
1✔
2030
                    "type": "raster",
1✔
2031
                    "opacity": 1,
1✔
2032
                    "colorizer": {
1✔
2033
                        "type": "linearGradient",
1✔
2034
                        "breakpoints": [{
1✔
2035
                            "value": 1,
1✔
2036
                            "color": [0, 0, 4, 255]
1✔
2037
                        }, {
1✔
2038
                            "value": 17.866_666_666_666_667,
1✔
2039
                            "color": [11, 9, 36, 255]
1✔
2040
                        }, {
1✔
2041
                            "value": 34.733_333_333_333_334,
1✔
2042
                            "color": [32, 17, 75, 255]
1✔
2043
                        }, {
1✔
2044
                            "value": 51.6,
1✔
2045
                            "color": [59, 15, 112, 255]
1✔
2046
                        }, {
1✔
2047
                            "value": 68.466_666_666_666_67,
1✔
2048
                            "color": [87, 21, 126, 255]
1✔
2049
                        }, {
1✔
2050
                            "value": 85.333_333_333_333_33,
1✔
2051
                            "color": [114, 31, 129, 255]
1✔
2052
                        }, {
1✔
2053
                            "value": 102.199_999_999_999_99,
1✔
2054
                            "color": [140, 41, 129, 255]
1✔
2055
                        }, {
1✔
2056
                            "value": 119.066_666_666_666_65,
1✔
2057
                            "color": [168, 50, 125, 255]
1✔
2058
                        }, {
1✔
2059
                            "value": 135.933_333_333_333_34,
1✔
2060
                            "color": [196, 60, 117, 255]
1✔
2061
                        }, {
1✔
2062
                            "value": 152.799_999_999_999_98,
1✔
2063
                            "color": [222, 73, 104, 255]
1✔
2064
                        }, {
1✔
2065
                            "value": 169.666_666_666_666_66,
1✔
2066
                            "color": [241, 96, 93, 255]
1✔
2067
                        }, {
1✔
2068
                            "value": 186.533_333_333_333_33,
1✔
2069
                            "color": [250, 127, 94, 255]
1✔
2070
                        }, {
1✔
2071
                            "value": 203.399_999_999_999_98,
1✔
2072
                            "color": [254, 159, 109, 255]
1✔
2073
                        }, {
1✔
2074
                            "value": 220.266_666_666_666_65,
1✔
2075
                            "color": [254, 191, 132, 255]
1✔
2076
                        }, {
1✔
2077
                            "value": 237.133_333_333_333_3,
1✔
2078
                            "color": [253, 222, 160, 255]
1✔
2079
                        }, {
1✔
2080
                            "value": 254,
1✔
2081
                            "color": [252, 253, 191, 255]
1✔
2082
                        }],
1✔
2083
                        "noDataColor": [0, 0, 0, 0],
1✔
2084
                        "overColor": [255, 255, 255, 127],
1✔
2085
                        "underColor": [255, 255, 255, 127]
1✔
2086
                    }
1✔
2087
                }
1✔
2088
            }]
1✔
2089
        }))
1✔
2090
        .unwrap();
1✔
2091

1✔
2092
        db.update_project(update).await.unwrap();
16✔
2093

1✔
2094
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2095
            "id": project_id.to_string(),
1✔
2096
            "layers": [{
1✔
2097
                "name": "NDVI",
1✔
2098
                "workflow": workflow_id.to_string(),
1✔
2099
                "visibility": {
1✔
2100
                    "data": true,
1✔
2101
                    "legend": false
1✔
2102
                },
1✔
2103
                "symbology": {
1✔
2104
                    "type": "raster",
1✔
2105
                    "opacity": 1,
1✔
2106
                    "colorizer": {
1✔
2107
                        "type": "linearGradient",
1✔
2108
                        "breakpoints": [{
1✔
2109
                            "value": 1,
1✔
2110
                            "color": [0, 0, 4, 255]
1✔
2111
                        }, {
1✔
2112
                            "value": 17.866_666_666_666_667,
1✔
2113
                            "color": [11, 9, 36, 255]
1✔
2114
                        }, {
1✔
2115
                            "value": 34.733_333_333_333_334,
1✔
2116
                            "color": [32, 17, 75, 255]
1✔
2117
                        }, {
1✔
2118
                            "value": 51.6,
1✔
2119
                            "color": [59, 15, 112, 255]
1✔
2120
                        }, {
1✔
2121
                            "value": 68.466_666_666_666_67,
1✔
2122
                            "color": [87, 21, 126, 255]
1✔
2123
                        }, {
1✔
2124
                            "value": 85.333_333_333_333_33,
1✔
2125
                            "color": [114, 31, 129, 255]
1✔
2126
                        }, {
1✔
2127
                            "value": 102.199_999_999_999_99,
1✔
2128
                            "color": [140, 41, 129, 255]
1✔
2129
                        }, {
1✔
2130
                            "value": 119.066_666_666_666_65,
1✔
2131
                            "color": [168, 50, 125, 255]
1✔
2132
                        }, {
1✔
2133
                            "value": 135.933_333_333_333_34,
1✔
2134
                            "color": [196, 60, 117, 255]
1✔
2135
                        }, {
1✔
2136
                            "value": 152.799_999_999_999_98,
1✔
2137
                            "color": [222, 73, 104, 255]
1✔
2138
                        }, {
1✔
2139
                            "value": 169.666_666_666_666_66,
1✔
2140
                            "color": [241, 96, 93, 255]
1✔
2141
                        }, {
1✔
2142
                            "value": 186.533_333_333_333_33,
1✔
2143
                            "color": [250, 127, 94, 255]
1✔
2144
                        }, {
1✔
2145
                            "value": 203.399_999_999_999_98,
1✔
2146
                            "color": [254, 159, 109, 255]
1✔
2147
                        }, {
1✔
2148
                            "value": 220.266_666_666_666_65,
1✔
2149
                            "color": [254, 191, 132, 255]
1✔
2150
                        }, {
1✔
2151
                            "value": 237.133_333_333_333_3,
1✔
2152
                            "color": [253, 222, 160, 255]
1✔
2153
                        }, {
1✔
2154
                            "value": 254,
1✔
2155
                            "color": [252, 253, 191, 255]
1✔
2156
                        }],
1✔
2157
                        "noDataColor": [0, 0, 0, 0],
1✔
2158
                        "overColor": [255, 255, 255, 127],
1✔
2159
                        "underColor": [255, 255, 255, 127]
1✔
2160
                    }
1✔
2161
                }
1✔
2162
            }]
1✔
2163
        }))
1✔
2164
        .unwrap();
1✔
2165

1✔
2166
        db.update_project(update).await.unwrap();
16✔
2167

1✔
2168
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2169
            "id": project_id.to_string(),
1✔
2170
            "layers": [{
1✔
2171
                "name": "NDVI",
1✔
2172
                "workflow": workflow_id.to_string(),
1✔
2173
                "visibility": {
1✔
2174
                    "data": true,
1✔
2175
                    "legend": false
1✔
2176
                },
1✔
2177
                "symbology": {
1✔
2178
                    "type": "raster",
1✔
2179
                    "opacity": 1,
1✔
2180
                    "colorizer": {
1✔
2181
                        "type": "linearGradient",
1✔
2182
                        "breakpoints": [{
1✔
2183
                            "value": 1,
1✔
2184
                            "color": [0, 0, 4, 255]
1✔
2185
                        }, {
1✔
2186
                            "value": 17.933_333_333_333_334,
1✔
2187
                            "color": [11, 9, 36, 255]
1✔
2188
                        }, {
1✔
2189
                            "value": 34.866_666_666_666_67,
1✔
2190
                            "color": [32, 17, 75, 255]
1✔
2191
                        }, {
1✔
2192
                            "value": 51.800_000_000_000_004,
1✔
2193
                            "color": [59, 15, 112, 255]
1✔
2194
                        }, {
1✔
2195
                            "value": 68.733_333_333_333_33,
1✔
2196
                            "color": [87, 21, 126, 255]
1✔
2197
                        }, {
1✔
2198
                            "value": 85.666_666_666_666_66,
1✔
2199
                            "color": [114, 31, 129, 255]
1✔
2200
                        }, {
1✔
2201
                            "value": 102.6,
1✔
2202
                            "color": [140, 41, 129, 255]
1✔
2203
                        }, {
1✔
2204
                            "value": 119.533_333_333_333_32,
1✔
2205
                            "color": [168, 50, 125, 255]
1✔
2206
                        }, {
1✔
2207
                            "value": 136.466_666_666_666_67,
1✔
2208
                            "color": [196, 60, 117, 255]
1✔
2209
                        }, {
1✔
2210
                            "value": 153.4,
1✔
2211
                            "color": [222, 73, 104, 255]
1✔
2212
                        }, {
1✔
2213
                            "value": 170.333_333_333_333_31,
1✔
2214
                            "color": [241, 96, 93, 255]
1✔
2215
                        }, {
1✔
2216
                            "value": 187.266_666_666_666_65,
1✔
2217
                            "color": [250, 127, 94, 255]
1✔
2218
                        }, {
1✔
2219
                            "value": 204.2,
1✔
2220
                            "color": [254, 159, 109, 255]
1✔
2221
                        }, {
1✔
2222
                            "value": 221.133_333_333_333_33,
1✔
2223
                            "color": [254, 191, 132, 255]
1✔
2224
                        }, {
1✔
2225
                            "value": 238.066_666_666_666_63,
1✔
2226
                            "color": [253, 222, 160, 255]
1✔
2227
                        }, {
1✔
2228
                            "value": 255,
1✔
2229
                            "color": [252, 253, 191, 255]
1✔
2230
                        }],
1✔
2231
                        "noDataColor": [0, 0, 0, 0],
1✔
2232
                        "overColor": [255, 255, 255, 127],
1✔
2233
                        "underColor": [255, 255, 255, 127]
1✔
2234
                    }
1✔
2235
                }
1✔
2236
            }]
1✔
2237
        }))
1✔
2238
        .unwrap();
1✔
2239

1✔
2240
        let update = update;
1✔
2241

2242
        // run two updates concurrently
2243
        let (r0, r1) = join!(db.update_project(update.clone()), db.update_project(update));
1✔
2244

2245
        assert!(r0.is_ok());
1✔
2246
        assert!(r1.is_ok());
1✔
2247
    }
1✔
2248

2249
    #[ge_context::test]
2✔
2250
    #[allow(clippy::too_many_lines)]
2251
    async fn it_resolves_dataset_names_to_ids(app_ctx: PostgresContext<NoTls>) {
1✔
2252
        let session = app_ctx.default_session().await.unwrap();
18✔
2253
        let db = app_ctx.session_context(session.clone()).db();
1✔
2254

1✔
2255
        let loading_info = OgrSourceDataset {
1✔
2256
            file_name: PathBuf::from("test.csv"),
1✔
2257
            layer_name: "test.csv".to_owned(),
1✔
2258
            data_type: Some(VectorDataType::MultiPoint),
1✔
2259
            time: OgrSourceDatasetTimeType::Start {
1✔
2260
                start_field: "start".to_owned(),
1✔
2261
                start_format: OgrSourceTimeFormat::Auto,
1✔
2262
                duration: OgrSourceDurationSpec::Zero,
1✔
2263
            },
1✔
2264
            default_geometry: None,
1✔
2265
            columns: Some(OgrSourceColumnSpec {
1✔
2266
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2267
                    header: CsvHeader::Auto,
1✔
2268
                }),
1✔
2269
                x: "x".to_owned(),
1✔
2270
                y: None,
1✔
2271
                int: vec![],
1✔
2272
                float: vec![],
1✔
2273
                text: vec![],
1✔
2274
                bool: vec![],
1✔
2275
                datetime: vec![],
1✔
2276
                rename: None,
1✔
2277
            }),
1✔
2278
            force_ogr_time_filter: false,
1✔
2279
            force_ogr_spatial_filter: false,
1✔
2280
            on_error: OgrSourceErrorSpec::Ignore,
1✔
2281
            sql_query: None,
1✔
2282
            attribute_query: None,
1✔
2283
            cache_ttl: CacheTtlSeconds::default(),
1✔
2284
        };
1✔
2285

1✔
2286
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2287
            OgrSourceDataset,
1✔
2288
            VectorResultDescriptor,
1✔
2289
            VectorQueryRectangle,
1✔
2290
        > {
1✔
2291
            loading_info: loading_info.clone(),
1✔
2292
            result_descriptor: VectorResultDescriptor {
1✔
2293
                data_type: VectorDataType::MultiPoint,
1✔
2294
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2295
                columns: [(
1✔
2296
                    "foo".to_owned(),
1✔
2297
                    VectorColumnInfo {
1✔
2298
                        data_type: FeatureDataType::Float,
1✔
2299
                        measurement: Measurement::Unitless,
1✔
2300
                    },
1✔
2301
                )]
1✔
2302
                .into_iter()
1✔
2303
                .collect(),
1✔
2304
                time: None,
1✔
2305
                bbox: None,
1✔
2306
            },
1✔
2307
            phantom: Default::default(),
1✔
2308
        });
1✔
2309

2310
        let DatasetIdAndName {
2311
            id: dataset_id1,
1✔
2312
            name: dataset_name1,
1✔
2313
        } = db
1✔
2314
            .add_dataset(
1✔
2315
                AddDataset {
1✔
2316
                    name: Some(DatasetName::new(None, "my_dataset".to_owned())),
1✔
2317
                    display_name: "Ogr Test".to_owned(),
1✔
2318
                    description: "desc".to_owned(),
1✔
2319
                    source_operator: "OgrSource".to_owned(),
1✔
2320
                    symbology: None,
1✔
2321
                    provenance: Some(vec![Provenance {
1✔
2322
                        citation: "citation".to_owned(),
1✔
2323
                        license: "license".to_owned(),
1✔
2324
                        uri: "uri".to_owned(),
1✔
2325
                    }]),
1✔
2326
                },
1✔
2327
                db.wrap_meta_data(meta_data.clone()),
1✔
2328
            )
1✔
2329
            .await
154✔
2330
            .unwrap();
1✔
2331

1✔
2332
        assert_eq!(
1✔
2333
            db.resolve_dataset_name_to_id(&dataset_name1).await.unwrap(),
3✔
2334
            dataset_id1
2335
        );
2336
    }
1✔
2337

2338
    #[ge_context::test]
2✔
2339
    #[allow(clippy::too_many_lines)]
2340
    async fn test_postgres_type_serialization(app_ctx: PostgresContext<NoTls>) {
1✔
2341
        let pool = app_ctx.pool.get().await.unwrap();
1✔
2342

1✔
2343
        assert_sql_type(&pool, "RgbaColor", [RgbaColor::new(0, 1, 2, 3)]).await;
4✔
2344

2345
        assert_sql_type(
1✔
2346
            &pool,
1✔
2347
            "double precision",
1✔
2348
            [NotNanF64::from(NotNan::<f64>::new(1.0).unwrap())],
1✔
2349
        )
1✔
2350
        .await;
2✔
2351

2352
        assert_sql_type(
1✔
2353
            &pool,
1✔
2354
            "Breakpoint",
1✔
2355
            [Breakpoint {
1✔
2356
                value: NotNan::<f64>::new(1.0).unwrap(),
1✔
2357
                color: RgbaColor::new(0, 0, 0, 0),
1✔
2358
            }],
1✔
2359
        )
1✔
2360
        .await;
5✔
2361

2362
        assert_sql_type(
1✔
2363
            &pool,
1✔
2364
            "DefaultColors",
1✔
2365
            [
1✔
2366
                DefaultColors::DefaultColor {
1✔
2367
                    default_color: RgbaColor::new(0, 10, 20, 30),
1✔
2368
                },
1✔
2369
                DefaultColors::OverUnder {
1✔
2370
                    over_color: RgbaColor::new(1, 2, 3, 4),
1✔
2371
                    under_color: RgbaColor::new(5, 6, 7, 8),
1✔
2372
                },
1✔
2373
            ],
1✔
2374
        )
1✔
2375
        .await;
6✔
2376

2377
        assert_sql_type(
1✔
2378
            &pool,
1✔
2379
            "Colorizer",
1✔
2380
            [
1✔
2381
                Colorizer::LinearGradient {
1✔
2382
                    breakpoints: vec![
1✔
2383
                        Breakpoint {
1✔
2384
                            value: NotNan::<f64>::new(-10.0).unwrap(),
1✔
2385
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
2386
                        },
1✔
2387
                        Breakpoint {
1✔
2388
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
2389
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
2390
                        },
1✔
2391
                    ],
1✔
2392
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
2393
                    default_colors: DefaultColors::OverUnder {
1✔
2394
                        over_color: RgbaColor::new(1, 2, 3, 4),
1✔
2395
                        under_color: RgbaColor::new(5, 6, 7, 8),
1✔
2396
                    },
1✔
2397
                },
1✔
2398
                Colorizer::LogarithmicGradient {
1✔
2399
                    breakpoints: vec![
1✔
2400
                        Breakpoint {
1✔
2401
                            value: NotNan::<f64>::new(1.0).unwrap(),
1✔
2402
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
2403
                        },
1✔
2404
                        Breakpoint {
1✔
2405
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
2406
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
2407
                        },
1✔
2408
                    ],
1✔
2409
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
2410
                    default_colors: DefaultColors::OverUnder {
1✔
2411
                        over_color: RgbaColor::new(1, 2, 3, 4),
1✔
2412
                        under_color: RgbaColor::new(5, 6, 7, 8),
1✔
2413
                    },
1✔
2414
                },
1✔
2415
                Colorizer::palette(
1✔
2416
                    [
1✔
2417
                        (NotNan::<f64>::new(1.0).unwrap(), RgbaColor::new(0, 0, 0, 0)),
1✔
2418
                        (
1✔
2419
                            NotNan::<f64>::new(2.0).unwrap(),
1✔
2420
                            RgbaColor::new(255, 0, 0, 255),
1✔
2421
                        ),
1✔
2422
                        (
1✔
2423
                            NotNan::<f64>::new(3.0).unwrap(),
1✔
2424
                            RgbaColor::new(0, 10, 20, 30),
1✔
2425
                        ),
1✔
2426
                    ]
1✔
2427
                    .into(),
1✔
2428
                    RgbaColor::new(1, 2, 3, 4),
1✔
2429
                    RgbaColor::new(5, 6, 7, 8),
1✔
2430
                )
1✔
2431
                .unwrap(),
1✔
2432
                Colorizer::Rgba,
1✔
2433
            ],
1✔
2434
        )
1✔
2435
        .await;
14✔
2436

2437
        assert_sql_type(
1✔
2438
            &pool,
1✔
2439
            "ColorParam",
1✔
2440
            [
1✔
2441
                ColorParam::Static {
1✔
2442
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
2443
                },
1✔
2444
                ColorParam::Derived(DerivedColor {
1✔
2445
                    attribute: "foobar".to_string(),
1✔
2446
                    colorizer: Colorizer::Rgba,
1✔
2447
                }),
1✔
2448
            ],
1✔
2449
        )
1✔
2450
        .await;
6✔
2451

2452
        assert_sql_type(
1✔
2453
            &pool,
1✔
2454
            "NumberParam",
1✔
2455
            [
1✔
2456
                NumberParam::Static { value: 42 },
1✔
2457
                NumberParam::Derived(DerivedNumber {
1✔
2458
                    attribute: "foobar".to_string(),
1✔
2459
                    factor: 1.0,
1✔
2460
                    default_value: 42.,
1✔
2461
                }),
1✔
2462
            ],
1✔
2463
        )
1✔
2464
        .await;
6✔
2465

2466
        assert_sql_type(
1✔
2467
            &pool,
1✔
2468
            "StrokeParam",
1✔
2469
            [StrokeParam {
1✔
2470
                width: NumberParam::Static { value: 42 },
1✔
2471
                color: ColorParam::Static {
1✔
2472
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
2473
                },
1✔
2474
            }],
1✔
2475
        )
1✔
2476
        .await;
4✔
2477

2478
        assert_sql_type(
1✔
2479
            &pool,
1✔
2480
            "TextSymbology",
1✔
2481
            [TextSymbology {
1✔
2482
                attribute: "attribute".to_string(),
1✔
2483
                fill_color: ColorParam::Static {
1✔
2484
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
2485
                },
1✔
2486
                stroke: StrokeParam {
1✔
2487
                    width: NumberParam::Static { value: 42 },
1✔
2488
                    color: ColorParam::Static {
1✔
2489
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
2490
                    },
1✔
2491
                },
1✔
2492
            }],
1✔
2493
        )
1✔
2494
        .await;
4✔
2495

2496
        assert_sql_type(
1✔
2497
            &pool,
1✔
2498
            "Symbology",
1✔
2499
            [
1✔
2500
                Symbology::Point(PointSymbology {
1✔
2501
                    fill_color: ColorParam::Static {
1✔
2502
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
2503
                    },
1✔
2504
                    stroke: StrokeParam {
1✔
2505
                        width: NumberParam::Static { value: 42 },
1✔
2506
                        color: ColorParam::Static {
1✔
2507
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
2508
                        },
1✔
2509
                    },
1✔
2510
                    radius: NumberParam::Static { value: 42 },
1✔
2511
                    text: Some(TextSymbology {
1✔
2512
                        attribute: "attribute".to_string(),
1✔
2513
                        fill_color: ColorParam::Static {
1✔
2514
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
2515
                        },
1✔
2516
                        stroke: StrokeParam {
1✔
2517
                            width: NumberParam::Static { value: 42 },
1✔
2518
                            color: ColorParam::Static {
1✔
2519
                                color: RgbaColor::new(0, 10, 20, 30),
1✔
2520
                            },
1✔
2521
                        },
1✔
2522
                    }),
1✔
2523
                }),
1✔
2524
                Symbology::Line(LineSymbology {
1✔
2525
                    stroke: StrokeParam {
1✔
2526
                        width: NumberParam::Static { value: 42 },
1✔
2527
                        color: ColorParam::Static {
1✔
2528
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
2529
                        },
1✔
2530
                    },
1✔
2531
                    text: Some(TextSymbology {
1✔
2532
                        attribute: "attribute".to_string(),
1✔
2533
                        fill_color: ColorParam::Static {
1✔
2534
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
2535
                        },
1✔
2536
                        stroke: StrokeParam {
1✔
2537
                            width: NumberParam::Static { value: 42 },
1✔
2538
                            color: ColorParam::Static {
1✔
2539
                                color: RgbaColor::new(0, 10, 20, 30),
1✔
2540
                            },
1✔
2541
                        },
1✔
2542
                    }),
1✔
2543
                    auto_simplified: true,
1✔
2544
                }),
1✔
2545
                Symbology::Polygon(PolygonSymbology {
1✔
2546
                    fill_color: ColorParam::Static {
1✔
2547
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
2548
                    },
1✔
2549
                    stroke: StrokeParam {
1✔
2550
                        width: NumberParam::Static { value: 42 },
1✔
2551
                        color: ColorParam::Static {
1✔
2552
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
2553
                        },
1✔
2554
                    },
1✔
2555
                    text: Some(TextSymbology {
1✔
2556
                        attribute: "attribute".to_string(),
1✔
2557
                        fill_color: ColorParam::Static {
1✔
2558
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
2559
                        },
1✔
2560
                        stroke: StrokeParam {
1✔
2561
                            width: NumberParam::Static { value: 42 },
1✔
2562
                            color: ColorParam::Static {
1✔
2563
                                color: RgbaColor::new(0, 10, 20, 30),
1✔
2564
                            },
1✔
2565
                        },
1✔
2566
                    }),
1✔
2567
                    auto_simplified: true,
1✔
2568
                }),
1✔
2569
                Symbology::Raster(RasterSymbology {
1✔
2570
                    opacity: 1.0,
1✔
2571
                    colorizer: Colorizer::LinearGradient {
1✔
2572
                        breakpoints: vec![
1✔
2573
                            Breakpoint {
1✔
2574
                                value: NotNan::<f64>::new(-10.0).unwrap(),
1✔
2575
                                color: RgbaColor::new(0, 0, 0, 0),
1✔
2576
                            },
1✔
2577
                            Breakpoint {
1✔
2578
                                value: NotNan::<f64>::new(2.0).unwrap(),
1✔
2579
                                color: RgbaColor::new(255, 0, 0, 255),
1✔
2580
                            },
1✔
2581
                        ],
1✔
2582
                        no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
2583
                        default_colors: DefaultColors::OverUnder {
1✔
2584
                            over_color: RgbaColor::new(1, 2, 3, 4),
1✔
2585
                            under_color: RgbaColor::new(5, 6, 7, 8),
1✔
2586
                        },
1✔
2587
                    },
1✔
2588
                }),
1✔
2589
            ],
1✔
2590
        )
1✔
2591
        .await;
18✔
2592

2593
        assert_sql_type(
1✔
2594
            &pool,
1✔
2595
            "RasterDataType",
1✔
2596
            [
1✔
2597
                RasterDataType::U8,
1✔
2598
                RasterDataType::U16,
1✔
2599
                RasterDataType::U32,
1✔
2600
                RasterDataType::U64,
1✔
2601
                RasterDataType::I8,
1✔
2602
                RasterDataType::I16,
1✔
2603
                RasterDataType::I32,
1✔
2604
                RasterDataType::I64,
1✔
2605
                RasterDataType::F32,
1✔
2606
                RasterDataType::F64,
1✔
2607
            ],
1✔
2608
        )
1✔
2609
        .await;
22✔
2610

2611
        assert_sql_type(
1✔
2612
            &pool,
1✔
2613
            "Measurement",
1✔
2614
            [
1✔
2615
                Measurement::Unitless,
1✔
2616
                Measurement::Continuous(ContinuousMeasurement {
1✔
2617
                    measurement: "Temperature".to_string(),
1✔
2618
                    unit: Some("°C".to_string()),
1✔
2619
                }),
1✔
2620
                Measurement::Classification(ClassificationMeasurement {
1✔
2621
                    measurement: "Color".to_string(),
1✔
2622
                    classes: [(1, "Grayscale".to_string()), (2, "Colorful".to_string())].into(),
1✔
2623
                }),
1✔
2624
            ],
1✔
2625
        )
1✔
2626
        .await;
15✔
2627

2628
        assert_sql_type(&pool, "Coordinate2D", [Coordinate2D::new(0.0f64, 1.)]).await;
4✔
2629

2630
        assert_sql_type(
1✔
2631
            &pool,
1✔
2632
            "SpatialPartition2D",
1✔
2633
            [
1✔
2634
                SpatialPartition2D::new(Coordinate2D::new(0.0f64, 1.), Coordinate2D::new(2., 0.5))
1✔
2635
                    .unwrap(),
1✔
2636
            ],
1✔
2637
        )
1✔
2638
        .await;
5✔
2639

2640
        assert_sql_type(
1✔
2641
            &pool,
1✔
2642
            "BoundingBox2D",
1✔
2643
            [
1✔
2644
                BoundingBox2D::new(Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0))
1✔
2645
                    .unwrap(),
1✔
2646
            ],
1✔
2647
        )
1✔
2648
        .await;
4✔
2649

2650
        assert_sql_type(
1✔
2651
            &pool,
1✔
2652
            "SpatialResolution",
1✔
2653
            [SpatialResolution { x: 1.2, y: 2.3 }],
1✔
2654
        )
1✔
2655
        .await;
4✔
2656

2657
        assert_sql_type(
1✔
2658
            &pool,
1✔
2659
            "VectorDataType",
1✔
2660
            [
1✔
2661
                VectorDataType::Data,
1✔
2662
                VectorDataType::MultiPoint,
1✔
2663
                VectorDataType::MultiLineString,
1✔
2664
                VectorDataType::MultiPolygon,
1✔
2665
            ],
1✔
2666
        )
1✔
2667
        .await;
10✔
2668

2669
        assert_sql_type(
1✔
2670
            &pool,
1✔
2671
            "FeatureDataType",
1✔
2672
            [
1✔
2673
                FeatureDataType::Category,
1✔
2674
                FeatureDataType::Int,
1✔
2675
                FeatureDataType::Float,
1✔
2676
                FeatureDataType::Text,
1✔
2677
                FeatureDataType::Bool,
1✔
2678
                FeatureDataType::DateTime,
1✔
2679
            ],
1✔
2680
        )
1✔
2681
        .await;
14✔
2682

2683
        assert_sql_type(&pool, "TimeInterval", [TimeInterval::default()]).await;
4✔
2684

2685
        assert_sql_type(
1✔
2686
            &pool,
1✔
2687
            "SpatialReference",
1✔
2688
            [
1✔
2689
                SpatialReferenceOption::Unreferenced,
1✔
2690
                SpatialReferenceOption::SpatialReference(SpatialReference::epsg_4326()),
1✔
2691
            ],
1✔
2692
        )
1✔
2693
        .await;
8✔
2694

2695
        assert_sql_type(
1✔
2696
            &pool,
1✔
2697
            "PlotResultDescriptor",
1✔
2698
            [PlotResultDescriptor {
1✔
2699
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
2700
                time: None,
1✔
2701
                bbox: None,
1✔
2702
            }],
1✔
2703
        )
1✔
2704
        .await;
4✔
2705

2706
        assert_sql_type(
1✔
2707
            &pool,
1✔
2708
            "VectorResultDescriptor",
1✔
2709
            [VectorResultDescriptor {
1✔
2710
                data_type: VectorDataType::MultiPoint,
1✔
2711
                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2712
                    SpatialReference::epsg_4326(),
1✔
2713
                ),
1✔
2714
                columns: [(
1✔
2715
                    "foo".to_string(),
1✔
2716
                    VectorColumnInfo {
1✔
2717
                        data_type: FeatureDataType::Int,
1✔
2718
                        measurement: Measurement::Unitless,
1✔
2719
                    },
1✔
2720
                )]
1✔
2721
                .into(),
1✔
2722
                time: Some(TimeInterval::default()),
1✔
2723
                bbox: Some(
1✔
2724
                    BoundingBox2D::new(Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0))
1✔
2725
                        .unwrap(),
1✔
2726
                ),
1✔
2727
            }],
1✔
2728
        )
1✔
2729
        .await;
7✔
2730

2731
        assert_sql_type(
1✔
2732
            &pool,
1✔
2733
            "RasterResultDescriptor",
1✔
2734
            [RasterResultDescriptor {
1✔
2735
                data_type: RasterDataType::U8,
1✔
2736
                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2737
                    SpatialReference::epsg_4326(),
1✔
2738
                ),
1✔
2739
                measurement: Measurement::Unitless,
1✔
2740
                time: Some(TimeInterval::default()),
1✔
2741
                bbox: Some(
1✔
2742
                    SpatialPartition2D::new(
1✔
2743
                        Coordinate2D::new(0.0f64, 1.),
1✔
2744
                        Coordinate2D::new(2., 0.5),
1✔
2745
                    )
1✔
2746
                    .unwrap(),
1✔
2747
                ),
1✔
2748
                resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }),
1✔
2749
            }],
1✔
2750
        )
1✔
2751
        .await;
4✔
2752

2753
        assert_sql_type(
1✔
2754
            &pool,
1✔
2755
            "ResultDescriptor",
1✔
2756
            [
1✔
2757
                TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
2758
                    data_type: VectorDataType::MultiPoint,
1✔
2759
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2760
                        SpatialReference::epsg_4326(),
1✔
2761
                    ),
1✔
2762
                    columns: [(
1✔
2763
                        "foo".to_string(),
1✔
2764
                        VectorColumnInfo {
1✔
2765
                            data_type: FeatureDataType::Int,
1✔
2766
                            measurement: Measurement::Unitless,
1✔
2767
                        },
1✔
2768
                    )]
1✔
2769
                    .into(),
1✔
2770
                    time: Some(TimeInterval::default()),
1✔
2771
                    bbox: Some(
1✔
2772
                        BoundingBox2D::new(
1✔
2773
                            Coordinate2D::new(0.0f64, 0.5),
1✔
2774
                            Coordinate2D::new(2., 1.0),
1✔
2775
                        )
1✔
2776
                        .unwrap(),
1✔
2777
                    ),
1✔
2778
                }),
1✔
2779
                TypedResultDescriptor::Raster(RasterResultDescriptor {
1✔
2780
                    data_type: RasterDataType::U8,
1✔
2781
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2782
                        SpatialReference::epsg_4326(),
1✔
2783
                    ),
1✔
2784
                    measurement: Measurement::Unitless,
1✔
2785
                    time: Some(TimeInterval::default()),
1✔
2786
                    bbox: Some(
1✔
2787
                        SpatialPartition2D::new(
1✔
2788
                            Coordinate2D::new(0.0f64, 1.),
1✔
2789
                            Coordinate2D::new(2., 0.5),
1✔
2790
                        )
1✔
2791
                        .unwrap(),
1✔
2792
                    ),
1✔
2793
                    resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }),
1✔
2794
                }),
1✔
2795
                TypedResultDescriptor::Plot(PlotResultDescriptor {
1✔
2796
                    spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
2797
                    time: None,
1✔
2798
                    bbox: None,
1✔
2799
                }),
1✔
2800
            ],
1✔
2801
        )
1✔
2802
        .await;
8✔
2803

2804
        assert_sql_type(
1✔
2805
            &pool,
1✔
2806
            "MockDatasetDataSourceLoadingInfo",
1✔
2807
            [MockDatasetDataSourceLoadingInfo {
1✔
2808
                points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
2809
            }],
1✔
2810
        )
1✔
2811
        .await;
5✔
2812

2813
        assert_sql_type(
1✔
2814
            &pool,
1✔
2815
            "OgrSourceTimeFormat",
1✔
2816
            [
1✔
2817
                OgrSourceTimeFormat::Auto,
1✔
2818
                OgrSourceTimeFormat::Custom {
1✔
2819
                    custom_format: geoengine_datatypes::primitives::DateTimeParseFormat::custom(
1✔
2820
                        "%Y-%m-%dT%H:%M:%S%.3fZ".to_string(),
1✔
2821
                    ),
1✔
2822
                },
1✔
2823
                OgrSourceTimeFormat::UnixTimeStamp {
1✔
2824
                    timestamp_type: UnixTimeStampType::EpochSeconds,
1✔
2825
                    fmt: geoengine_datatypes::primitives::DateTimeParseFormat::unix(),
1✔
2826
                },
1✔
2827
            ],
1✔
2828
        )
1✔
2829
        .await;
17✔
2830

2831
        assert_sql_type(
1✔
2832
            &pool,
1✔
2833
            "OgrSourceDurationSpec",
1✔
2834
            [
1✔
2835
                OgrSourceDurationSpec::Infinite,
1✔
2836
                OgrSourceDurationSpec::Zero,
1✔
2837
                OgrSourceDurationSpec::Value(TimeStep {
1✔
2838
                    granularity: TimeGranularity::Millis,
1✔
2839
                    step: 1000,
1✔
2840
                }),
1✔
2841
            ],
1✔
2842
        )
1✔
2843
        .await;
12✔
2844

2845
        assert_sql_type(
1✔
2846
            &pool,
1✔
2847
            "OgrSourceDatasetTimeType",
1✔
2848
            [
1✔
2849
                OgrSourceDatasetTimeType::None,
1✔
2850
                OgrSourceDatasetTimeType::Start {
1✔
2851
                    start_field: "start".to_string(),
1✔
2852
                    start_format: OgrSourceTimeFormat::Auto,
1✔
2853
                    duration: OgrSourceDurationSpec::Zero,
1✔
2854
                },
1✔
2855
                OgrSourceDatasetTimeType::StartEnd {
1✔
2856
                    start_field: "start".to_string(),
1✔
2857
                    start_format: OgrSourceTimeFormat::Auto,
1✔
2858
                    end_field: "end".to_string(),
1✔
2859
                    end_format: OgrSourceTimeFormat::Auto,
1✔
2860
                },
1✔
2861
                OgrSourceDatasetTimeType::StartDuration {
1✔
2862
                    start_field: "start".to_string(),
1✔
2863
                    start_format: OgrSourceTimeFormat::Auto,
1✔
2864
                    duration_field: "duration".to_string(),
1✔
2865
                },
1✔
2866
            ],
1✔
2867
        )
1✔
2868
        .await;
16✔
2869

2870
        assert_sql_type(
1✔
2871
            &pool,
1✔
2872
            "FormatSpecifics",
1✔
2873
            [FormatSpecifics::Csv {
1✔
2874
                header: CsvHeader::Yes,
1✔
2875
            }],
1✔
2876
        )
1✔
2877
        .await;
8✔
2878

2879
        assert_sql_type(
1✔
2880
            &pool,
1✔
2881
            "OgrSourceColumnSpec",
1✔
2882
            [OgrSourceColumnSpec {
1✔
2883
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2884
                    header: CsvHeader::Auto,
1✔
2885
                }),
1✔
2886
                x: "x".to_string(),
1✔
2887
                y: Some("y".to_string()),
1✔
2888
                int: vec!["int".to_string()],
1✔
2889
                float: vec!["float".to_string()],
1✔
2890
                text: vec!["text".to_string()],
1✔
2891
                bool: vec!["bool".to_string()],
1✔
2892
                datetime: vec!["datetime".to_string()],
1✔
2893
                rename: Some(
1✔
2894
                    [
1✔
2895
                        ("xx".to_string(), "xx_renamed".to_string()),
1✔
2896
                        ("yx".to_string(), "yy_renamed".to_string()),
1✔
2897
                    ]
1✔
2898
                    .into(),
1✔
2899
                ),
1✔
2900
            }],
1✔
2901
        )
1✔
2902
        .await;
7✔
2903

2904
        assert_sql_type(
1✔
2905
            &pool,
1✔
2906
            "point[]",
1✔
2907
            [MultiPoint::new(vec![
1✔
2908
                Coordinate2D::new(0.0f64, 0.5),
1✔
2909
                Coordinate2D::new(2., 1.0),
1✔
2910
            ])
1✔
2911
            .unwrap()],
1✔
2912
        )
1✔
2913
        .await;
2✔
2914

2915
        assert_sql_type(
1✔
2916
            &pool,
1✔
2917
            "path[]",
1✔
2918
            [MultiLineString::new(vec![
1✔
2919
                vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
2920
                vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
2921
            ])
1✔
2922
            .unwrap()],
1✔
2923
        )
1✔
2924
        .await;
2✔
2925

2926
        assert_sql_type(
1✔
2927
            &pool,
1✔
2928
            "\"Polygon\"[]",
1✔
2929
            [MultiPolygon::new(vec![
1✔
2930
                vec![
1✔
2931
                    vec![
1✔
2932
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2933
                        Coordinate2D::new(2., 1.0),
1✔
2934
                        Coordinate2D::new(2., 1.0),
1✔
2935
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2936
                    ],
1✔
2937
                    vec![
1✔
2938
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2939
                        Coordinate2D::new(2., 1.0),
1✔
2940
                        Coordinate2D::new(2., 1.0),
1✔
2941
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2942
                    ],
1✔
2943
                ],
1✔
2944
                vec![
1✔
2945
                    vec![
1✔
2946
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2947
                        Coordinate2D::new(2., 1.0),
1✔
2948
                        Coordinate2D::new(2., 1.0),
1✔
2949
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2950
                    ],
1✔
2951
                    vec![
1✔
2952
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2953
                        Coordinate2D::new(2., 1.0),
1✔
2954
                        Coordinate2D::new(2., 1.0),
1✔
2955
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2956
                    ],
1✔
2957
                ],
1✔
2958
            ])
1✔
2959
            .unwrap()],
1✔
2960
        )
1✔
2961
        .await;
4✔
2962

2963
        assert_sql_type(
1✔
2964
            &pool,
1✔
2965
            "TypedGeometry",
1✔
2966
            [
1✔
2967
                TypedGeometry::Data(NoGeometry),
1✔
2968
                TypedGeometry::MultiPoint(
1✔
2969
                    MultiPoint::new(vec![
1✔
2970
                        Coordinate2D::new(0.0f64, 0.5),
1✔
2971
                        Coordinate2D::new(2., 1.0),
1✔
2972
                    ])
1✔
2973
                    .unwrap(),
1✔
2974
                ),
1✔
2975
                TypedGeometry::MultiLineString(
1✔
2976
                    MultiLineString::new(vec![
1✔
2977
                        vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
2978
                        vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
2979
                    ])
1✔
2980
                    .unwrap(),
1✔
2981
                ),
1✔
2982
                TypedGeometry::MultiPolygon(
1✔
2983
                    MultiPolygon::new(vec![
1✔
2984
                        vec![
1✔
2985
                            vec![
1✔
2986
                                Coordinate2D::new(0.0f64, 0.5),
1✔
2987
                                Coordinate2D::new(2., 1.0),
1✔
2988
                                Coordinate2D::new(2., 1.0),
1✔
2989
                                Coordinate2D::new(0.0f64, 0.5),
1✔
2990
                            ],
1✔
2991
                            vec![
1✔
2992
                                Coordinate2D::new(0.0f64, 0.5),
1✔
2993
                                Coordinate2D::new(2., 1.0),
1✔
2994
                                Coordinate2D::new(2., 1.0),
1✔
2995
                                Coordinate2D::new(0.0f64, 0.5),
1✔
2996
                            ],
1✔
2997
                        ],
1✔
2998
                        vec![
1✔
2999
                            vec![
1✔
3000
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3001
                                Coordinate2D::new(2., 1.0),
1✔
3002
                                Coordinate2D::new(2., 1.0),
1✔
3003
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3004
                            ],
1✔
3005
                            vec![
1✔
3006
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3007
                                Coordinate2D::new(2., 1.0),
1✔
3008
                                Coordinate2D::new(2., 1.0),
1✔
3009
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3010
                            ],
1✔
3011
                        ],
1✔
3012
                    ])
1✔
3013
                    .unwrap(),
1✔
3014
                ),
1✔
3015
            ],
1✔
3016
        )
1✔
3017
        .await;
11✔
3018

3019
        assert_sql_type(&pool, "int", [CacheTtlSeconds::new(100)]).await;
2✔
3020

3021
        assert_sql_type(
1✔
3022
            &pool,
1✔
3023
            "OgrSourceDataset",
1✔
3024
            [OgrSourceDataset {
1✔
3025
                file_name: "test".into(),
1✔
3026
                layer_name: "test".to_string(),
1✔
3027
                data_type: Some(VectorDataType::MultiPoint),
1✔
3028
                time: OgrSourceDatasetTimeType::Start {
1✔
3029
                    start_field: "start".to_string(),
1✔
3030
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3031
                    duration: OgrSourceDurationSpec::Zero,
1✔
3032
                },
1✔
3033
                default_geometry: Some(TypedGeometry::MultiPoint(
1✔
3034
                    MultiPoint::new(vec![
1✔
3035
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3036
                        Coordinate2D::new(2., 1.0),
1✔
3037
                    ])
1✔
3038
                    .unwrap(),
1✔
3039
                )),
1✔
3040
                columns: Some(OgrSourceColumnSpec {
1✔
3041
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
3042
                        header: CsvHeader::Auto,
1✔
3043
                    }),
1✔
3044
                    x: "x".to_string(),
1✔
3045
                    y: Some("y".to_string()),
1✔
3046
                    int: vec!["int".to_string()],
1✔
3047
                    float: vec!["float".to_string()],
1✔
3048
                    text: vec!["text".to_string()],
1✔
3049
                    bool: vec!["bool".to_string()],
1✔
3050
                    datetime: vec!["datetime".to_string()],
1✔
3051
                    rename: Some(
1✔
3052
                        [
1✔
3053
                            ("xx".to_string(), "xx_renamed".to_string()),
1✔
3054
                            ("yx".to_string(), "yy_renamed".to_string()),
1✔
3055
                        ]
1✔
3056
                        .into(),
1✔
3057
                    ),
1✔
3058
                }),
1✔
3059
                force_ogr_time_filter: false,
1✔
3060
                force_ogr_spatial_filter: true,
1✔
3061
                on_error: OgrSourceErrorSpec::Abort,
1✔
3062
                sql_query: None,
1✔
3063
                attribute_query: Some("foo = 'bar'".to_string()),
1✔
3064
                cache_ttl: CacheTtlSeconds::new(5),
1✔
3065
            }],
1✔
3066
        )
1✔
3067
        .await;
6✔
3068

3069
        assert_sql_type(
1✔
3070
            &pool,
1✔
3071
            "MockMetaData",
1✔
3072
            [StaticMetaData::<
1✔
3073
                MockDatasetDataSourceLoadingInfo,
1✔
3074
                VectorResultDescriptor,
1✔
3075
                VectorQueryRectangle,
1✔
3076
            > {
1✔
3077
                loading_info: MockDatasetDataSourceLoadingInfo {
1✔
3078
                    points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3079
                },
1✔
3080
                result_descriptor: VectorResultDescriptor {
1✔
3081
                    data_type: VectorDataType::MultiPoint,
1✔
3082
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3083
                        SpatialReference::epsg_4326(),
1✔
3084
                    ),
1✔
3085
                    columns: [(
1✔
3086
                        "foo".to_string(),
1✔
3087
                        VectorColumnInfo {
1✔
3088
                            data_type: FeatureDataType::Int,
1✔
3089
                            measurement: Measurement::Unitless,
1✔
3090
                        },
1✔
3091
                    )]
1✔
3092
                    .into(),
1✔
3093
                    time: Some(TimeInterval::default()),
1✔
3094
                    bbox: Some(
1✔
3095
                        BoundingBox2D::new(
1✔
3096
                            Coordinate2D::new(0.0f64, 0.5),
1✔
3097
                            Coordinate2D::new(2., 1.0),
1✔
3098
                        )
1✔
3099
                        .unwrap(),
1✔
3100
                    ),
1✔
3101
                },
1✔
3102
                phantom: PhantomData,
1✔
3103
            }],
1✔
3104
        )
1✔
3105
        .await;
4✔
3106

3107
        assert_sql_type(
1✔
3108
            &pool,
1✔
3109
            "OgrMetaData",
1✔
3110
            [
1✔
3111
                StaticMetaData::<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle> {
1✔
3112
                    loading_info: OgrSourceDataset {
1✔
3113
                        file_name: "test".into(),
1✔
3114
                        layer_name: "test".to_string(),
1✔
3115
                        data_type: Some(VectorDataType::MultiPoint),
1✔
3116
                        time: OgrSourceDatasetTimeType::Start {
1✔
3117
                            start_field: "start".to_string(),
1✔
3118
                            start_format: OgrSourceTimeFormat::Auto,
1✔
3119
                            duration: OgrSourceDurationSpec::Zero,
1✔
3120
                        },
1✔
3121
                        default_geometry: Some(TypedGeometry::MultiPoint(
1✔
3122
                            MultiPoint::new(vec![
1✔
3123
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3124
                                Coordinate2D::new(2., 1.0),
1✔
3125
                            ])
1✔
3126
                            .unwrap(),
1✔
3127
                        )),
1✔
3128
                        columns: Some(OgrSourceColumnSpec {
1✔
3129
                            format_specifics: Some(FormatSpecifics::Csv {
1✔
3130
                                header: CsvHeader::Auto,
1✔
3131
                            }),
1✔
3132
                            x: "x".to_string(),
1✔
3133
                            y: Some("y".to_string()),
1✔
3134
                            int: vec!["int".to_string()],
1✔
3135
                            float: vec!["float".to_string()],
1✔
3136
                            text: vec!["text".to_string()],
1✔
3137
                            bool: vec!["bool".to_string()],
1✔
3138
                            datetime: vec!["datetime".to_string()],
1✔
3139
                            rename: Some(
1✔
3140
                                [
1✔
3141
                                    ("xx".to_string(), "xx_renamed".to_string()),
1✔
3142
                                    ("yx".to_string(), "yy_renamed".to_string()),
1✔
3143
                                ]
1✔
3144
                                .into(),
1✔
3145
                            ),
1✔
3146
                        }),
1✔
3147
                        force_ogr_time_filter: false,
1✔
3148
                        force_ogr_spatial_filter: true,
1✔
3149
                        on_error: OgrSourceErrorSpec::Abort,
1✔
3150
                        sql_query: None,
1✔
3151
                        attribute_query: Some("foo = 'bar'".to_string()),
1✔
3152
                        cache_ttl: CacheTtlSeconds::new(5),
1✔
3153
                    },
1✔
3154
                    result_descriptor: VectorResultDescriptor {
1✔
3155
                        data_type: VectorDataType::MultiPoint,
1✔
3156
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3157
                            SpatialReference::epsg_4326(),
1✔
3158
                        ),
1✔
3159
                        columns: [(
1✔
3160
                            "foo".to_string(),
1✔
3161
                            VectorColumnInfo {
1✔
3162
                                data_type: FeatureDataType::Int,
1✔
3163
                                measurement: Measurement::Unitless,
1✔
3164
                            },
1✔
3165
                        )]
1✔
3166
                        .into(),
1✔
3167
                        time: Some(TimeInterval::default()),
1✔
3168
                        bbox: Some(
1✔
3169
                            BoundingBox2D::new(
1✔
3170
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3171
                                Coordinate2D::new(2., 1.0),
1✔
3172
                            )
1✔
3173
                            .unwrap(),
1✔
3174
                        ),
1✔
3175
                    },
1✔
3176
                    phantom: PhantomData,
1✔
3177
                },
1✔
3178
            ],
1✔
3179
        )
1✔
3180
        .await;
4✔
3181

3182
        assert_sql_type(
1✔
3183
            &pool,
1✔
3184
            "GdalDatasetGeoTransform",
1✔
3185
            [GdalDatasetGeoTransform {
1✔
3186
                origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3187
                x_pixel_size: 1.0,
1✔
3188
                y_pixel_size: 2.0,
1✔
3189
            }],
1✔
3190
        )
1✔
3191
        .await;
4✔
3192

3193
        assert_sql_type(
1✔
3194
            &pool,
1✔
3195
            "FileNotFoundHandling",
1✔
3196
            [FileNotFoundHandling::NoData, FileNotFoundHandling::Error],
1✔
3197
        )
1✔
3198
        .await;
6✔
3199

3200
        assert_sql_type(
1✔
3201
            &pool,
1✔
3202
            "GdalMetadataMapping",
1✔
3203
            [GdalMetadataMapping {
1✔
3204
                source_key: RasterPropertiesKey {
1✔
3205
                    domain: None,
1✔
3206
                    key: "foo".to_string(),
1✔
3207
                },
1✔
3208
                target_key: RasterPropertiesKey {
1✔
3209
                    domain: Some("bar".to_string()),
1✔
3210
                    key: "foo".to_string(),
1✔
3211
                },
1✔
3212
                target_type: RasterPropertiesEntryType::String,
1✔
3213
            }],
1✔
3214
        )
1✔
3215
        .await;
8✔
3216

3217
        assert_sql_type(
1✔
3218
            &pool,
1✔
3219
            "StringPair",
1✔
3220
            [StringPair::from(("foo".to_string(), "bar".to_string()))],
1✔
3221
        )
1✔
3222
        .await;
3✔
3223

3224
        assert_sql_type(
1✔
3225
            &pool,
1✔
3226
            "GdalDatasetParameters",
1✔
3227
            [GdalDatasetParameters {
1✔
3228
                file_path: "text".into(),
1✔
3229
                rasterband_channel: 1,
1✔
3230
                geo_transform: GdalDatasetGeoTransform {
1✔
3231
                    origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3232
                    x_pixel_size: 1.0,
1✔
3233
                    y_pixel_size: 2.0,
1✔
3234
                },
1✔
3235
                width: 42,
1✔
3236
                height: 23,
1✔
3237
                file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3238
                no_data_value: Some(42.0),
1✔
3239
                properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3240
                    source_key: RasterPropertiesKey {
1✔
3241
                        domain: None,
1✔
3242
                        key: "foo".to_string(),
1✔
3243
                    },
1✔
3244
                    target_key: RasterPropertiesKey {
1✔
3245
                        domain: Some("bar".to_string()),
1✔
3246
                        key: "foo".to_string(),
1✔
3247
                    },
1✔
3248
                    target_type: RasterPropertiesEntryType::String,
1✔
3249
                }]),
1✔
3250
                gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3251
                gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3252
                allow_alphaband_as_mask: false,
1✔
3253
                retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3254
            }],
1✔
3255
        )
1✔
3256
        .await;
8✔
3257

3258
        assert_sql_type(
1✔
3259
            &pool,
1✔
3260
            "GdalMetaDataRegular",
1✔
3261
            [GdalMetaDataRegular {
1✔
3262
                result_descriptor: RasterResultDescriptor {
1✔
3263
                    data_type: RasterDataType::U8,
1✔
3264
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3265
                    measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3266
                        measurement: "Temperature".to_string(),
1✔
3267
                        unit: Some("°C".to_string()),
1✔
3268
                    }),
1✔
3269
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3270
                    bbox: Some(
1✔
3271
                        SpatialPartition2D::new(
1✔
3272
                            Coordinate2D::new(0.0f64, 1.),
1✔
3273
                            Coordinate2D::new(2., 0.5),
1✔
3274
                        )
1✔
3275
                        .unwrap(),
1✔
3276
                    ),
1✔
3277
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
3278
                },
1✔
3279
                params: GdalDatasetParameters {
1✔
3280
                    file_path: "text".into(),
1✔
3281
                    rasterband_channel: 1,
1✔
3282
                    geo_transform: GdalDatasetGeoTransform {
1✔
3283
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3284
                        x_pixel_size: 1.0,
1✔
3285
                        y_pixel_size: 2.0,
1✔
3286
                    },
1✔
3287
                    width: 42,
1✔
3288
                    height: 23,
1✔
3289
                    file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3290
                    no_data_value: Some(42.0),
1✔
3291
                    properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3292
                        source_key: RasterPropertiesKey {
1✔
3293
                            domain: None,
1✔
3294
                            key: "foo".to_string(),
1✔
3295
                        },
1✔
3296
                        target_key: RasterPropertiesKey {
1✔
3297
                            domain: Some("bar".to_string()),
1✔
3298
                            key: "foo".to_string(),
1✔
3299
                        },
1✔
3300
                        target_type: RasterPropertiesEntryType::String,
1✔
3301
                    }]),
1✔
3302
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3303
                    gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3304
                    allow_alphaband_as_mask: false,
1✔
3305
                    retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3306
                },
1✔
3307
                time_placeholders: [(
1✔
3308
                    "foo".to_string(),
1✔
3309
                    GdalSourceTimePlaceholder {
1✔
3310
                        format: geoengine_datatypes::primitives::DateTimeParseFormat::unix(),
1✔
3311
                        reference: TimeReference::Start,
1✔
3312
                    },
1✔
3313
                )]
1✔
3314
                .into(),
1✔
3315
                data_time: TimeInterval::new_unchecked(0, 1),
1✔
3316
                step: TimeStep {
1✔
3317
                    granularity: TimeGranularity::Millis,
1✔
3318
                    step: 1,
1✔
3319
                },
1✔
3320
                cache_ttl: CacheTtlSeconds::max(),
1✔
3321
            }],
1✔
3322
        )
1✔
3323
        .await;
12✔
3324

3325
        assert_sql_type(
1✔
3326
            &pool,
1✔
3327
            "GdalMetaDataStatic",
1✔
3328
            [GdalMetaDataStatic {
1✔
3329
                time: Some(TimeInterval::new_unchecked(0, 1)),
1✔
3330
                result_descriptor: RasterResultDescriptor {
1✔
3331
                    data_type: RasterDataType::U8,
1✔
3332
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3333
                    measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3334
                        measurement: "Temperature".to_string(),
1✔
3335
                        unit: Some("°C".to_string()),
1✔
3336
                    }),
1✔
3337
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3338
                    bbox: Some(
1✔
3339
                        SpatialPartition2D::new(
1✔
3340
                            Coordinate2D::new(0.0f64, 1.),
1✔
3341
                            Coordinate2D::new(2., 0.5),
1✔
3342
                        )
1✔
3343
                        .unwrap(),
1✔
3344
                    ),
1✔
3345
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
3346
                },
1✔
3347
                params: GdalDatasetParameters {
1✔
3348
                    file_path: "text".into(),
1✔
3349
                    rasterband_channel: 1,
1✔
3350
                    geo_transform: GdalDatasetGeoTransform {
1✔
3351
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3352
                        x_pixel_size: 1.0,
1✔
3353
                        y_pixel_size: 2.0,
1✔
3354
                    },
1✔
3355
                    width: 42,
1✔
3356
                    height: 23,
1✔
3357
                    file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3358
                    no_data_value: Some(42.0),
1✔
3359
                    properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3360
                        source_key: RasterPropertiesKey {
1✔
3361
                            domain: None,
1✔
3362
                            key: "foo".to_string(),
1✔
3363
                        },
1✔
3364
                        target_key: RasterPropertiesKey {
1✔
3365
                            domain: Some("bar".to_string()),
1✔
3366
                            key: "foo".to_string(),
1✔
3367
                        },
1✔
3368
                        target_type: RasterPropertiesEntryType::String,
1✔
3369
                    }]),
1✔
3370
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3371
                    gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3372
                    allow_alphaband_as_mask: false,
1✔
3373
                    retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3374
                },
1✔
3375
                cache_ttl: CacheTtlSeconds::max(),
1✔
3376
            }],
1✔
3377
        )
1✔
3378
        .await;
4✔
3379

3380
        assert_sql_type(
1✔
3381
            &pool,
1✔
3382
            "GdalMetadataNetCdfCf",
1✔
3383
            [GdalMetadataNetCdfCf {
1✔
3384
                result_descriptor: RasterResultDescriptor {
1✔
3385
                    data_type: RasterDataType::U8,
1✔
3386
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3387
                    measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3388
                        measurement: "Temperature".to_string(),
1✔
3389
                        unit: Some("°C".to_string()),
1✔
3390
                    }),
1✔
3391
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3392
                    bbox: Some(
1✔
3393
                        SpatialPartition2D::new(
1✔
3394
                            Coordinate2D::new(0.0f64, 1.),
1✔
3395
                            Coordinate2D::new(2., 0.5),
1✔
3396
                        )
1✔
3397
                        .unwrap(),
1✔
3398
                    ),
1✔
3399
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
3400
                },
1✔
3401
                params: GdalDatasetParameters {
1✔
3402
                    file_path: "text".into(),
1✔
3403
                    rasterband_channel: 1,
1✔
3404
                    geo_transform: GdalDatasetGeoTransform {
1✔
3405
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3406
                        x_pixel_size: 1.0,
1✔
3407
                        y_pixel_size: 2.0,
1✔
3408
                    },
1✔
3409
                    width: 42,
1✔
3410
                    height: 23,
1✔
3411
                    file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3412
                    no_data_value: Some(42.0),
1✔
3413
                    properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3414
                        source_key: RasterPropertiesKey {
1✔
3415
                            domain: None,
1✔
3416
                            key: "foo".to_string(),
1✔
3417
                        },
1✔
3418
                        target_key: RasterPropertiesKey {
1✔
3419
                            domain: Some("bar".to_string()),
1✔
3420
                            key: "foo".to_string(),
1✔
3421
                        },
1✔
3422
                        target_type: RasterPropertiesEntryType::String,
1✔
3423
                    }]),
1✔
3424
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3425
                    gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3426
                    allow_alphaband_as_mask: false,
1✔
3427
                    retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3428
                },
1✔
3429
                start: TimeInstance::from_millis(0).unwrap(),
1✔
3430
                end: TimeInstance::from_millis(1000).unwrap(),
1✔
3431
                cache_ttl: CacheTtlSeconds::max(),
1✔
3432
                step: TimeStep {
1✔
3433
                    granularity: TimeGranularity::Millis,
1✔
3434
                    step: 1,
1✔
3435
                },
1✔
3436
                band_offset: 3,
1✔
3437
            }],
1✔
3438
        )
1✔
3439
        .await;
4✔
3440

3441
        assert_sql_type(
1✔
3442
            &pool,
1✔
3443
            "GdalMetaDataList",
1✔
3444
            [GdalMetaDataList {
1✔
3445
                result_descriptor: RasterResultDescriptor {
1✔
3446
                    data_type: RasterDataType::U8,
1✔
3447
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3448
                    measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3449
                        measurement: "Temperature".to_string(),
1✔
3450
                        unit: Some("°C".to_string()),
1✔
3451
                    }),
1✔
3452
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3453
                    bbox: Some(
1✔
3454
                        SpatialPartition2D::new(
1✔
3455
                            Coordinate2D::new(0.0f64, 1.),
1✔
3456
                            Coordinate2D::new(2., 0.5),
1✔
3457
                        )
1✔
3458
                        .unwrap(),
1✔
3459
                    ),
1✔
3460
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
3461
                },
1✔
3462
                params: vec![GdalLoadingInfoTemporalSlice {
1✔
3463
                    time: TimeInterval::new_unchecked(0, 1),
1✔
3464
                    params: Some(GdalDatasetParameters {
1✔
3465
                        file_path: "text".into(),
1✔
3466
                        rasterband_channel: 1,
1✔
3467
                        geo_transform: GdalDatasetGeoTransform {
1✔
3468
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3469
                            x_pixel_size: 1.0,
1✔
3470
                            y_pixel_size: 2.0,
1✔
3471
                        },
1✔
3472
                        width: 42,
1✔
3473
                        height: 23,
1✔
3474
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3475
                        no_data_value: Some(42.0),
1✔
3476
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3477
                            source_key: RasterPropertiesKey {
1✔
3478
                                domain: None,
1✔
3479
                                key: "foo".to_string(),
1✔
3480
                            },
1✔
3481
                            target_key: RasterPropertiesKey {
1✔
3482
                                domain: Some("bar".to_string()),
1✔
3483
                                key: "foo".to_string(),
1✔
3484
                            },
1✔
3485
                            target_type: RasterPropertiesEntryType::String,
1✔
3486
                        }]),
1✔
3487
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3488
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3489
                        allow_alphaband_as_mask: false,
1✔
3490
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3491
                    }),
1✔
3492
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3493
                }],
1✔
3494
            }],
1✔
3495
        )
1✔
3496
        .await;
7✔
3497

3498
        assert_sql_type(
1✔
3499
            &pool,
1✔
3500
            "MetaDataDefinition",
1✔
3501
            [
1✔
3502
                MetaDataDefinition::MockMetaData(StaticMetaData::<
1✔
3503
                    MockDatasetDataSourceLoadingInfo,
1✔
3504
                    VectorResultDescriptor,
1✔
3505
                    VectorQueryRectangle,
1✔
3506
                > {
1✔
3507
                    loading_info: MockDatasetDataSourceLoadingInfo {
1✔
3508
                        points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3509
                    },
1✔
3510
                    result_descriptor: VectorResultDescriptor {
1✔
3511
                        data_type: VectorDataType::MultiPoint,
1✔
3512
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3513
                            SpatialReference::epsg_4326(),
1✔
3514
                        ),
1✔
3515
                        columns: [(
1✔
3516
                            "foo".to_string(),
1✔
3517
                            VectorColumnInfo {
1✔
3518
                                data_type: FeatureDataType::Int,
1✔
3519
                                measurement: Measurement::Unitless,
1✔
3520
                            },
1✔
3521
                        )]
1✔
3522
                        .into(),
1✔
3523
                        time: Some(TimeInterval::default()),
1✔
3524
                        bbox: Some(
1✔
3525
                            BoundingBox2D::new(
1✔
3526
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3527
                                Coordinate2D::new(2., 1.0),
1✔
3528
                            )
1✔
3529
                            .unwrap(),
1✔
3530
                        ),
1✔
3531
                    },
1✔
3532
                    phantom: PhantomData,
1✔
3533
                }),
1✔
3534
                MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
3535
                    OgrSourceDataset,
1✔
3536
                    VectorResultDescriptor,
1✔
3537
                    VectorQueryRectangle,
1✔
3538
                > {
1✔
3539
                    loading_info: OgrSourceDataset {
1✔
3540
                        file_name: "test".into(),
1✔
3541
                        layer_name: "test".to_string(),
1✔
3542
                        data_type: Some(VectorDataType::MultiPoint),
1✔
3543
                        time: OgrSourceDatasetTimeType::Start {
1✔
3544
                            start_field: "start".to_string(),
1✔
3545
                            start_format: OgrSourceTimeFormat::Auto,
1✔
3546
                            duration: OgrSourceDurationSpec::Zero,
1✔
3547
                        },
1✔
3548
                        default_geometry: Some(TypedGeometry::MultiPoint(
1✔
3549
                            MultiPoint::new(vec![
1✔
3550
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3551
                                Coordinate2D::new(2., 1.0),
1✔
3552
                            ])
1✔
3553
                            .unwrap(),
1✔
3554
                        )),
1✔
3555
                        columns: Some(OgrSourceColumnSpec {
1✔
3556
                            format_specifics: Some(FormatSpecifics::Csv {
1✔
3557
                                header: CsvHeader::Auto,
1✔
3558
                            }),
1✔
3559
                            x: "x".to_string(),
1✔
3560
                            y: Some("y".to_string()),
1✔
3561
                            int: vec!["int".to_string()],
1✔
3562
                            float: vec!["float".to_string()],
1✔
3563
                            text: vec!["text".to_string()],
1✔
3564
                            bool: vec!["bool".to_string()],
1✔
3565
                            datetime: vec!["datetime".to_string()],
1✔
3566
                            rename: Some(
1✔
3567
                                [
1✔
3568
                                    ("xx".to_string(), "xx_renamed".to_string()),
1✔
3569
                                    ("yx".to_string(), "yy_renamed".to_string()),
1✔
3570
                                ]
1✔
3571
                                .into(),
1✔
3572
                            ),
1✔
3573
                        }),
1✔
3574
                        force_ogr_time_filter: false,
1✔
3575
                        force_ogr_spatial_filter: true,
1✔
3576
                        on_error: OgrSourceErrorSpec::Abort,
1✔
3577
                        sql_query: None,
1✔
3578
                        attribute_query: Some("foo = 'bar'".to_string()),
1✔
3579
                        cache_ttl: CacheTtlSeconds::new(5),
1✔
3580
                    },
1✔
3581
                    result_descriptor: VectorResultDescriptor {
1✔
3582
                        data_type: VectorDataType::MultiPoint,
1✔
3583
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3584
                            SpatialReference::epsg_4326(),
1✔
3585
                        ),
1✔
3586
                        columns: [(
1✔
3587
                            "foo".to_string(),
1✔
3588
                            VectorColumnInfo {
1✔
3589
                                data_type: FeatureDataType::Int,
1✔
3590
                                measurement: Measurement::Unitless,
1✔
3591
                            },
1✔
3592
                        )]
1✔
3593
                        .into(),
1✔
3594
                        time: Some(TimeInterval::default()),
1✔
3595
                        bbox: Some(
1✔
3596
                            BoundingBox2D::new(
1✔
3597
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3598
                                Coordinate2D::new(2., 1.0),
1✔
3599
                            )
1✔
3600
                            .unwrap(),
1✔
3601
                        ),
1✔
3602
                    },
1✔
3603
                    phantom: PhantomData,
1✔
3604
                }),
1✔
3605
                MetaDataDefinition::GdalMetaDataRegular(GdalMetaDataRegular {
1✔
3606
                    result_descriptor: RasterResultDescriptor {
1✔
3607
                        data_type: RasterDataType::U8,
1✔
3608
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3609
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3610
                            measurement: "Temperature".to_string(),
1✔
3611
                            unit: Some("°C".to_string()),
1✔
3612
                        }),
1✔
3613
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3614
                        bbox: Some(
1✔
3615
                            SpatialPartition2D::new(
1✔
3616
                                Coordinate2D::new(0.0f64, 1.),
1✔
3617
                                Coordinate2D::new(2., 0.5),
1✔
3618
                            )
1✔
3619
                            .unwrap(),
1✔
3620
                        ),
1✔
3621
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3622
                    },
1✔
3623
                    params: GdalDatasetParameters {
1✔
3624
                        file_path: "text".into(),
1✔
3625
                        rasterband_channel: 1,
1✔
3626
                        geo_transform: GdalDatasetGeoTransform {
1✔
3627
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3628
                            x_pixel_size: 1.0,
1✔
3629
                            y_pixel_size: 2.0,
1✔
3630
                        },
1✔
3631
                        width: 42,
1✔
3632
                        height: 23,
1✔
3633
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3634
                        no_data_value: Some(42.0),
1✔
3635
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3636
                            source_key: RasterPropertiesKey {
1✔
3637
                                domain: None,
1✔
3638
                                key: "foo".to_string(),
1✔
3639
                            },
1✔
3640
                            target_key: RasterPropertiesKey {
1✔
3641
                                domain: Some("bar".to_string()),
1✔
3642
                                key: "foo".to_string(),
1✔
3643
                            },
1✔
3644
                            target_type: RasterPropertiesEntryType::String,
1✔
3645
                        }]),
1✔
3646
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3647
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3648
                        allow_alphaband_as_mask: false,
1✔
3649
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3650
                    },
1✔
3651
                    time_placeholders: [(
1✔
3652
                        "foo".to_string(),
1✔
3653
                        GdalSourceTimePlaceholder {
1✔
3654
                            format: DateTimeParseFormat::unix(),
1✔
3655
                            reference: TimeReference::Start,
1✔
3656
                        },
1✔
3657
                    )]
1✔
3658
                    .into(),
1✔
3659
                    data_time: TimeInterval::new_unchecked(0, 1),
1✔
3660
                    step: TimeStep {
1✔
3661
                        granularity: TimeGranularity::Millis,
1✔
3662
                        step: 1,
1✔
3663
                    },
1✔
3664
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3665
                }),
1✔
3666
                MetaDataDefinition::GdalStatic(GdalMetaDataStatic {
1✔
3667
                    time: Some(TimeInterval::new_unchecked(0, 1)),
1✔
3668
                    result_descriptor: RasterResultDescriptor {
1✔
3669
                        data_type: RasterDataType::U8,
1✔
3670
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3671
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3672
                            measurement: "Temperature".to_string(),
1✔
3673
                            unit: Some("°C".to_string()),
1✔
3674
                        }),
1✔
3675
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3676
                        bbox: Some(
1✔
3677
                            SpatialPartition2D::new(
1✔
3678
                                Coordinate2D::new(0.0f64, 1.),
1✔
3679
                                Coordinate2D::new(2., 0.5),
1✔
3680
                            )
1✔
3681
                            .unwrap(),
1✔
3682
                        ),
1✔
3683
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3684
                    },
1✔
3685
                    params: GdalDatasetParameters {
1✔
3686
                        file_path: "text".into(),
1✔
3687
                        rasterband_channel: 1,
1✔
3688
                        geo_transform: GdalDatasetGeoTransform {
1✔
3689
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3690
                            x_pixel_size: 1.0,
1✔
3691
                            y_pixel_size: 2.0,
1✔
3692
                        },
1✔
3693
                        width: 42,
1✔
3694
                        height: 23,
1✔
3695
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3696
                        no_data_value: Some(42.0),
1✔
3697
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3698
                            source_key: RasterPropertiesKey {
1✔
3699
                                domain: None,
1✔
3700
                                key: "foo".to_string(),
1✔
3701
                            },
1✔
3702
                            target_key: RasterPropertiesKey {
1✔
3703
                                domain: Some("bar".to_string()),
1✔
3704
                                key: "foo".to_string(),
1✔
3705
                            },
1✔
3706
                            target_type: RasterPropertiesEntryType::String,
1✔
3707
                        }]),
1✔
3708
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3709
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3710
                        allow_alphaband_as_mask: false,
1✔
3711
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3712
                    },
1✔
3713
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3714
                }),
1✔
3715
                MetaDataDefinition::GdalMetadataNetCdfCf(GdalMetadataNetCdfCf {
1✔
3716
                    result_descriptor: RasterResultDescriptor {
1✔
3717
                        data_type: RasterDataType::U8,
1✔
3718
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3719
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3720
                            measurement: "Temperature".to_string(),
1✔
3721
                            unit: Some("°C".to_string()),
1✔
3722
                        }),
1✔
3723
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3724
                        bbox: Some(
1✔
3725
                            SpatialPartition2D::new(
1✔
3726
                                Coordinate2D::new(0.0f64, 1.),
1✔
3727
                                Coordinate2D::new(2., 0.5),
1✔
3728
                            )
1✔
3729
                            .unwrap(),
1✔
3730
                        ),
1✔
3731
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3732
                    },
1✔
3733
                    params: GdalDatasetParameters {
1✔
3734
                        file_path: "text".into(),
1✔
3735
                        rasterband_channel: 1,
1✔
3736
                        geo_transform: GdalDatasetGeoTransform {
1✔
3737
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3738
                            x_pixel_size: 1.0,
1✔
3739
                            y_pixel_size: 2.0,
1✔
3740
                        },
1✔
3741
                        width: 42,
1✔
3742
                        height: 23,
1✔
3743
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3744
                        no_data_value: Some(42.0),
1✔
3745
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3746
                            source_key: RasterPropertiesKey {
1✔
3747
                                domain: None,
1✔
3748
                                key: "foo".to_string(),
1✔
3749
                            },
1✔
3750
                            target_key: RasterPropertiesKey {
1✔
3751
                                domain: Some("bar".to_string()),
1✔
3752
                                key: "foo".to_string(),
1✔
3753
                            },
1✔
3754
                            target_type: RasterPropertiesEntryType::String,
1✔
3755
                        }]),
1✔
3756
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3757
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3758
                        allow_alphaband_as_mask: false,
1✔
3759
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3760
                    },
1✔
3761
                    start: TimeInstance::from_millis(0).unwrap(),
1✔
3762
                    end: TimeInstance::from_millis(1000).unwrap(),
1✔
3763
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3764
                    step: TimeStep {
1✔
3765
                        granularity: TimeGranularity::Millis,
1✔
3766
                        step: 1,
1✔
3767
                    },
1✔
3768
                    band_offset: 3,
1✔
3769
                }),
1✔
3770
                MetaDataDefinition::GdalMetaDataList(GdalMetaDataList {
1✔
3771
                    result_descriptor: RasterResultDescriptor {
1✔
3772
                        data_type: RasterDataType::U8,
1✔
3773
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3774
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3775
                            measurement: "Temperature".to_string(),
1✔
3776
                            unit: Some("°C".to_string()),
1✔
3777
                        }),
1✔
3778
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3779
                        bbox: Some(
1✔
3780
                            SpatialPartition2D::new(
1✔
3781
                                Coordinate2D::new(0.0f64, 1.),
1✔
3782
                                Coordinate2D::new(2., 0.5),
1✔
3783
                            )
1✔
3784
                            .unwrap(),
1✔
3785
                        ),
1✔
3786
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3787
                    },
1✔
3788
                    params: vec![GdalLoadingInfoTemporalSlice {
1✔
3789
                        time: TimeInterval::new_unchecked(0, 1),
1✔
3790
                        params: Some(GdalDatasetParameters {
1✔
3791
                            file_path: "text".into(),
1✔
3792
                            rasterband_channel: 1,
1✔
3793
                            geo_transform: GdalDatasetGeoTransform {
1✔
3794
                                origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3795
                                x_pixel_size: 1.0,
1✔
3796
                                y_pixel_size: 2.0,
1✔
3797
                            },
1✔
3798
                            width: 42,
1✔
3799
                            height: 23,
1✔
3800
                            file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3801
                            no_data_value: Some(42.0),
1✔
3802
                            properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3803
                                source_key: RasterPropertiesKey {
1✔
3804
                                    domain: None,
1✔
3805
                                    key: "foo".to_string(),
1✔
3806
                                },
1✔
3807
                                target_key: RasterPropertiesKey {
1✔
3808
                                    domain: Some("bar".to_string()),
1✔
3809
                                    key: "foo".to_string(),
1✔
3810
                                },
1✔
3811
                                target_type: RasterPropertiesEntryType::String,
1✔
3812
                            }]),
1✔
3813
                            gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3814
                            gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3815
                            allow_alphaband_as_mask: false,
1✔
3816
                            retry: None,
1✔
3817
                        }),
1✔
3818
                        cache_ttl: CacheTtlSeconds::max(),
1✔
3819
                    }],
1✔
3820
                }),
1✔
3821
            ],
1✔
3822
        )
1✔
3823
        .await;
15✔
3824

3825
        test_data_provider_definition_types(&pool).await;
59✔
3826
    }
1✔
3827

3828
    #[test]
1✔
3829
    fn test_postgres_config_translation() {
1✔
3830
        let host = "localhost";
1✔
3831
        let port = 8095;
1✔
3832
        let ge_default = "geoengine";
1✔
3833
        let schema = "geoengine";
1✔
3834

1✔
3835
        let db_config = config::Postgres {
1✔
3836
            host: host.to_string(),
1✔
3837
            port,
1✔
3838
            database: ge_default.to_string(),
1✔
3839
            schema: schema.to_string(),
1✔
3840
            user: ge_default.to_string(),
1✔
3841
            password: ge_default.to_string(),
1✔
3842
            clear_database_on_start: false,
1✔
3843
        };
1✔
3844

1✔
3845
        let pg_config = Config::try_from(db_config).unwrap();
1✔
3846

1✔
3847
        assert_eq!(ge_default, pg_config.get_user().unwrap());
1✔
3848
        assert_eq!(
1✔
3849
            <str as AsRef<[u8]>>::as_ref(ge_default).to_vec(),
1✔
3850
            pg_config.get_password().unwrap()
1✔
3851
        );
1✔
3852
        assert_eq!(ge_default, pg_config.get_dbname().unwrap());
1✔
3853
        assert_eq!(
1✔
3854
            &format!("-c search_path={schema}"),
1✔
3855
            pg_config.get_options().unwrap()
1✔
3856
        );
1✔
3857
        assert_eq!(vec![Host::Tcp(host.to_string())], pg_config.get_hosts());
1✔
3858
        assert_eq!(vec![port], pg_config.get_ports());
1✔
3859
    }
1✔
3860

3861
    #[allow(clippy::too_many_lines)]
3862
    async fn test_data_provider_definition_types(
1✔
3863
        pool: &PooledConnection<'_, PostgresConnectionManager<tokio_postgres::NoTls>>,
1✔
3864
    ) {
1✔
3865
        assert_sql_type(
1✔
3866
            pool,
1✔
3867
            "ArunaDataProviderDefinition",
1✔
3868
            [ArunaDataProviderDefinition {
1✔
3869
                id: DataProviderId::from_str("86a7f7ce-1bab-4ce9-a32b-172c0f958ee0").unwrap(),
1✔
3870
                name: "NFDI".to_string(),
1✔
3871
                api_url: "http://test".to_string(),
1✔
3872
                project_id: "project".to_string(),
1✔
3873
                api_token: "api_token".to_string(),
1✔
3874
                filter_label: "filter".to_string(),
1✔
3875
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3876
            }],
1✔
3877
        )
1✔
3878
        .await;
4✔
3879

3880
        assert_sql_type(
1✔
3881
            pool,
1✔
3882
            "GbifDataProviderDefinition",
1✔
3883
            [GbifDataProviderDefinition {
1✔
3884
                name: "GBIF".to_string(),
1✔
3885
                db_config: DatabaseConnectionConfig {
1✔
3886
                    host: "testhost".to_string(),
1✔
3887
                    port: 1234,
1✔
3888
                    database: "testdb".to_string(),
1✔
3889
                    schema: "testschema".to_string(),
1✔
3890
                    user: "testuser".to_string(),
1✔
3891
                    password: "testpass".to_string(),
1✔
3892
                },
1✔
3893
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3894
            }],
1✔
3895
        )
1✔
3896
        .await;
6✔
3897

3898
        assert_sql_type(
1✔
3899
            pool,
1✔
3900
            "GfbioAbcdDataProviderDefinition",
1✔
3901
            [GfbioAbcdDataProviderDefinition {
1✔
3902
                name: "GFbio".to_string(),
1✔
3903
                db_config: DatabaseConnectionConfig {
1✔
3904
                    host: "testhost".to_string(),
1✔
3905
                    port: 1234,
1✔
3906
                    database: "testdb".to_string(),
1✔
3907
                    schema: "testschema".to_string(),
1✔
3908
                    user: "testuser".to_string(),
1✔
3909
                    password: "testpass".to_string(),
1✔
3910
                },
1✔
3911
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3912
            }],
1✔
3913
        )
1✔
3914
        .await;
4✔
3915

3916
        assert_sql_type(
1✔
3917
            pool,
1✔
3918
            "GfbioCollectionsDataProviderDefinition",
1✔
3919
            [GfbioCollectionsDataProviderDefinition {
1✔
3920
                name: "GFbio".to_string(),
1✔
3921
                collection_api_url: "http://testhost".try_into().unwrap(),
1✔
3922
                collection_api_auth_token: "token".to_string(),
1✔
3923
                abcd_db_config: DatabaseConnectionConfig {
1✔
3924
                    host: "testhost".to_string(),
1✔
3925
                    port: 1234,
1✔
3926
                    database: "testdb".to_string(),
1✔
3927
                    schema: "testschema".to_string(),
1✔
3928
                    user: "testuser".to_string(),
1✔
3929
                    password: "testpass".to_string(),
1✔
3930
                },
1✔
3931
                pangaea_url: "http://panaea".try_into().unwrap(),
1✔
3932
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3933
            }],
1✔
3934
        )
1✔
3935
        .await;
4✔
3936

3937
        assert_sql_type(pool, "\"PropertyType\"[]", [Vec::<Property>::new()]).await;
5✔
3938

3939
        assert_sql_type(
1✔
3940
            pool,
1✔
3941
            "EbvPortalDataProviderDefinition",
1✔
3942
            [EbvPortalDataProviderDefinition {
1✔
3943
                name: "ebv".to_string(),
1✔
3944
                path: "a_path".into(),
1✔
3945
                base_url: "http://base".try_into().unwrap(),
1✔
3946
                overviews: "another_path".into(),
1✔
3947
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3948
            }],
1✔
3949
        )
1✔
3950
        .await;
4✔
3951

3952
        assert_sql_type(
1✔
3953
            pool,
1✔
3954
            "NetCdfCfDataProviderDefinition",
1✔
3955
            [NetCdfCfDataProviderDefinition {
1✔
3956
                name: "netcdfcf".to_string(),
1✔
3957
                path: "a_path".into(),
1✔
3958
                overviews: "another_path".into(),
1✔
3959
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3960
            }],
1✔
3961
        )
1✔
3962
        .await;
4✔
3963

3964
        assert_sql_type(
1✔
3965
            pool,
1✔
3966
            "PangaeaDataProviderDefinition",
1✔
3967
            [PangaeaDataProviderDefinition {
1✔
3968
                name: "pangaea".to_string(),
1✔
3969
                base_url: "http://base".try_into().unwrap(),
1✔
3970
                cache_ttl: CacheTtlSeconds::new(0),
1✔
3971
            }],
1✔
3972
        )
1✔
3973
        .await;
5✔
3974

3975
        assert_sql_type(
1✔
3976
            pool,
1✔
3977
            "DataProviderDefinition",
1✔
3978
            [
1✔
3979
                TypedDataProviderDefinition::ArunaDataProviderDefinition(
1✔
3980
                    ArunaDataProviderDefinition {
1✔
3981
                        id: DataProviderId::from_str("86a7f7ce-1bab-4ce9-a32b-172c0f958ee0")
1✔
3982
                            .unwrap(),
1✔
3983
                        name: "NFDI".to_string(),
1✔
3984
                        api_url: "http://test".to_string(),
1✔
3985
                        project_id: "project".to_string(),
1✔
3986
                        api_token: "api_token".to_string(),
1✔
3987
                        filter_label: "filter".to_string(),
1✔
3988
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
3989
                    },
1✔
3990
                ),
1✔
3991
                TypedDataProviderDefinition::GbifDataProviderDefinition(
1✔
3992
                    GbifDataProviderDefinition {
1✔
3993
                        name: "GBIF".to_string(),
1✔
3994
                        db_config: DatabaseConnectionConfig {
1✔
3995
                            host: "testhost".to_string(),
1✔
3996
                            port: 1234,
1✔
3997
                            database: "testdb".to_string(),
1✔
3998
                            schema: "testschema".to_string(),
1✔
3999
                            user: "testuser".to_string(),
1✔
4000
                            password: "testpass".to_string(),
1✔
4001
                        },
1✔
4002
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4003
                    },
1✔
4004
                ),
1✔
4005
                TypedDataProviderDefinition::GfbioAbcdDataProviderDefinition(
1✔
4006
                    GfbioAbcdDataProviderDefinition {
1✔
4007
                        name: "GFbio".to_string(),
1✔
4008
                        db_config: DatabaseConnectionConfig {
1✔
4009
                            host: "testhost".to_string(),
1✔
4010
                            port: 1234,
1✔
4011
                            database: "testdb".to_string(),
1✔
4012
                            schema: "testschema".to_string(),
1✔
4013
                            user: "testuser".to_string(),
1✔
4014
                            password: "testpass".to_string(),
1✔
4015
                        },
1✔
4016
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4017
                    },
1✔
4018
                ),
1✔
4019
                TypedDataProviderDefinition::GfbioCollectionsDataProviderDefinition(
1✔
4020
                    GfbioCollectionsDataProviderDefinition {
1✔
4021
                        name: "GFbio".to_string(),
1✔
4022
                        collection_api_url: "http://testhost".try_into().unwrap(),
1✔
4023
                        collection_api_auth_token: "token".to_string(),
1✔
4024
                        abcd_db_config: DatabaseConnectionConfig {
1✔
4025
                            host: "testhost".to_string(),
1✔
4026
                            port: 1234,
1✔
4027
                            database: "testdb".to_string(),
1✔
4028
                            schema: "testschema".to_string(),
1✔
4029
                            user: "testuser".to_string(),
1✔
4030
                            password: "testpass".to_string(),
1✔
4031
                        },
1✔
4032
                        pangaea_url: "http://panaea".try_into().unwrap(),
1✔
4033
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4034
                    },
1✔
4035
                ),
1✔
4036
                TypedDataProviderDefinition::EbvPortalDataProviderDefinition(
1✔
4037
                    EbvPortalDataProviderDefinition {
1✔
4038
                        name: "ebv".to_string(),
1✔
4039
                        path: "a_path".into(),
1✔
4040
                        base_url: "http://base".try_into().unwrap(),
1✔
4041
                        overviews: "another_path".into(),
1✔
4042
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4043
                    },
1✔
4044
                ),
1✔
4045
                TypedDataProviderDefinition::NetCdfCfDataProviderDefinition(
1✔
4046
                    NetCdfCfDataProviderDefinition {
1✔
4047
                        name: "netcdfcf".to_string(),
1✔
4048
                        path: "a_path".into(),
1✔
4049
                        overviews: "another_path".into(),
1✔
4050
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4051
                    },
1✔
4052
                ),
1✔
4053
                TypedDataProviderDefinition::PangaeaDataProviderDefinition(
1✔
4054
                    PangaeaDataProviderDefinition {
1✔
4055
                        name: "pangaea".to_string(),
1✔
4056
                        base_url: "http://base".try_into().unwrap(),
1✔
4057
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4058
                    },
1✔
4059
                ),
1✔
4060
            ],
1✔
4061
        )
1✔
4062
        .await;
23✔
4063
    }
1✔
4064
}
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