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(mbtiles) - Add validation to martin .mbtiles #741 #1689

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Auspicus
Copy link

@Auspicus Auspicus commented Feb 15, 2025

closes #741

validation_error.to_string(),
));
}
OnInvalid::Warn => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to do further processing of the validation_error to determine if this is a critical issue or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep wondering if "fast" and "skip" are actually the same thing. We should always do some basic validation - like making sure the tiles table exists with the right columns - or else we can't even use it. The only difference is in what we do afterwards - ignore the source or continue with it... So perhaps:

  • validation level is fast vs thorough (no skip)
  • severity would be good, warn, error
  • and the action could be abort or ignore source for error, and abort or ignore source or warn on warning?
  • we may even introduce warnings-as-errors parameter? (slowly building a compiler here :) )

Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like where you are going with this! I left a few minor comments inline.

A few overall thoughts:

  • we may have more than one type of "local source validation" (pmtiles, sprites, fonts, cog files, ...) - so we should keep CLI parameters simple and global (not mbtiles specific)
  • all configuration sources may introduce some format-specific validation steps, but we should try to keep them all consistent from configuration file perspective
  • we should have multi-level config: CLI / config file root / per source type / specific path/file
  • lets cleanup error handling dup code somehow
  • as i wrote more in depth in a comment, we may want to have warning-as-error non-default mode

overall, awesome work! I think it is pretty close to the working state. One last thing - usually you do not want to submit PRs from the main branch of your fork, but that's really a minor thing :)

@@ -149,8 +203,10 @@ mod tests {
pm-src3: https://example.org/file3.ext
pm-src4:
path: https://example.org/file4.ext
validate: thorough
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: probably best to put the simple key: value things before the nested ones - i.e. move these two above paths:

@@ -57,7 +57,7 @@ pub enum MbtError {
#[error("The destination file {0} is not empty. Some operations like creating a diff file require the destination file to be non-existent or empty.")]
NonEmptyTargetFile(PathBuf),

#[error("The file {0} does not have the required uniqueness constraint")]
#[error("The file {0} does not have the required uniqueness constraint. Try adding a unique index on the `map` or `tiles` table.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps link to https://maplibre.org/martin/mbtiles-schema.html - and also update that page to include some information about performance? Note that tiles is the only official requirement of an mbtiles, but it could be either a table or a view - and it would be difficult to explain all this in a few lines.

validation_error.to_string(),
));
}
OnInvalid::Warn => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep wondering if "fast" and "skip" are actually the same thing. We should always do some basic validation - like making sure the tiles table exists with the right columns - or else we can't even use it. The only difference is in what we do afterwards - ignore the source or continue with it... So perhaps:

  • validation level is fast vs thorough (no skip)
  • severity would be good, warn, error
  • and the action could be abort or ignore source for error, and abort or ignore source or warn on warning?
  • we may even introduce warnings-as-errors parameter? (slowly building a compiler here :) )

@@ -264,7 +270,11 @@ async fn resolve_int<T: SourceConfigExtras>(
let dup = if dup { "duplicate " } else { "" };
let id = idr.resolve(&id, url.to_string());
configs.insert(id.clone(), source);
results.push(cfg.custom.new_sources_url(id.clone(), url.clone()).await?);
match cfg.custom.new_sources_url(id.clone(), url.clone()).await {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not a big fan of all this dup code for each call to new_sources - i wonder if we can do this logic elsewhere, and here keep the simple ? operator as before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more validations to .mbtiles detection
2 participants