Skip to content

Commit

Permalink
Change some custom mimetypes and refactor default creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Jan 21, 2024
1 parent c470aaa commit 3246992
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions tiled/catalog/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,37 @@
from .core import check_catalog_database, initialize_database
from .explain import ExplainAsyncSession
from .mimetypes import (
AWKWARD_BUFFERS_MIMETYPE,
DEFAULT_ADAPTERS_BY_MIMETYPE,
PARQUET_MIMETYPE,
SPARSE_BLOCKS_PARQUET_MIMETYPE,
ZARR_MIMETYPE,
ZIP_MIMETYPE,
)
from .utils import SCHEME_PATTERN, ensure_uri

DEFAULT_ECHO = bool(int(os.getenv("TILED_ECHO_SQL", "0") or "0"))
INDEX_PATTERN = re.compile(r"^[A-Za-z0-9_-]+$")

# When data is uploaded, how is it saved?
# TODO: Make this configurable at Catalog construction time.
DEFAULT_CREATION_MIMETYPE = {
StructureFamily.array: ZARR_MIMETYPE,
StructureFamily.awkward: ZIP_MIMETYPE,
StructureFamily.awkward: AWKWARD_BUFFERS_MIMETYPE,
StructureFamily.table: PARQUET_MIMETYPE,
StructureFamily.sparse: SPARSE_BLOCKS_PARQUET_MIMETYPE,
}
CREATE_ADAPTER_BY_MIMETYPE = OneShotCachedMap(
DEFAULT_INIT_STORAGE = OneShotCachedMap(
{
ZARR_MIMETYPE: lambda: importlib.import_module(
StructureFamily.array: lambda: importlib.import_module(
"...adapters.zarr", __name__
).ZarrArrayAdapter.init_storage,
ZIP_MIMETYPE: lambda: importlib.import_module(
StructureFamily.awkward: lambda: importlib.import_module(
"...adapters.awkward_buffers", __name__
).AwkwardBuffersAdapter.init_storage,
PARQUET_MIMETYPE: lambda: importlib.import_module(
StructureFamily.table: lambda: importlib.import_module(
"...adapters.parquet", __name__
).ParquetDatasetAdapter.init_storage,
SPARSE_BLOCKS_PARQUET_MIMETYPE: lambda: importlib.import_module(
StructureFamily.sparse: lambda: importlib.import_module(
"...adapters.sparse_blocks_parquet", __name__
).SparseBlocksParquetAdapter.init_storage,
}
Expand Down Expand Up @@ -567,7 +569,7 @@ async def create_node(
data_uri = str(self.context.writable_storage) + "".join(
f"/{quote_plus(segment)}" for segment in (self.segments + [key])
)
init_storage = CREATE_ADAPTER_BY_MIMETYPE[data_source.mimetype]
init_storage = DEFAULT_INIT_STORAGE[structure_family]
assets = await ensure_awaitable(
init_storage, data_uri, data_source.structure
)
Expand Down
6 changes: 3 additions & 3 deletions tiled/catalog/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# OneShotCachedMap is used to defer imports. We don't want to pay up front
# for importing Readers that we will not actually use.
PARQUET_MIMETYPE = "application/x-parquet"
SPARSE_BLOCKS_PARQUET_MIMETYPE = "application/x-parquet-sparse" # HACK!
ZIP_MIMETYPE = "application/zip"
SPARSE_BLOCKS_PARQUET_MIMETYPE = "application/x-parquet;structure=sparse"
ZARR_MIMETYPE = "application/x-zarr"
AWKWARD_BUFFERS_MIMETYPE = "application/x-awkward-buffers"
DEFAULT_ADAPTERS_BY_MIMETYPE = OneShotCachedMap(
{
"image/tiff": lambda: importlib.import_module(
Expand Down Expand Up @@ -39,7 +39,7 @@
ZARR_MIMETYPE: lambda: importlib.import_module(
"...adapters.zarr", __name__
).read_zarr,
ZIP_MIMETYPE: lambda: importlib.import_module(
AWKWARD_BUFFERS_MIMETYPE: lambda: importlib.import_module(
"...adapters.awkward_buffers", __name__
).AwkwardBuffersAdapter.from_directory,
}
Expand Down

0 comments on commit 3246992

Please sign in to comment.