-
Notifications
You must be signed in to change notification settings - Fork 29
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
add SQLite Backend #148
add SQLite Backend #148
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main reason we set -1
to be the metadata quadkey for DynamoDB is that DynamoDB is a no-sql database, so the values are any json document. In a relational database like SQLite, I think it would be more standard to expand each key. For the tiles
mapping, it would still only have two columns: quadkey
and tiles
, where quadkey
could be an integer and tiles
a JSONb. But I think standard schema for metadata would have it be a separate table, so that more fields could be their own columns.
Co-authored-by: Kyle Barron <[email protected]>
I agree this is quite of a hack, so following what you are saying we could create 2 tables, using the current
my only worry is that we have to hard code the schema of MosaicJSON, meaning that any change in the mosaicJSON will need to be reflected here to. |
No, I was suggesting one global metadata table for all mosaics, plus one data table for each mosaic. E.g. geopackage has So a global metadata table like
Yes... With relational databases you need to have a stable schema, or otherwise deal with database migration when your schema changes. You could still have a global metadata table + a data table for each mosaic, while still storing all fields as jsonb 🤷♂️ |
); | ||
""", | ||
self.metadata.dict(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit verbose, maybe there is a better way to write this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to named, not positional, arguments
@@ -101,7 +101,7 @@ def assets_for_point(self, lng: float, lat: float) -> List[str]: | |||
|
|||
@cached( | |||
TTLCache(maxsize=cache_config.maxsize, ttl=cache_config.ttl), | |||
key=lambda self, x, y, z: hashkey(self.path, x, y, z), | |||
key=lambda self, x, y, z: hashkey(self.path, x, y, z, self.mosaicid), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to the SQLite backend, but while writing the tests I realized that we were caching this even when the mosaic changed... to fix it we can use the mosaicid (built from the metadata, e.g mosaic version) to make sure we call the function when the mosaic has been updated.
@@ -151,7 +152,7 @@ def update( | |||
"""Update existing MosaicJSON on backend.""" | |||
logger.debug(f"Updating {self.mosaic_name}...") | |||
|
|||
new_mosaic = self.mosaic_def.from_features( | |||
new_mosaic = MosaicJSON.from_features( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using self.mosaic_def.from_features(
was a bit misleading
if not self.mosaic_def and not os.path.exists(self.db_path): | ||
raise MosaicNotFoundError( | ||
f"SQLite database not found at path {self.db_path}." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not create a file if mosaic_def
is not passed and file doesn't exist yet
Co-authored-by: Kyle Barron <[email protected]>
The SQLite MosaicJSON backend follows what we did in dynamoDB.mosaicjson_metadata
TableBy default we store the mosaic metadata in a
reserved
tablemosaicjson_metadata
. It's schema is following the mosaicJSON specification (minus thetiles
).Schema
{mosaic}
TableWhen creating a mosaic, the backend will update the
mosaicjson_metadata
table with the metadata and update a new table with themosaic_name
provided. This table will be used to store thetiles
info ({quadkey: [datasets]})Schema
path and mosaic name
The database can old multiple mosaics thus the user needs to pass it in the path name
To Do
ref #142