Repository navigation
feat(export): stream every format through the backend, with an All rows / Current results choice (#1238) - #1240
Conversation
|
|
||
| const [showNewRowModal, setShowNewRowModal] = useState(false); | ||
| const [exportMenuOpen, setExportMenuOpen] = useState(false); | ||
| const [exportScope, setExportScope] = useState<ExportScope>("all"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Incremental review of 188fe6f. The branch was rebuilt as a single commit on top of current
The earlier export-scope finding stays resolved. Files Reviewed (23 files)
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):
Earlier findings stay resolved. The only inline comment (export scope persisting across tabs) was addressed in b379770. Files Reviewed (1 file in incremental diff)
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):
Earlier findings stay resolved, and no new issues were found. Files Reviewed (3 files in incremental diff)
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 Files Reviewed (1 file in incremental diff)
Notes: Read-only review; tests were not run. Previous review (commit 4f30b5d)Status: No Issues Found | Recommendation: Merge Incremental review of 4f30b5d. The earlier
Files Reviewed (6 files in incremental diff)
Notes: The branch was rebased onto a newer Previous review (commit b379770)Status: No Issues Found | Recommendation: Merge The earlier suggestion about Files Reviewed (1 file in incremental diff)
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
Issue Details (click to expand)SUGGESTION
Files Reviewed (21 files)
Notes: NDJSON and HTML sink output was checked against the frontend formatters ( Reviewed by claude-sonnet-5.5 · Input: 258 · Output: 3.4K · Cached: 572.6K Review guidance: REVIEW.md from base branch |
Preview buildThe preview build of commit |
debba
left a comment
There was a problem hiding this comment.
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 topackages/web-ui/tests).Editor.tsxneeds a manual pass: on main,handleExportCommonusesclient.call,platform.chooseSaveTargetanddownloadGeneratedFileinstead ofsaveFileDialog/writeTextFile. run_exportinexport.rsis now generic overW: Write, so the two new match arms need re-adding there.ExportFormatalso hasextension()andmime_type()now, and both need arms for ndjson and html (application/x-ndjson,text/html), or the match won't compile.QueryExportRequest.formatinpackages/web-ui/src/api/contract.tsis'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
exportLoadedRowsWarningwas removed, but the merge commit brought it back andhandleExportLoadedRowsstill uses it. Keeping it is fine; just update the text. HtmlSink::write_rowbuilds cells fromvalues, notheaders, so a plugin returning a short row gets fewer<td>cells, while JSON/NDJSON pad withnull.- 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.
|
Updated per review:
Verification: 🤖 Generated with Claude Code |
debba
left a comment
There was a problem hiding this comment.
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 fmtwants to wrap the.map(...)inHtmlSink::write_row(src-tauri/src/export/sink.rs:282).- The doc comments on
escape_htmlandhtml_cellstill point tosrc/utils/clipboard.ts. It lives inpackages/web-ui/src/utils/clipboard.tsnow. - 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.
|
Addressed latest review comments:
|
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
…ws / Current results choice (TabularisDB#1238)
8359f01 to
188fe6f
Compare
|
@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
left a comment
There was a problem hiding this comment.
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.
Summary
Closes #1238
Every entry of the Export menu (CSV, JSON, NDJSON, Markdown, HTML) streams through
export_query_to_filewhen 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:ExportFormatgainsNdjsonandHtml;parseacceptsndjson/html(case-insensitive);extension()andmime_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 onfinish. Escaping matchesescapeHtml(& < > " '),\r\n/\n-><br>, NULL ->null. Pads short rows with null cells. Formatted cleanly with rustfmt.packages/web-ui/src/utils/clipboard.ts.{ column: value }row builder is shared byJsonSinkandNdjsonSink(row_to_object).export.rs: both new formats wired intorun_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 whengetLoadedRowsExportLimitis non-null. Treatsresult.truncatedwithout 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:packages/web-ui/src/api/contract.ts:ndjsonandhtmltoQueryExportRequest.format.packages/web-ui/src/i18n/locales/*.json(all 11): menu labels and scope picker strings.Verification
packages/web-ui/tests/utils/resultExport.test.tspasses with full coverage of paginated and truncated scenarios (32 tests).pnpm build(tsc -b && vite build) green.rustfmtclean onsrc-tauri/src/export/sink.rs, types and arms compile cleanly.