Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Sep 28, 2023
1 parent d52787a commit bcff949
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions 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 docs/src/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The original [MBTiles specification](https://github.com/mapbox/mbtiles-spec#read

A typical Normalized schema generated by tools like [tilelive-copy](https://github.com/mapbox/TileLive#bintilelive-copy) use MD5 hash in the `tile_id` column. The Martin's `mbtiles` tool can use this hash to verify the content of each tile. We also define a new `flat-with-hash` schema that stores the hash and tile data in the same table. This schema is more efficient than the `normalized` schema when data has no duplicate tiles (see below). Per tile validation is not available for `flat` schema.

Per-tile validation will catch individual invalid tiles, but it will not detect overall datastore corruption (e.g. missing tiles or tiles that shouldn't exist, or tiles with incorrect z/x/y values). For that, Martin `mbtiles` tool defines a new metadata value called `agg_tiles_hash`. The value is computed by hashing `cast(zoom_level AS text), cast(tile_column AS text), cast(tile_row AS text), tile_data` combined for all rows in the `tiles` table/view, ordered by z,x,y. In case there are no rows or all are NULL, the hash value of an empty string is used.
Per-tile validation will catch individual invalid tiles, but it will not detect overall datastore corruption (e.g. missing tiles or tiles that shouldn't exist, or tiles with incorrect z/x/y values). For that, Martin `mbtiles` tool defines a new metadata value called `agg_tiles_hash`. The value is computed by hashing `cast(zoom_level AS text), cast(tile_column AS text), cast(tile_row AS text), cast(tile_data as blob)` combined for all rows in the `tiles` table/view, ordered by z,x,y. In case there are no rows or all are NULL, the hash value of an empty string is used.

The `mbtiles` tool will compute `agg_tiles_hash` value when copying or validating mbtiles files.

Expand Down
27 changes: 14 additions & 13 deletions martin-mbtiles/src/mbtiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,20 +564,21 @@ where
let query = query(
// The md5_concat func will return NULL if there are no rows in the tiles table.
// For our use case, we will treat it as an empty string, and hash that.
// Note that in some weird rare cases, a column with blob type may be stored as an integer value
"SELECT
hex(
coalesce(
md5_concat(
cast(zoom_level AS text),
cast(tile_column AS text),
cast(tile_row AS text),
tile_data
),
md5('')
)
)
FROM tiles
ORDER BY zoom_level, tile_column, tile_row;",
hex(
coalesce(
md5_concat(
cast(zoom_level AS text),
cast(tile_column AS text),
cast(tile_row AS text),
cast(tile_data as blob)
),
md5('')
)
)
FROM tiles
ORDER BY zoom_level, tile_column, tile_row;",
);
Ok(query.fetch_one(conn).await?.get::<String, _>(0))
}
Expand Down

0 comments on commit bcff949

Please sign in to comment.