Skip to content

Commit

Permalink
Merge branch 'main' into dashmap-based-catalog
Browse files Browse the repository at this point in the history
# Conflicts:
#	martin/src/source.rs
#	martin/src/srv/server.rs
#	martin/tests/pg_table_source_test.rs
  • Loading branch information
CommanderStorm committed Dec 15, 2024
2 parents be9634e + 12e5167 commit f941c65
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 163 deletions.
35 changes: 10 additions & 25 deletions martin/src/bin/martin-cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,46 +458,31 @@ mod tests {
let bbox_mi = Bounds::from_str("-86.6271,41.6811,-82.3095,45.8058").unwrap();
let bbox_usa = Bounds::from_str("-124.8489,24.3963,-66.8854,49.3843").unwrap();

assert_yaml_snapshot!(compute_tile_ranges(&args(&[world], &[0])), @r###"
---
- "0: (0,0) - (0,0)"
"###);
assert_yaml_snapshot!(compute_tile_ranges(&args(&[world], &[0])), @r#"- "0: (0,0) - (0,0)""#);

assert_yaml_snapshot!(compute_tile_ranges(&args(&[world], &[3,7])), @r###"
---
assert_yaml_snapshot!(compute_tile_ranges(&args(&[world], &[3,7])), @r#"
- "3: (0,0) - (7,7)"
- "7: (0,0) - (127,127)"
"###);
"#);

assert_yaml_snapshot!(compute_tile_ranges(&arg_minmax(&[world], 2, 4)), @r###"
---
assert_yaml_snapshot!(compute_tile_ranges(&arg_minmax(&[world], 2, 4)), @r#"
- "2: (0,0) - (3,3)"
- "3: (0,0) - (7,7)"
- "4: (0,0) - (15,15)"
"###);
"#);

assert_yaml_snapshot!(compute_tile_ranges(&args(&[world], &[14])), @r###"
---
- "14: (0,0) - (16383,16383)"
"###);
assert_yaml_snapshot!(compute_tile_ranges(&args(&[world], &[14])), @r#"- "14: (0,0) - (16383,16383)""#);

assert_yaml_snapshot!(compute_tile_ranges(&args(&[bbox_usa], &[14])), @r###"
---
- "14: (2509,5599) - (5147,7046)"
"###);
assert_yaml_snapshot!(compute_tile_ranges(&args(&[bbox_usa], &[14])), @r#"- "14: (2509,5599) - (5147,7046)""#);

assert_yaml_snapshot!(compute_tile_ranges(&args(&[bbox_usa, bbox_mi, bbox_ca], &[14])), @r###"
---
- "14: (2509,5599) - (5147,7046)"
"###);
assert_yaml_snapshot!(compute_tile_ranges(&args(&[bbox_usa, bbox_mi, bbox_ca], &[14])), @r#"- "14: (2509,5599) - (5147,7046)""#);

assert_yaml_snapshot!(compute_tile_ranges(&args(&[bbox_ca_south, bbox_mi, bbox_ca], &[14])), @r###"
---
assert_yaml_snapshot!(compute_tile_ranges(&args(&[bbox_ca_south, bbox_mi, bbox_ca], &[14])), @r#"
- "14: (2791,6499) - (2997,6624)"
- "14: (4249,5841) - (4446,6101)"
- "14: (2526,6081) - (2790,6624)"
- "14: (2791,6081) - (2997,6498)"
"###);
"#);
}

fn args(bbox: &[Bounds], zooms: &[u8]) -> CopyArgs {
Expand Down
6 changes: 3 additions & 3 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::config::{copy_unrecognized_config, UnrecognizedValues};
use crate::file_config::FileError::{
InvalidFilePath, InvalidSourceFilePath, InvalidSourceUrl, IoError,
};
use crate::source::{Source, TileInfoSources};
use crate::source::{TileInfoSource, TileInfoSources};
use crate::utils::{IdResolver, OptMainCache, OptOneMany};
use crate::MartinResult;
use crate::OptOneMany::{Many, One};
Expand Down Expand Up @@ -70,13 +70,13 @@ pub trait SourceConfigExtras: ConfigExtras {
&self,
id: String,
path: PathBuf,
) -> impl std::future::Future<Output = FileResult<Box<dyn Source>>> + Send;
) -> impl std::future::Future<Output = FileResult<TileInfoSource>> + Send;

fn new_sources_url(
&self,
id: String,
url: Url,
) -> impl std::future::Future<Output = FileResult<Box<dyn Source>>> + Send;
) -> impl std::future::Future<Output = FileResult<TileInfoSource>> + Send;
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions martin/src/mbtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use url::Url;
use crate::config::UnrecognizedValues;
use crate::file_config::FileError::{AcquireConnError, InvalidMetadata, IoError};
use crate::file_config::{ConfigExtras, FileResult, SourceConfigExtras};
use crate::source::{TileData, UrlQuery};
use crate::source::{TileData, TileInfoSource, UrlQuery};
use crate::{MartinResult, Source};

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand All @@ -30,14 +30,14 @@ impl ConfigExtras for MbtConfig {
}

impl SourceConfigExtras for MbtConfig {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>> {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<TileInfoSource> {
Ok(Box::new(MbtSource::new(id, path).await?))
}

// TODO: Remove #[allow] after switching to Rust/Clippy v1.78+ in CI
// See https://github.com/rust-lang/rust-clippy/pull/12323
#[allow(clippy::no_effect_underscore_binding)]
async fn new_sources_url(&self, _id: String, _url: Url) -> FileResult<Box<dyn Source>> {
async fn new_sources_url(&self, _id: String, _url: Url) -> FileResult<TileInfoSource> {
unreachable!()
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Source for MbtSource {
self.tile_info
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
152 changes: 70 additions & 82 deletions martin/src/pg/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,142 +496,130 @@ mod tests {
#[allow(clippy::too_many_lines)]
fn test_auto_publish_no_auto() {
let cfg = auto("{}");
assert_yaml_snapshot!(cfg, @r###"
---
auto_table:
source_id_format: "{table}"
auto_funcs:
source_id_format: "{function}"
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table:
source_id_format: "{table}"
auto_funcs:
source_id_format: "{function}"
"#);

let cfg = auto("tables: {}");
assert_yaml_snapshot!(cfg, @r###"
---
auto_table: ~
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r"
auto_table: ~
auto_funcs: ~
");

let cfg = auto("functions: {}");
assert_yaml_snapshot!(cfg, @r###"
---
auto_table: ~
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r"
auto_table: ~
auto_funcs: ~
");

let cfg = auto("auto_publish: true");
assert_yaml_snapshot!(cfg, @r###"
---
auto_table:
source_id_format: "{table}"
auto_funcs:
source_id_format: "{function}"
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table:
source_id_format: "{table}"
auto_funcs:
source_id_format: "{function}"
"#);

let cfg = auto("auto_publish: false");
assert_yaml_snapshot!(cfg, @r###"
---
auto_table: ~
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r"
auto_table: ~
auto_funcs: ~
");

let cfg = auto(indoc! {"
auto_publish:
from_schemas: public
tables: true"});
assert_yaml_snapshot!(cfg, @r###"
---
auto_table:
schemas:
- public
source_id_format: "{table}"
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table:
schemas:
- public
source_id_format: "{table}"
auto_funcs: ~
"#);

let cfg = auto(indoc! {"
auto_publish:
from_schemas: public
functions: true"});
assert_yaml_snapshot!(cfg, @r###"
---
auto_table: ~
auto_funcs:
schemas:
- public
source_id_format: "{function}"
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table: ~
auto_funcs:
schemas:
- public
source_id_format: "{function}"
"#);

let cfg = auto(indoc! {"
auto_publish:
from_schemas: public
tables: false"});
assert_yaml_snapshot!(cfg, @r###"
---
auto_table: ~
auto_funcs:
schemas:
- public
source_id_format: "{function}"
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table: ~
auto_funcs:
schemas:
- public
source_id_format: "{function}"
"#);

let cfg = auto(indoc! {"
auto_publish:
from_schemas: public
functions: false"});
assert_yaml_snapshot!(cfg, @r###"
---
auto_table:
schemas:
- public
source_id_format: "{table}"
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table:
schemas:
- public
source_id_format: "{table}"
auto_funcs: ~
"#);

let cfg = auto(indoc! {"
auto_publish:
from_schemas: public
tables:
from_schemas: osm
id_format: 'foo_{schema}.{table}_bar'"});
assert_yaml_snapshot!(cfg, @r###"
---
auto_table:
schemas:
- osm
- public
source_id_format: "foo_{schema}.{table}_bar"
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table:
schemas:
- osm
- public
source_id_format: "foo_{schema}.{table}_bar"
auto_funcs: ~
"#);

let cfg = auto(indoc! {"
auto_publish:
from_schemas: public
tables:
from_schemas: osm
source_id_format: '{schema}.{table}'"});
assert_yaml_snapshot!(cfg, @r###"
---
assert_yaml_snapshot!(cfg, @r#"
auto_table:
schemas:
- osm
- public
source_id_format: "{schema}.{table}"
auto_funcs: ~
"###);
"#);

let cfg = auto(indoc! {"
auto_publish:
tables:
from_schemas:
- osm
- public"});
assert_yaml_snapshot!(cfg, @r###"
---
auto_table:
schemas:
- osm
- public
source_id_format: "{table}"
auto_funcs: ~
"###);
assert_yaml_snapshot!(cfg, @r#"
auto_table:
schemas:
- osm
- public
source_id_format: "{table}"
auto_funcs: ~
"#);
}
}
4 changes: 2 additions & 2 deletions martin/src/pg/pg_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tilejson::TileJSON;
use crate::pg::pool::PgPool;
use crate::pg::utils::query_to_json;
use crate::pg::PgError::{GetTileError, GetTileWithQueryError, PrepareQueryError};
use crate::source::{Source, TileData, UrlQuery};
use crate::source::{Source, TileData, TileInfoSource, UrlQuery};
use crate::MartinResult;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Source for PgSource {
TileInfo::new(Mvt, Uncompressed)
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
8 changes: 4 additions & 4 deletions martin/src/pmtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use url::Url;
use crate::config::UnrecognizedValues;
use crate::file_config::FileError::{InvalidMetadata, InvalidUrlMetadata, IoError};
use crate::file_config::{ConfigExtras, FileError, FileResult, SourceConfigExtras};
use crate::source::UrlQuery;
use crate::source::{TileInfoSource, UrlQuery};
use crate::utils::cache::get_cached_value;
use crate::utils::{CacheKey, CacheValue, OptMainCache};
use crate::{MartinResult, Source, TileData};
Expand Down Expand Up @@ -134,13 +134,13 @@ impl SourceConfigExtras for PmtConfig {
true
}

async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>> {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<TileInfoSource> {
Ok(Box::new(
PmtFileSource::new(self.new_cached_source(), id, path).await?,
))
}

async fn new_sources_url(&self, id: String, url: Url) -> FileResult<Box<dyn Source>> {
async fn new_sources_url(&self, id: String, url: Url) -> FileResult<TileInfoSource> {
Ok(Box::new(
PmtHttpSource::new(
self.client.clone().unwrap(),
Expand Down Expand Up @@ -250,7 +250,7 @@ macro_rules! impl_pmtiles_source {
self.tile_info
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
4 changes: 2 additions & 2 deletions martin/src/srv/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub mod tests {
use tilejson::TileJSON;

use super::*;
use crate::source::{Source, TileData};
use crate::source::{Source, TileData, TileInfoSource};
use crate::UrlQuery;

#[derive(Debug, Clone)]
Expand All @@ -225,7 +225,7 @@ pub mod tests {
TileInfo::new(Format::Mvt, Encoding::Uncompressed)
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
Loading

0 comments on commit f941c65

Please sign in to comment.