Craticula

Export

An export is a request of its own kind. It drops the grouping state and names its output columns, which an ordinary row query does not. The export scope chooses the page mode and nothing else in the compiler changes; streaming and the CSV file itself are described elsewhere.

the grouping addendum above, of which this is the sibling: the TRD's §6.1 states the export requirements and this is where the compile-time half of them is decided)

The TRD's EXP-1..EXP-8 span a wire contract, a compilation rule, a streaming obligation and a CSV writer. Only EXP-1 and EXP-2 have a compiled form at all — EXP-3 is streaming, and EXP-4..EXP-8 are the CSV writer's; none of them is restated here. So this addendum owns no new number: it refines the two that exist, splitting EXP-1's single paragraph into the two independent rules it actually contains — the request extension with its group carve-out, EXP-1(a), and the column list, EXP-1(b). Numbering the column list "EXP-3" is a mistake this repo has already made twice, in GRP-3 and in its restatement in SqlQueryBuilder; both are corrected.

What follows is what a compiler and its request adapter must do, pinned because #1650 found the two questions below answered inconsistently in the suite that was meant to pin them: whether an ordinary row query projects, and whether an export does.

EXP-1(a). The export is a request-shaped extension, and its group state is discarded. The wire request carries exportFormat: "csv" | "tsv", exportScope: "all" | "page" (default "all") and an optional ordered exportColumns: [{ colId, header? }] beside the ordinary AG Grid SSRM members — filterModel and sortModel are always honoured, unchanged, which is why nothing else about the compiled query differs. Three consequences, all of them the adapter's to apply before a compiler sees the IR:

EXP-1(b). An export names its output columns; an ordinary row query still does not. This is the widening GRP-3 deferred to "the export feature", and it is deliberately narrow — it did not become a general projection rule:

Per backend. On SQL the projection is the SELECT list, each column aliased back to its logical name only where the physical column differs ("order_date" AS "orderDate", but plain "status") — GRP-3's drill-down-leaf rule, reused unchanged. On MongoDB it is a trailing $project, after any $skip/$limit, re-keying a differing physical path with the expression form ("id": "$_id") and a matching one with a plain 1, then _id: 0 last (MDB-10's shape rules apply to it like any other stage document; the suppression is written after the output list because that list's order is what is normative and byte-compared). On OpenSearch/Elasticsearch there is no projection at all — see OSE-13, which is a statement about the artifact's admitted member set, and the note there on _source filtering. Column selection and ordering for that backend fall to the writer, reading exportColumns from the request it already holds. That is not EXP-1(b) contradicting OSE-13; it is one rule with a per-backend split, and the fourteen Search arms in page-export/ pin it.

EXP-2. exportScope resolves to a page mode, and nothing else in the compiler changes. "all" is $defs/nonePage — the whole filtered and sorted result, with the request's own startRow/endRow discarded, not merely absent. "page" honours that range exactly as an ordinary row fetch does. page-export/006 and /007 are the pair that pins this: identical requests down to startRow: 200, endRow: 250, differing only in the scope, and 006 compiles with no LIMIT/OFFSET, no $skip/$limit and no from/size on any backend. The startRow/endRow pair is still shape-checked before the scope overrides it — a half-supplied range is malformed whether or not this scope would have used it.

SEM-6's tiebreaker is unaffected: page: none is still a paged read as far as determinism is concerned (a stream can be resumed, and an unordered one cannot be), so the stable key is appended exactly as it always is. sort-paging/012 and every exportScope: "all" fixture in page-export/ carry it.

Cross-links. $defs/nonePage, $defs/rangePage, $defs/groupSpec, GRP-1 (the dispatch the carve-out bypasses), GRP-3 (the projection rule this one composes with), SEM-6 (the tiebreaker page: none keeps), OSE-13 and MDB-10. spec/fixtures/page-export/ is the artifact oracle, plus sort-paging/012 for the page: none shape on all three backends. EXP-3..EXP-8 — streaming and chunking, the CSV writer, its formatting and injection hardening, and the row-count limit — have no compiled form and are not restated here; the TRD §6.1 prose is their normative home. #1651 built the writer half of EXP-4/EXP-5, #1652 EXP-6's injection hardening and #1653 EXP-5's per-field format overrides, and their oracle is the byte-exact expected/export.csv/.tsv files in page-export/012-020, /022, /025 and /026 — twelve of that category's twenty-six cases, which is every writer-facing one except 021 (EXP-7's row limit produces no output to compare). See the category README for the file shapes. #1652 also narrowed EXP-6's scope, and that narrowing is stated at EXP-6 itself in the TRD — deliberately not here, and not in summary either: it turns on a distinction fine enough (which spelling of the type test, not just which types) that a second copy would be wrong within a story or two. page-export/018 is its oracle. EXP-3 and EXP-7 are the execution adapters'.