Skip to content

feat(cli): vortex sql — interactive Calcite-backed SQL shell#161

Open
dfa1 wants to merge 2 commits into
mainfrom
feat/sql-tui
Open

feat(cli): vortex sql — interactive Calcite-backed SQL shell#161
dfa1 wants to merge 2 commits into
mainfrom
feat/sql-tui

Conversation

@dfa1

@dfa1 dfa1 commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

Adds vortex sql FILE.vortex [MORE...] — an interactive SQL shell over Vortex files, backed by the calcite module. Each file is registered as a table named after its filename stem (ohlc.vortexvtx.ohlc).

Split-pane TUI: multiline editor on top, scrollable result grid below.

UX

  • Submit: psql convention — Enter inserts a newline; the query runs only when the buffer ends with ;. Gives multiline for free (Shift+Enter is not detectable in a raw terminal).
  • Focus: Tab toggles editor ↔ result grid; in the grid, arrows / PgUp / PgDn scroll.
  • History: Up/Down at the editor's top/bottom edge recall the last 100 queries, persisted to ~/.vortex/sql_history (newline-escaped, consecutive-dup collapsed).
  • Esc clears the buffer, Ctrl-D quits.

Design

  • Queries execute synchronously on the render threadVortexTable opens its own reader per scan, so no separate I/O thread is needed for arena confinement. UI shows running… then repaints.
  • Reuses the existing Terminal/Ansi/Key TUI stack. Adds Key.Backspace (KeyDecoder maps 0x7F/0x08) for line editing.
  • ResultGrid snapshots a ResultSet (capped at 10k rows; truncation flagged in the status bar).

Tests

All green (cli suite 199 pass, incl. checkstyle):

  • VortexSqlTuiTest (6) — scripted FakeTerminal over a real in-memory Calcite connection + Vortex fixture: run-on-;, backspace correction, multiline newline, history recall, Tab focus, invalid-SQL error handling.
  • QueryHistoryTest (7), SqlCommandTest (4), KeyDecoderTest +backspace, KeyTest exhaustive switch.

Note

vortex-calcite (calcite-core + transitives: avatica, guava, …) now shades into the cli uber-jar, growing its size meaningfully. Flagged in the pom comment.

🤖 Generated with Claude Code

dfa1 and others added 2 commits June 25, 2026 20:09
Adds `sql FILE.vortex [MORE...]`, an interactive SQL REPL over Vortex
files using the calcite module. Split-pane TUI: a multiline editor on
top and a scrollable result grid below.

- Editor follows psql convention: Enter inserts a newline, a query runs
  only when the buffer ends with `;`. Tab toggles focus editor<->grid;
  Up/Down at the editor edge recall previous queries; Esc clears; Ctrl-D
  quits.
- QueryHistory persists the last 100 queries to ~/.vortex/sql_history,
  newline-escaped and consecutive-dup collapsed.
- ResultGrid snapshots a ResultSet (capped at 10k rows) for the grid.
- Reuses the existing Terminal/Ansi/Key TUI stack; adds Key.Backspace
  (KeyDecoder maps 0x7F/0x08) for line editing.

Queries execute synchronously on the render thread — VortexTable opens
its own reader per scan, so no separate I/O thread is needed for arena
confinement.

Note: vortex-calcite (calcite-core + transitives) now shades into the
cli uber-jar, growing its size.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Review fixes for the SQL shell, plus a keybinding cleanup:

- QueryHistory.persist() no longer throws on a failed write (read-only
  home, full disk). It is best-effort, mirroring the swallow in load(),
  so a write failure can never abort the running shell.
- The editor drops non-printable control bytes (Ctrl-A, Ctrl-U, …)
  instead of inserting them as invisible literal SQL text.
- Esc is now the universal quit key in every TUI (SQL shell, grid,
  inspector). The grid and inspector already quit on Esc; the SQL shell
  now does too, and all three advertise it in their status hints. Tab
  still toggles the SQL panes; Ctrl-D still quits.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant