Skip to content

feat(export): stream every format through the backend, with an All rows / Current results choice (#1238) - #1240

Merged
NewtTheWolf merged 1 commit into
TabularisDB:mainfrom
markankamaransheogarat-sys:feat/export-scope-streaming-1238
Nov 12, 2026
Merged

NewtTheWolf merged 1 commit into
TabularisDB:mainfrom
markankamaransheogarat-sys:feat/export-scope-streaming-1238

Conversation

@markankamaransheogarat-sys

@markankamaransheogarat-sys markankamaransheogarat-sys commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1238

Every entry of the Export menu (CSV, JSON, NDJSON, Markdown, HTML) streams through export_query_to_file when the grid is missing rows and 'All rows' is chosen, so the file holds the full result of the query. Plugin drivers receive NDJSON and HTML through this exact same streaming path. When the grid already holds the complete result, export uses the loaded-rows path to avoid unnecessary query re-runs. When the grid holds fewer rows than the query returns (or when the driver limits/truncates non-SELECT results without pagination, e.g. WITH ... SELECT, VALUES, SHOW, PRAGMA), the All rows / Current results selector lets the user choose between streaming the full query or exporting the loaded rows with a clear warning.

Backend (src-tauri/src/export/)

  • format.rs: ExportFormat gains Ndjson and Html; parse accepts ndjson / html (case-insensitive); extension() and mime_type() cover both new formats.
  • sink.rs:
    • NdjsonSink: one compact JSON object per row, every record (the last one included) ends with \n, empty stream -> empty file.
    • HtmlSink: writes a standalone document: head + <thead> on the first row, one <tr> per row, closing tags on finish. Escaping matches escapeHtml (& < > " '), \r\n/\n -> <br>, NULL -> null. Pads short rows with null cells. Formatted cleanly with rustfmt.
    • Updated doc comment references to point to packages/web-ui/src/utils/clipboard.ts.
    • The { column: value } row builder is shared by JsonSink and NdjsonSink (row_to_object).
  • export.rs: both new formats wired into run_export, so progress events and cancel work exactly as for the other formats.
  • tests.rs: tests covering NULL handling, value types, column order, escaping, line breaks, empty stream, trailing newline, null padding for short rows, and byte-exact HTML document output.

Frontend

  • packages/web-ui/src/utils/resultExport.ts:
    • ExportScope = "all" | "loaded".
    • hasUnloadedRows(result): true when getLoadedRowsExportLimit is non-null. Treats result.truncated without pagination as partial rows.
    • resolveExportScope(result, requested, canStream): streams only when rows are missing and All rows was requested.
  • packages/web-ui/src/pages/Editor.tsx:
    • The scope selector shows when rows are missing from the grid (including truncated non-paginated queries).
    • Scope choice is scoped per tab/result entry, falling back safely to "all".
  • packages/web-ui/src/api/contract.ts:
    • Added ndjson and html to QueryExportRequest.format.
  • packages/web-ui/src/i18n/locales/*.json (all 11): menu labels and scope picker strings.

Verification

  • Vitest: packages/web-ui/tests/utils/resultExport.test.ts passes with full coverage of paginated and truncated scenarios (32 tests).
  • Frontend production build: pnpm build (tsc -b && vite build) green.
  • Rust: rustfmt clean on src-tauri/src/export/sink.rs, types and arms compile cleanly.

Comment thread src/pages/Editor.tsx Outdated

const [showNewRowModal, setShowNewRowModal] = useState(false);
const [exportMenuOpen, setExportMenuOpen] = useState(false);
const [exportScope, setExportScope] = useState<ExportScope>("all");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SUGGESTION: Export scope is editor-wide and never resets

exportScope is one piece of state for the whole Editor, not per tab or per result. If the user picks "Current results" on one paged tab, every other paged tab that shows the selector later opens with "Current results" already selected. An export from there silently writes only the loaded rows instead of the full query result, which is the truncation this PR is meant to prevent. Consider resetting it to "all" when the active tab or result entry changes, or when the menu closes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed in b379770. The choice is now stored together with the tab id and result entry id it was made on. On any other tab or result the menu falls back to "All rows", so a "Current results" pick can't silently truncate another export.

@kilo-code-bot

kilo-code-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review of 188fe6f. The branch was rebuilt as a single commit on top of current main (27e9315), so the PR diff (23 files) was re-read in full rather than as a delta from 8359f01.

  • Backend export (src-tauri/src/export.rs, export/format.rs, export/sink.rs): ndjson and html are wired through ExportFormat::parse, extension and mime, and stream_to_sink. NdjsonSink and HtmlSink reuse the shared row_to_object and escape_html/html_cell helpers, pad short rows with null, and escape headers and cells. An empty stream yields a valid HTML document. No unhandled ExportFormat match sites remain elsewhere in the crate.
  • Frontend (Editor.tsx, resultExport.ts, multiResult.ts, types/editor.ts, contract.ts):
    • The scope choice is keyed to tab id and result entry id, so a "Current results" pick does not leak to other tabs or results.
    • Split result sets (fromResultSets) always export from the grid.
    • On multi-result tabs, only the active statement is re-run.
    • getLoadedRowsExportLimit now also treats truncated results as partial.
  • i18n: exportScope, exportScopeAll and exportScopeLoaded are present across the 11 changed locales, and the removed exportLoadedNdjson and exportLoadedHtml keys have no remaining references in this PR's scope.
  • Tests: New unit tests cover both sinks, format parsing, hasUnloadedRows and resolveExportScope. The web audit test runs in an isolated child process with an env-var recursion guard.

The earlier export-scope finding stays resolved.

Files Reviewed (23 files)
  • packages/web-ui/src/api/contract.ts
  • packages/web-ui/src/i18n/locales/{de,en,es,fr,it,ja,ko,pt-BR,ru,tl,zh}.json
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/types/editor.ts
  • packages/web-ui/src/utils/multiResult.ts
  • packages/web-ui/src/utils/resultExport.ts
  • packages/web-ui/tests/utils/multiResult.test.ts
  • packages/web-ui/tests/utils/resultExport.test.ts
  • src-tauri/src/export.rs
  • src-tauri/src/export/format.rs
  • src-tauri/src/export/sink.rs
  • src-tauri/src/export/tests.rs
  • src-tauri/src/transport/web/tests.rs

Notes: Read-only review; tests were not run.

Previous Review Summaries (6 snapshots, latest commit 8359f01)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 8359f01)

Status: No Issues Found | Recommendation: Merge

Incremental review of 8359f01. Changes since the previously reviewed commit (d951de8):

  • A merge of main into the branch (63d026c9). The merged-in files belong to the base branch and are outside this PR's diff, so they were not reviewed here.
  • src-tauri/src/transport/web/tests.rs: authenticates_remote_password_and_proxy_requests_with_auditing now re-runs itself in a child process with RUST_LOG=info. This keeps the audit-log assertions away from other web tests that clear or disable the process-wide log buffer. The TABULARIS_WEB_AUDIT_TEST_CHILD env guard prevents recursion, .output() waits for the child, and --exact makes the "1 passed" check reliable. No functional issue found.

Earlier findings stay resolved. The only inline comment (export scope persisting across tabs) was addressed in b379770.

Files Reviewed (1 file in incremental diff)
  • src-tauri/src/transport/web/tests.rs

Notes: Read-only review; tests were not run.

Previous review (commit d951de8)

Status: No Issues Found | Recommendation: Merge

Incremental review of d951de8. Changes since the previously reviewed commit (10b66c1):

  • resultExport.ts: getLoadedRowsExportLimit now treats a driver-truncated result (truncated: true, no pagination) as partial and returns totalRows: null. The QueryResult.truncated field exists in types/editor.ts, and the caller in Editor.tsx already handles a null total with the "unknown total" warning. hasUnloadedRows and resolveExportScope pick up the change correctly.
  • resultExport.test.ts: adds tests covering the truncated-without-pagination case for both functions.
  • sink.rs: doc-comment path updates and a rustfmt-style reformat of the HTML cell closure, with no behaviour change.

Earlier findings stay resolved, and no new issues were found.

Files Reviewed (3 files in incremental diff)
  • packages/web-ui/src/utils/resultExport.ts
  • packages/web-ui/tests/utils/resultExport.test.ts
  • src-tauri/src/export/sink.rs

Notes: Read-only review; tests were not run.

Previous review (commit 10b66c1)

Status: No Issues Found | Recommendation: Merge

Incremental review of 10b66c1. The only change since the previously reviewed commit (4f30b5d) is a one-line update in web-ui-project/docs/web-ui-parity.json, moving the Editor.tsx line reference from 726 to 740. That line now points at the invoke('set_window_title', ...) call, so the reference is correct. Earlier findings stay resolved, and no new issues were found.

Files Reviewed (1 file in incremental diff)
  • web-ui-project/docs/web-ui-parity.json

Notes: Read-only review; tests were not run.

Previous review (commit 4f30b5d)

Status: No Issues Found | Recommendation: Merge

Incremental review of 4f30b5d. The earlier exportScope suggestion stays fixed, and the new commit adds no issues:

  • resolveExportScope now streams through the backend only when rows are actually missing and "All rows" was requested. A fully loaded grid is written as-is, so the query is not re-executed. Its unit test matches.
  • QueryExportRequest.format now allows ndjson and html, in line with ExportFormat::parse.
  • ExportFormat::extension and mime_type now cover Ndjson and Html, so the generated download gets the right file extension and MIME type.
  • HtmlSink::write_row pads short rows with null cells, with a test added.
Files Reviewed (6 files in incremental diff)
  • packages/web-ui/src/api/contract.ts
  • packages/web-ui/src/utils/resultExport.ts
  • packages/web-ui/tests/utils/resultExport.test.ts
  • src-tauri/src/export/format.rs
  • src-tauri/src/export/sink.rs
  • src-tauri/src/export/tests.rs

Notes: The branch was rebased onto a newer main that moved the frontend into packages/web-ui, so the diff against the previous SHA is very large. The review covered only the PR's own changes and the new commit. Tests were not run (read-only review).

Previous review (commit b379770)

Status: No Issues Found | Recommendation: Merge

The earlier suggestion about exportScope leaking across tabs is fixed in b379770. The scope choice is now stored with the tab id and result entry id it was made on, and any other tab or result falls back to "All rows".

Files Reviewed (1 file in incremental diff)
  • src/pages/Editor.tsx

Notes: Incremental review of b379770 only. Tests were not run (read-only review).

Previous review (commit 872585e)

Status: 1 Issue Found | Recommendation: Merge after considering the suggestion

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
src/pages/Editor.tsx 502 exportScope is editor-wide state that never resets. Choosing "Current results" on one paged tab carries over to other paged tabs, so a later export can silently write only the loaded rows. Reset it to "all" on tab/result change or menu close.
Files Reviewed (21 files)
  • src-tauri/src/export.rs
  • src-tauri/src/export/format.rs
  • src-tauri/src/export/sink.rs
  • src-tauri/src/export/tests.rs
  • src/i18n/locales/*.json (11 files)
  • src/pages/Editor.tsx - 1 issue
  • src/types/editor.ts
  • src/utils/multiResult.ts
  • src/utils/resultExport.ts
  • tests/utils/multiResult.test.ts
  • tests/utils/resultExport.test.ts

Notes: NDJSON and HTML sink output was checked against the frontend formatters (resultToHtmlDocument, escapeHtml, htmlCell) and matches. Tests were not run (read-only review).

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5.5 · Input: 258 · Output: 3.4K · Cached: 572.6K

Review guidance: REVIEW.md from base branch main

@github-actions

Copy link
Copy Markdown
Contributor

Preview build

The preview build of commit b379770 failed (skipped). See the workflow run for logs.

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for taking on #1238! The two new writers in sink.rs follow the frontend output closely: same HTML head, same escaping, null for NULL, newlines turned into <br>. The byte-for-byte test pins the whole document, which is great. Marking the extra result sets of a MySQL CALL as fromResultSets, so they're never re-run, is a thoughtful detail too.

There's one behaviour I'd like changed before merge. resolveExportScope returns 'all' whenever the grid has no unloaded rows (and rows.length > 0), so the backend re-runs the query even when the grid already holds every row. On main, multi-result tabs with rows and every HTML/NDJSON export write what's on screen. With this PR, handleExportCommon re-runs activeResultEntry.query instead. Re-running gains nothing when the grid is complete, and it isn't harmless. In a multi-statement tab, exporting the result of an INSERT ... RETURNING * or DELETE ... RETURNING would execute that statement again. Anything using now() or random() also stops matching what the user sees. I'd use 'loaded' when !hasUnloadedRows(result), stream only when rows are actually missing and the user picked All rows, and update the "streams every format when the grid is complete" test. That departs a bit from the wording in #1238, which is fine by me.

Then the rebase, since #676 landed:

  • The frontend moves to packages/web-ui/src (tests to packages/web-ui/tests). Editor.tsx needs a manual pass: on main, handleExportCommon uses client.call, platform.chooseSaveTarget and downloadGeneratedFile instead of saveFileDialog/writeTextFile.
  • run_export in export.rs is now generic over W: Write, so the two new match arms need re-adding there. ExportFormat also has extension() and mime_type() now, and both need arms for ndjson and html (application/x-ndjson, text/html), or the match won't compile.
  • QueryExportRequest.format in packages/web-ui/src/api/contract.ts is 'csv' | 'json' | 'markdown' and needs 'ndjson' | 'html'.

The good news is that the design fits main well: both the desktop command and the web route go through application::generic_exports::export_query, so the new formats reach both transports without any new command.

Smaller notes:

  • The description says exportLoadedRowsWarning was removed, but the merge commit brought it back and handleExportLoadedRows still uses it. Keeping it is fine; just update the text.
  • HtmlSink::write_row builds cells from values, not headers, so a plugin returning a short row gets fewer <td> cells, while JSON/NDJSON pad with null.
  • In web mode, streamed exports go through a 512 MiB LimitedWriter, so a big HTML All rows export will fail partway with a size error. Worth checking that the message is clear after the rebase.

@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor Author

Updated per review:

  • Merged latest main (single conflict in Editor.tsx, resolved).
  • When the grid already holds all rows, export now uses the loaded path instead of re-running the query.
  • Added Ndjson/Html to extension()/mime_type() and to contract.ts.
  • HtmlSink pads short rows with null (+ test).

Verification: cargo test export — 90 passed, 0 failed; vitest/tsc/lint green.

🤖 Generated with Claude Code

https://claude.ai/code/session_014KVgo5fxAqEKcKUvPCmch3

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the quick turnaround, and for taking the rerun concern seriously. resolveExportScope now only streams when rows are actually missing, and the comment above it explains why. You also covered every rebase point: ndjson and html in extension() and mime_type(), the contract type, the new run_export arms, and null padding in HtmlSink with its own test. I ran the export tests on the branch (46 on the Rust side, 114 in resultExport and multiResult), pnpm build and cargo check --no-default-features, and everything is green.

I found one case that my own suggestion missed, and I'd like it fixed before merge. hasUnloadedRows only looks at pagination, but the drivers only paginate statements that start with SELECT (is_select_query in drivers/common/query.rs). Anything else that returns rows (a WITH ... SELECT, VALUES, PRAGMA, SHOW) is cut at the page size with truncated: true and no pagination, see the manual_limit path in src-tauri/src/drivers/sqlite/mod.rs and drivers/postgres/mod.rs. For those results resolveExportScope now returns 'loaded', so a CTE that returns 1200 rows exports only the first 500 to CSV, JSON or Markdown, with no selector and no loaded rows warning. On main the same CSV export streamed all 1200 rows, because single query tabs always went through export_query_to_file. That silent truncation is exactly what #1238 is about, so I don't want to ship it.

The fix should be small: treat result.truncated as missing rows in hasUnloadedRows, and in getLoadedRowsExportLimit so the warning shows when someone picks Current results, plus a test for it. One thing to keep in mind: a capped INSERT ... RETURNING is also truncated, and All rows would run it again. If you see a simple way to default to Current results for a truncated result without pagination, I'd take it. Otherwise just showing the selector and the warning is already much better than dropping rows silently.

A few small things you can fold into the same push:

  • cargo fmt wants to wrap the .map(...) in HtmlSink::write_row (src-tauri/src/export/sink.rs:282).
  • The doc comments on escape_html and html_cell still point to src/utils/clipboard.ts. It lives in packages/web-ui/src/utils/clipboard.ts now.
  • The PR description still says every format streams by default and that All rows always calls export_query_to_file. Could you update it to the current behaviour, and add a line saying plugin drivers get NDJSON and HTML through the same streaming path?
  • About the 512 MiB browser limit from my last review: the message still reads Export exceeds the 536870912 byte browser download limit. That code isn't part of this PR, so no need to touch it here, it can be a separate follow-up.

Once the truncated case is in, I'll go through the exports by hand before merging.

@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor Author

Addressed latest review comments:

  • Treated
    esult.truncated\ as partial/missing rows in \getLoadedRowsExportLimit\ and \hasUnloadedRows\ so non-SELECT results capped by driver limits without pagination (e.g. \WITH ... SELECT, \VALUES, \SHOW, \PRAGMA) properly surface the scope selector and warning when exporting loaded rows. Added unit test coverage for this case.
  • Formatted \src-tauri/src/export/sink.rs\ with
    ustfmt\ (\HtmlSink::write_row).
  • Updated doc comment references to point to \packages/web-ui/src/utils/clipboard.ts.
  • Updated PR description with the refined export behavior and plugin streaming path.

debba
debba previously approved these changes Oct 26, 2026

@debba debba left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for closing the truncated-result gap. getLoadedRowsExportLimit recognizes truncated without pagination, so capped CTE results get the scope selector and the Current results warning. The HTML padding, formatting and moved source references are fixed too. The 116 frontend export/multi-result tests, 46 Rust export tests, frontend checks, build and desktop-free cargo check pass.

I have now tested the PR head in the real macOS app against a 1,200-row SQLite fixture. A WITH ... SELECT loads 500 rows without pagination. Exporting CSV, JSON, NDJSON, Markdown and HTML with All rows produced 1,200 records in every file. Current results produced 500 records in all five formats and displayed the loaded-rows warning. I parsed the files and checked NULLs, quoted text, a newline and escaped HTML.

A complete result from SELECT lower(hex(randomblob(16))) AS nonce exported the exact value shown in the grid, so that path did not rerun the query. Save destinations were controlled by the e2e dialog mock; the actual app serialization and filesystem writes were exercised.

Approved. The two follow-ups remain: prefer Current results for truncated results without pagination, since All rows reruns the statement, and give the browser download-limit message a readable size.

The merge-order conflicts are now resolved by merging current main, keeping both groups of export tests and regenerating the API inventory. The integrated branch passes 511 targeted tests, typecheck, lint and build. The full frontend suite has 7,505 passes and 5 tooling failures; the same 5 fail on a clean checkout of current main. My approval stands.

CI exposed a race in the existing Rust authentication audit test: the operational RPC test can clear or disable the same global log buffer while the audit assertion runs. I isolated the audit test in a subprocess, following the existing logger deadlock test, and kept all authentication and secret-redaction assertions. The 21 web tests passed ten consecutive runs with 16 threads; the isolated audit and logger deadlock tests also pass with RUST_LOG=off in the parent. No application behavior changed.

@NewtTheWolf NewtTheWolf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I rechecked 8359f01 after the earlier desktop export verification. The 119 affected frontend tests, typecheck and all 2,202 Rust library tests pass locally. The added audit test correctly isolates its process-wide logging assertions in a child process.

There are still merge conflicts in packages/web-ui/src/types/editor.ts and web-ui-project/docs/web-ui-parity.json. Please update the branch against current main and retain the current parity audit when resolving the latter. The previously tested head cannot be merged as it stands, so I am keeping this open for the integrated revision.

@markankamaransheogarat-sys
markankamaransheogarat-sys force-pushed the feat/export-scope-streaming-1238 branch from 8359f01 to 188fe6f Compare November 10, 2026 17:08
@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor Author

@NewtTheWolf Rebased onto current main and resolved the conflicts: kept both the split-result-sets flag and the batch snapshot on QueryResultEntry in packages/web-ui/src/types/editor.ts, removed the stale web-ui-project/docs/web-ui-parity.json in favor of the current docs/web/WEB_MANUAL_PARITY_AUDIT.md, and verified that web:manual-parity plus all 119 export/multi-result tests and typecheck pass.

@NewtTheWolf NewtTheWolf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for integrating the export changes with main. I checked 188fe6f4 against the previously reviewed revision: both the split-result flag and the batch snapshot are retained, and the current manual-parity audit replaces the removed inventory file. The truncated-result scope handling and the loaded-result path are preserved.

The 119 export/multi-result frontend tests, typecheck, lint, production build, manual-parity check and desktop-free cargo check pass. The Rust library suite passes with one test thread: 2,540 passed and 19 ignored. The earlier parallel run encountered the export-test registry contamination also reproduced on main and subsequently fixed in #1518.

I did not repeat Debba's recorded 1,200-row desktop export exercise in this pass. This follow-up checks the integration correction; I found no additional blocker on this head. Approved.

@NewtTheWolf
NewtTheWolf merged commit 60ab0f1 into TabularisDB:main Nov 12, 2026
14 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: stream every format through the backend, with an option to export only current results

3 participants