Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: martin-cp can set metadata values #1038

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ lints.workspace = true
[package]
name = "martin"
# Once the release is published with the hash, update https://github.com/maplibre/homebrew-martin
version = "0.11.2"
version = "0.11.3"
authors = ["Stepan Kuzmin <[email protected]>", "Yuri Astrakhan <[email protected]>", "MapLibre contributors"]
description = "Blazing fast and lightweight tile server with PostGIS, MBTiles, and PMTiles support"
keywords = ["maps", "tiles", "mbtiles", "pmtiles", "postgis"]
Expand Down
21 changes: 21 additions & 0 deletions martin/src/bin/martin-cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ pub struct CopyArgs {
/// Skip generating a global hash for mbtiles validation. By default, `martin-cp` will compute and update `agg_tiles_hash` metadata value.
#[arg(long)]
pub skip_agg_tiles_hash: bool,
/// Set additional metadata values. Must be set as "key=value" pairs. Can be specified multiple times.
#[arg(long, value_name="KEY=VALUE", value_parser = parse_key_value)]
pub set_meta: Vec<(String, String)>,
}

fn parse_key_value(s: &str) -> Result<(String, String), String> {
let mut parts = s.splitn(2, '=');
let key = parts.next().unwrap();
let value = parts
.next()
.ok_or_else(|| format!("Invalid key=value pair: {s}"))?;
if key.is_empty() || value.is_empty() {
Err(format!("Invalid key=value pair: {s}"))
} else {
Ok((key.to_string(), value.to_string()))
}
}

async fn start(copy_args: CopierArgs) -> MartinCpResult<()> {
Expand Down Expand Up @@ -336,6 +352,11 @@ async fn run_tile_copy(args: CopyArgs, state: ServerState) -> MartinCpResult<()>

info!("{progress}");

for (key, value) in args.set_meta {
info!("Setting metadata key={key} value={value}");
mbt.set_metadata_value(&mut conn, &key, value).await?;
}

if !args.skip_agg_tiles_hash {
if progress.non_empty.load(Ordering::Relaxed) == 0 {
info!("No tiles were copied, skipping agg_tiles_hash computation");
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/martin-cp/flat-with-hash_metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ tilejson:
description: public.function_zxy_query_test
name: function_zxy_query_test
format: mvt
generator: martin-cp v0.11.2
generator: martin-cp v0.11.3
agg_tiles_hash: 9B931A386D6075D1DA55323BD4DBEDAE

2 changes: 1 addition & 1 deletion tests/expected/martin-cp/flat_metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ tilejson:
name: table_source
foo: '{"bar":"foo"}'
format: mvt
generator: martin-cp v0.11.2
generator: martin-cp v0.11.3
agg_tiles_hash: EF19FCBCE73ADE1C85E856E6BBA9B4C7

6 changes: 3 additions & 3 deletions tests/expected/martin-cp/normalized_metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tilejson:
- 85.0511
center:
- 0.0
- 20.0
- 0.0
- 0
description: 'One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. '
legend: |-
Expand All @@ -25,7 +25,7 @@ tilejson:
</div>
maxzoom: 1
minzoom: 0
name: Geography Class
name: normalized
template: |-
{{#__location__}}{{/__location__}}{{#__teaser__}}<div style="text-align:center;">

Expand All @@ -35,6 +35,6 @@ tilejson:
</div>{{/__teaser__}}{{#__full__}}{{/__full__}}
version: 1.0.0
format: png
generator: martin-cp v0.11.2
generator: martin-cp v0.11.3
agg_tiles_hash: A85C80BA1CE047E2D93DAC25C5179775

3 changes: 2 additions & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ if [[ "$MARTIN_CP_BIN" != "-" ]]; then
--min-zoom 0 --max-zoom 6 "--bbox=-2,-1,142.84,45"
test_martin_cp "normalized" "${CFG[@]}" \
--source geography-class-png --mbtiles-type normalized --concurrency 3 \
--min-zoom 0 --max-zoom 6 "--bbox=-2,-1,142.84,45"
--min-zoom 0 --max-zoom 6 "--bbox=-2,-1,142.84,45" \
--set-meta "name=normalized" --set-meta=center=0,0,0

unset DATABASE_URL

Expand Down
Loading