Skip to content

fix(core): a NULL literal in a set operation declares its column's type for every leg - #473

Merged
fupelaqu merged 1 commit into
mainfrom
feature/SCHEMA-18
Nov 23, 2026
Merged

fupelaqu merged 1 commit into
mainfrom
feature/SCHEMA-18

Conversation

@fupelaqu

Copy link
Copy Markdown
Contributor

Summary

In a set operation, a branch that projects a NULL literal (SELECT NULL AS k … UNION SELECT n AS k …) declared no type at that position. SetOperationValues.legSchemas gave the leg no slot there, because the leg reader of a NULL literal reads nothing.

Core's own run already answers the column's type: the set-operation rule says a NULL literal takes the other branches' type (documentation/sql/dql_statements.md). The Arrow engine (Flight SQL, ADBC, the JDBC JOIN path) typed that leg from its own description instead, so the column came back as text: 3 arrived as "3". When the NULL branch had rows, the NULL itself was written as the text [null]. DuckDB answers the sibling's type.

Change

  • legSlot gives a NULL-literal position a slot typed as the column's set-operation result, MultiSearch.columnTypes(...).result: the same function core's set-operation typing already uses. Its reader answers null for every row and is shared.
  • There is no slot where the column type is NULL, holds ANY or a field-less STRUCT at any depth, or is NUMERIC / TEMPORAL. REAL and VARBINARY get one.
  • Beside a date read as stored text, the slot keeps the declared type. DuckDB's answer stays VARCHAR, as before.
  • Core's run path, legReaders, the converters and ResultSchema are unchanged. No signature or case-class change.

Visible changes

Measured on the Arrow engine's own code (leg typing, then DuckDB) over 240 cells: an empty and a non-empty NULL branch, UNION ALL / UNION / INTERSECT / EXCEPT, NULL first and second, every column family. Each cell is compared with main:

  • Type: 58 cells. A NULL-literal position beside a typed sibling now has the sibling's type (it was Utf8).
  • Value: 36 cells. A NULL-literal branch with rows now streams NULL instead of the text [null] (bytes 0x5b6e756c6c5d in a binary column).
  • Refused → answered: 26 cells, for example a NULL beside a STRUCT that holds a date field. Main failed with a DuckDB conversion error.
  • Answered → refused: none.
  • 120 cells are unchanged.

Cost

Warm medians, main and branch interleaved.

  • Planning (legSchemas, once per statement), ceiling ≤ main + 1.0 µs and ≤ ×1.05 (≤ ×1.03 for a statement without a NULL position). Measured in one JVM with main's and the branch's compiled core in two class loaders, alternating the first side per sample, 21 samples × 3 rounds. The verdict uses the within-round paired statistic:
    • one NULL position: −0.89 µs (×0.962) same statement, −0.71 µs (×0.971) fresh statement;
    • two NULL positions: +0.73 µs (×1.012) same, −0.17 µs (×0.998) fresh;
    • no NULL position: ×0.999 same, ×0.988 fresh.
    • Reported, not ruled: per-side medians for two NULL positions are +1.26 / +1.87 µs and pooled medians +1.13 / +1.83 µs; one NULL position, same statement, pooled ×1.081 (+1.82 µs); round 1 of that cell ×1.325 (main's JIT settled mid-round); no NULL position, round 1, ×1.035 / ×1.056. The call costs 60–95 µs, and machine noise within one round spans more than 1 µs.
  • Leg typing on the Arrow engine: ×0.974–1.027 per leg (≤ ×1.03); routing a NULL-only leg costs 0.08–0.39 µs (≤ 5 µs).
  • Per row: the shared NULL reader costs 2.0 ns per call with no allocation (≤ 3 ns). A 10k-row batch runs at ×0.53–1.01 (≤ ×1.03).
  • DuckDB execute and schema probe: ×0.94–1.01 (≤ ×1.05).
  • No new Elasticsearch version lookup; describe and prepare add no request.

Testing

  • core/test 1749 / 0: new SetOperationNullSlotSpec, the SetOperationLegSchemasSpec pin moved to the oracle, and a consumer smoke update. + compile passes on 2.12 and 2.13.
  • Docker-free client units: es6jest 58 / 0, es6rest 37 / 0, es7rest 33 / 0.
  • ES 8.18.3: the set-operation area (12 specs, including the new JavaClientNullSlotSpec), 151 / 0.
  • Arrow consumer check without any publish: the Arrow engine's own leg typing and DuckDB execution, run against the published core snapshot with the new slot reproduced exactly, on the 240 cells above.

Elasticsearch versions

ES 8.18.3 locally; ES 6.8, 7.17 and 9.0 run in CI.

After merge

Once a core snapshot carrying this change is published, downstream unit tests that pin the old untyped NULL must move to DuckDB's values. Downstream main code needs no change.

Release note

  • In Arrow Flight SQL and ADBC results, a NULL literal in a set operation now takes the type of the other branches (it was text), and a NULL branch no longer renders as the text [null].
  • No downstream rebuild: no signature or case-class change.

Recorded, not fixed

None.

🤖 Generated with Claude Code

…pe for every leg (SCHEMA-18)

Story SCHEMA-18. Reviewed: r0:clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fupelaqu
fupelaqu marked this pull request as ready for review November 23, 2026 22:28
@fupelaqu
fupelaqu merged commit b3b106d into main Nov 23, 2026
4 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.

1 participant