feat(zarr_fdw): add read-only Zarr v2/v3 scientific array FDW - #642
Open
HamzaMPSY wants to merge 1 commit into
Open
feat(zarr_fdw): add read-only Zarr v2/v3 scientific array FDW#642HamzaMPSY wants to merge 1 commit into
HamzaMPSY wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a read-only native Zarr FDW for querying multidimensional scientific arrays directly from PostgreSQL without importing or materializing the source dataset first.
The main use case is scientific and geospatial workloads where large arrays live in object storage while application, relational, or spatial metadata already lives in PostgreSQL/PostGIS.
For example, the goal is to make workflows such as this possible:
rather than requiring a separate ETL or Python/xarray service just to bridge the two systems.
What is included
Read-only Zarr v2 and a bounded Zarr v3 implementation.
Direct Zarr v3 arrays and indexed sharded arrays with bounded range reads.
S3-compatible storage.
Anonymous HTTPS object access with deliberately restricted networking behavior.
Confined local filesystem access.
Raw, gzip/zlib, Blosc/LZ4 and supported Zarr v3 codec pipelines including Zstandard and CRC32C.
Named N-dimensional arrays with rank 1–64.
Numeric dimension selectors by:
Conservative coordinate and chunk pruning with exact residual checks.
Lazy chunk-index iteration rather than materializing the Cartesian chunk set.
Bounded ordered prefetching, cancellation and a query-local compressed chunk cache.
Missing-chunk / fill-value handling.
CF packed-value decoding and CF time decoding for the currently supported calendar.
Dataset metadata inspection through
zarr_inspect().Scalar aggregate pushdown for
count,sum,avg,minandmax.Runtime Zarr I/O metrics exposed through
EXPLAIN ANALYZE.CRS discovery and PostGIS integration.
Point sampling, cell extraction, zonal statistics and spatial/time zonal statistics.
Initial OME-Zarr 0.5 multiscale discovery and explicit rank-2 level execution.
Deterministic MinIO-backed integration coverage plus unit/integration tests for codecs, chunking, selectors, spatial execution, missing chunks, sharding and safety bounds.
Execution model
A scan is reduced to a generic N-dimensional selection and then to a lazy chunk plan:
Selections are conservative: pruning is allowed to read more data than ultimately matches, but exact predicates are retained so pruning cannot change query results.
Large chunk sets are iterated lazily, and remote reads are bounded by both request count and byte budgets.
Why Zarr in PostgreSQL?
Zarr is increasingly used for cloud-native climate, weather, Earth-observation, microscopy and other multidimensional scientific datasets.
Those arrays can be hundreds of gigabytes, terabytes or larger, so loading them into PostgreSQL is generally the wrong storage model.
At the same time, the data scientists and applications need to relate those arrays to often already lives in Postgres:
The intent of this FDW is therefore not to turn PostgreSQL into xarray or a general numerical-computing engine.
It is to allow PostgreSQL to select and reduce the relevant portions of a remote scientific array, ideally reading only the necessary chunks, and combine the result with relational/PostGIS data.
Current scope and intentional limitations
This implementation is deliberately fail-closed for scientific semantics that it does not understand.
Some current boundaries are:
Unsupported cases return explicit errors rather than attempting potentially incorrect scientific interpretation.
Framework changes
Part of the aggregate work requires Wrappers-level planner/executor hooks so an FDW can safely decide whether a particular aggregate query can be executed remotely and return the aggregate result correctly.
I would especially appreciate guidance on this part.
If preferred, I can separate the generic framework changes from the Zarr FDW into a prerequisite PR so they can be reviewed independently.
Testing
The implementation includes deterministic local and MinIO-backed test fixtures covering both metadata and actual data scans.
The tests exercise areas including:
I am also validating the FDW against large public Zarr datasets over real S3-compatible and HTTPS endpoints to measure how much remote I/O can be avoided by selection and chunk pruning.
Feedback I am looking for
The main questions I would appreciate maintainer feedback on are:
I'm happy to reshape or split the work based on what would make it easiest to review and maintain.