Add XArraySQLSource for N-dimensional scientific data#1741
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new optional xarray-backed SQL Source implementation to Lumen, enabling SQL queries (via xarray-sql/DataFusion) over N-dimensional scientific datasets and exposing each data variable as a SQL table.
Changes:
- Added
XArraySQLSourceto query xarray datasets with DataFusion SQL, plus schema/metadata/dimension-info helpers and async query APIs. - Added a new optional dependency group (
lumen[xarray]) for installing xarray + xarray-sql related packages. - Added a dedicated test suite for
XArraySQLSourceand wired an optional import intolumen.sources.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
pyproject.toml |
Adds xarray optional dependency group for the new source. |
lumen/sources/__init__.py |
Registers XArraySQLSource via optional import (graceful when deps missing). |
lumen/sources/xarray_sql.py |
Implements XArraySQLSource (DataFusion execution, schema/metadata, async APIs). |
lumen/tests/sources/test_xarray_sql.py |
Adds tests for construction, querying, schema/metadata, serialization, async. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1741 +/- ##
==========================================
+ Coverage 68.75% 69.75% +1.00%
==========================================
Files 171 173 +2
Lines 28979 29770 +791
==========================================
+ Hits 19924 20767 +843
+ Misses 9055 9003 -52 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ahuang11
left a comment
There was a problem hiding this comment.
Didn't read through it completely; I think there's a lot of duplication instead of just properly inheriting from parent.
|
Thanks for the review @ahuang11! You were absolutely right -- there was way too much duplication. I went through What I removed (334 lines net deleted):
The one override I kept: DataFusion does not support Test changes: removed test classes for deleted methods ( Let me know if there's anything else to clean up! |
|
Hey @ahuang11, pushed a follow-up fix (f812387) addressing the duplication feedback:
-101 lines, all 58 tests pass locally. I also noticed a few things I could harden further (like wiring |
|
Thanks I'll review when time allows. In the future, there's no need to tag me or other maintainers. We'll review as soon as we can. For reference: https://holoviz.org/contribute.html#using-ai-readme |
|
Thanks for the heads up, noted! I am really sorry, won't tag in the future. And thanks for the link. |
Adds a new optional source that enables SQL queries over xarray datasets via xarray-sql/DataFusion. Each data variable is exposed as a SQL table, inheriting from BaseSQLSource to avoid duplication. Includes documentation, 58 tests, and pyproject.toml extras for xarray dependencies.
189bb18 to
39eea3a
Compare
|
Thanks for rebuilding my draft PR; interestingly I lost xarray.py somewhere. I think what you have is in a decent state. I'd like to see how this works on a variety of datasets and edge cases, including large datasets that are go out of memory, xqlsystems/xarray-sql#93 (comment), non-linear grids, like RASM tutorial dataset, all the other file formats you listed (grib, h5), and perhaps some prints of the table metadata. |
|
Yeah sure, I'll put together a demo notebook covering these cases:
I'll add the results as a comment here once ready. |
… metadata - _resolve_chunks: use dataset.chunks directly instead of getattr - get_schema: expand comment explaining TABLESAMPLE/DataFusion chain - normalize_table: add step-by-step comments for clarity - get(): document __limit__ filter usage - _get_table_metadata: replace math.prod with var.size, add auxiliary coord descriptions for non-linear grids (e.g. RASM 2D lat/lon) - Add cfgrib/eccodes deps for GRIB file support - Add tests: engine detection, GRIB I/O, 2D auxiliary coord metadata
|
Hey!! You can check the notebook here, I have compiled all the 5 cases mentioned here : https://colab.research.google.com/drive/1jvvJS7J4bYMK09SUpCdIyVtKjK9pWekF |
|
I think this PR is really close; left a couple more comments; will do some testing with it and see if it's missing anything. |
Ofcc, surely will love to refactor if anything breaks... |
ahuang11
left a comment
There was a problem hiding this comment.
Just a minor comment about the h5 extensions; otherwise, I believe this will go in v1.2.0
- Remove .h5/.hdf5/.he5 from XARRAY_ENGINES (xarray doesn't handle pure HDF5 well, h5py is better for those) - Drop h5netcdf from xarray deps in pyproject.toml and pixi.toml - Add separate xarray-grib extra with cfgrib and eccodes - Update engine detection test
Fixed this!! Thanks for the constant review and suggestions!! |
Remove top-level import xarray/xarray_sql so installing xarray does not cause it to load by default. Use _check_xarray_available() helper and inline imports in methods that need them. Remove XArraySQLSource from sources/__init__.py -- other optional sources (Snowflake, BigQuery) are not imported there either.
|
Thanks! |
|
Thanks a lot for the merge!! |
Resolve conflicts from holoviz#1741 merge by adopting main's canonical XArraySQLSource implementation (class-level _xarray_engines, classmethod _detect_engine, dialect="any").
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Adds
XArraySQLSourceso Lumen can query xarray datasets (NetCDF, Zarr, HDF5, GRIB) with SQL via Apache DataFusion. Builds on the proof-of-concept from #1434 and addresses #1508.Each data variable in the dataset becomes a SQL table with coordinate columns. For example, a NetCDF file with an
airvariable on(time, lat, lon)dimensions gives you a table you can query like:Inherits from
BaseSQLSourceto reuse schema inference, caching, SQL transforms, andcreate_sql_expr_source. Optional dependency viapip install lumen[xarray].After
Tested with NOAA air temperature dataset (3.8M rows):
How Has This Been Tested?
58 tests covering construction (from dataset, file, zarr), SQL execution, schema/metadata, table normalization, serialization roundtrip, async, and resource cleanup.
AI Disclosure
I planned the architecture and integration strategy. AI tools helped scaffold the implementation and tests based on my design decisions. I reviewed and tested all code manually.