Skip to content

fix(core): a value Elasticsearch ignored as malformed reads as NULL for every kind, and no number narrows silently - #472

Merged
fupelaqu merged 1 commit into
mainfrom
fix/ignored-values-null
Nov 21, 2026
Merged

fupelaqu merged 1 commit into
mainfrom
fix/ignored-values-null

Conversation

@fupelaqu

Copy link
Copy Markdown
Contributor

Summary

Two fixes to how a stored value reaches a typed column, both in the JDBC driver's getters and Arrow cells:

  1. A value Elasticsearch ignored as malformed reads as NULL, for every kind. Under ignore_malformed, Elasticsearch indexes the document, skips the bad value and names the field in the hit's _ignored. Dates already followed that verdict. Other kinds came back as stored instead. A "x" in a long arrived as text in a BIGINT column, and the getter failed with For input string: "x". A 3000000000 in an integer arrived as a Long in an INT column, and getInt returned -1294967296 without any error.
  2. No number is narrowed silently any more. Converting to TINYINT, SMALLINT, INT, BIGINT or REAL now fails with Value <v> is out of range for <TYPE>, as DuckDB's conversion error does, instead of wrapping. This also closes three silent paths with no _ignored involved:
    • a column declared INT over a long field;
    • an INT sum past the int range;
    • an object sub-field holding an out-of-range number.

Change

  • HitReading builds, once per statement, a map from each top-level path to its Elasticsearch kind, from the column's mapping type. That gives a single lookup for every hit-reading path.
  • NULL rule (verdict per value, as for dates):
    • a value the hit's _ignored names is NULL;
    • in an array or an ARRAY<X> column, only the elements Elasticsearch refused are NULL; an element its own parser accepts keeps its value.
  • Which value is "refused", per kind:
    • byte / short / integer / long: a value outside the type's range;
    • unsigned_long: a negative value or one with a decimal part (a whole value of any size is indexed);
    • float / half_float (after its rounding) / double / scaled_float: a non-finite value;
    • boolean: anything but Elasticsearch's own literals;
    • ip: anything but a literal IPv4 or IPv6 address, checked without any DNS lookup;
    • geo_point: anything that is not a point.
  • keyword, wildcard, constant_keyword and text never become NULL. _ignored also names a keyword over ignore_above, and that value is valid: it keeps its text.
  • Scope: top-level fields. A malformed value inside an object sub-field keeps today's reading. It is read as stored text, so a getter fails loudly, and an out-of-range number fails through the new range guard.
  • Range guard in ValueCoercion.coerceToByte / Short / Int / Long / Float:
    • a value of the target's own class is returned as is;
    • an in-range value gives exactly what it gave before;
    • fractional truncation is unchanged, and the truncated value is the one judged;
    • REAL fails on a finite value above Float.MaxValue and keeps NaN / ±Infinity.
  • documentation/client/gateway.md and documentation/client/jdbc.md describe both rules.

Cost

10,000-row numeric-only extraction on Elasticsearch 8.18.3, runs interleaved main / branch / main / branch:

main branch
Reading cost 612-678 ns/row 613-637 ns/row
Allocation 1,930.2 B/row 1,930.2 B/row

The _ignored check is one constant-time lookup per hit, and it allocates nothing when the hit has no _ignored.

Testing

  • Unit tests:

    • sql/test 2376/0 and core/test 1728/0;
    • new ValueCoercionRangeSpec, which covers every bound;
    • new HitReadingIgnoredValuesSpec, 10/10, failing on the base commit.
  • + compile passes on Scala 2.12 and 2.13. es6rest, es7rest and es9java test sources compile.

  • Elasticsearch 8.18.3:

    • new JavaClientIgnoredValueReadingSpec, 8/8, over every kind across SELECT *, a named column, a WHERE filter, scroll, arrays, ARRAY<X> columns, a keyword over ignore_above and the three range-guard paths;
    • 15 schema-area client specs, 335/0.

    These ES runs used the commit before the last review round. That round changed the unsigned_long acceptance (unit-tested) and one test literal.

  • Probe before the change, on Elasticsearch 8.18.3 and 6.8.23: it measured what each kind returns and what _ignored names.

  • CI lint line passes.

  • Not run locally: Elasticsearch 7.17 and 9 (runners added, CI).

Elasticsearch versions

  • Verified on Elasticsearch 7.17 and later.
  • scaled_float: covered from 8.6, the first version that names a refused one in _ignored. Before 8.6 its value is answered as stored, and the test gates that row by version.
  • Elasticsearch 6.8: not in scope.
    • It refuses at index time an out-of-range short / integer / long, even under ignore_malformed, so the silent case does not exist there.
    • It does not name a refused scaled_float in _ignored.

Release note

  • A value Elasticsearch ignored as malformed in a top-level field (numbers, ip, geo_point, boolean where accepted) now reads as NULL, as dates already did. In arrays only the ignored elements are NULL, and a keyword over ignore_above keeps its text. Verified on Elasticsearch 7.17 and later; a scaled_float from 8.6.
  • JDBC getters and Arrow cells of a narrower type now fail with Value <v> is out of range for <TYPE> instead of returning a wrapped number.
  • No case-class arity change.

Recorded, not fixed

  • A malformed value in an object sub-field (obj.n holding "x") is still read as stored text, so it fails loudly in the getter. obj.i holding 3000000000 now fails through the range guard.
  • A pattern that merges integer and long into BIGINT judges array elements by long.
  • Fractional truncation in the integral conversions is unchanged (2147483647.9 gives INT 2147483647).

🤖 Generated with Claude Code

…or every kind, and no number narrows silently (SCHEMA-17)

Story SCHEMA-17-R172. Reviewed: r0:must-fix, r1:must-fix, r2:clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fupelaqu
fupelaqu marked this pull request as ready for review November 21, 2026 11:32
@fupelaqu
fupelaqu merged commit 40ee29b into main Nov 21, 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