Skip to content

feat: initial SQL REPL for xarray-sql#118

Open
RohanDisa wants to merge 1 commit intoalxmrs:mainfrom
RohanDisa:feature/repl
Open

feat: initial SQL REPL for xarray-sql#118
RohanDisa wants to merge 1 commit intoalxmrs:mainfrom
RohanDisa:feature/repl

Conversation

@RohanDisa
Copy link
Contributor

  • Added xarray_sql/repl.py: first early REPL run via python -m xarray_sql.repl
  • Includes demo table air (xarray tutorial air_temperature, chunked) for quick testing
  • SQL queries at xarray-sql> prompt; exit via .quit / .exit
  • Results capped at 100 rows with overflow message
  • Command history via Up/Down arrows (readline; Windows needs pyreadline3)

Very early version; demo table is temporary and mainly for testing purposes

Copy link
Owner

@alxmrs alxmrs left a comment

Choose a reason for hiding this comment

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

Minor feedback, but overall, this seems like a great start for the REPL. I'm happy to chat with you about where to go next. Please review my notes and make fixes before merging.


# Enable up/down arrow history for input() (Unix/Mac built-in; Windows: pip install pyreadline3)
try:
import readline # noqa: F401
Copy link
Owner

Choose a reason for hiding this comment

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

This package was deprecated in 2022. Check out https://pypi.org/project/gnureadline/.

Copy link
Owner

Choose a reason for hiding this comment

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

I like the idea of using a library to handle this instead of rolling it ourselves.

Copy link
Owner

Choose a reason for hiding this comment

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

Lets add this dep as an extra in the pyproject.toml.

break

try:
result = ctx.sql(line).to_pandas()
Copy link
Owner

Choose a reason for hiding this comment

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

I recommend using native datafusion dataframes over pandas. I think all we'd need to do here is to call collect() instead of to_pandas().

Copy link
Owner

Choose a reason for hiding this comment

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

I believe that datafusion naturally truncates long lines.

Comment on lines +50 to +51
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm torn if we should swallow and log errors or exit upon error. For now, this seems fine.

@alxmrs
Copy link
Owner

alxmrs commented Mar 2, 2026

Hey @RohanDisa, I have a useful example for you: I'd love to match this CLI as closely as possible: https://lib.rs/crates/zarr-datafusion

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.

2 participants