Skip to content

feat: script export — multi-statement follow-up to streaming Export (#99)#104

Merged
BorisTyshkevich merged 1 commit into
mainfrom
feat/export-script-99
Jul 1, 2026
Merged

feat: script export — multi-statement follow-up to streaming Export (#99)#104
BorisTyshkevich merged 1 commit into
mainfrom
feat/export-script-99

Conversation

@BorisTyshkevich

Copy link
Copy Markdown
Collaborator

What & why

Follow-up to #87. The editor's Export button only handled a single query — running Export on a multi-statement script silently no-oped/blocked. This adds a dedicated script-export flow:

  • exportEntry() dispatches by statement count: one statement keeps Export button: stream full query result to disk as TSV (File System Access API, uncapped, bypasses the grid) #87's single-file exportDirect path; more than one opens exportScriptEntry.
  • A directory picker (showDirectoryPicker, requested before any auth/config await — transient activation) is skipped entirely when the script has no row-returning statements.
  • exportScript runs statements sequentially in one shared ClickHouse HTTP session (sessionParamsFor), so SET / CREATE TEMPORARY TABLE state carries across statements. Row-returning statements stream uncapped to their own file (NNN-slug.ext, via the new pure scriptExportName helper); non-row statements run for effect and log OK/error with no file.
  • The log lives in tab.result.scriptExportmetadata only, never the exported rows, so a multi-million-row script export stays flat in memory. A new results.js branch (buildToolbar + renderScriptExportGrid) renders it live: #/Statement/Type/Status/File/Bytes/Time, ticked every 200ms.
  • Cancel aborts the active statement's own abort/query-id (kept separate from both the grid-run and single-export state), issues its own KILL QUERY, marks the rest Skipped, and keeps already-completed files. Stop-on-first-failure, no retry — a partially-written file shouldn't be silently re-attempted.
  • ch.exportQuery (from Export button: stream full query result to disk as TSV (File System Access API, uncapped, bypasses the grid) #87) already forwarded params, so session_id rides alongside query_id with no net.js change beyond a regression test.

Two re-entrancy/leak bugs found and fixed during self-review before this PR: exportScriptEntry now flips app.state.exporting before its own directory-picker/auth await (mirroring exportDirect, closing a double-click race); the live-render setInterval now starts inside exportScript's try so a throw can't leak it.

Manually verified end-to-end in a real Chromium browser (real editor, real button clicks, injected fetch/picker seams) — single-statement still uses the save-file picker, a 3-statement script opens the directory picker and produces exactly the expected per-statement file/log output, and Cancel mid-export correctly marks Cancelled/Skipped while keeping the completed file.

Closes #99

Checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_01EfEGDNjwJcudck7Dzm82Pu

)

Export on a multi-statement script now opens a directory picker and runs
each statement sequentially into its own file (row-returning) or logs it
for effect, sharing one ClickHouse session across the script. A live log
pane (metadata only, never the exported rows) shows status/file/bytes/
elapsed per statement; Cancel stops the active statement and skips the
rest while keeping completed files.

Closes #99

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EfEGDNjwJcudck7Dzm82Pu
@BorisTyshkevich BorisTyshkevich mentioned this pull request Jul 1, 2026
24 tasks
@BorisTyshkevich BorisTyshkevich merged commit 3558e4c into main Jul 1, 2026
6 checks passed
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.

Export script: run multi-statement SQL with log pane and multiple output files

1 participant