Skip to content

Iceberg: a pushed decimal FILTER literal panics the reader or silently drops matching rows #2185

Closed

Description

@aaj3f

Found this while querying BigQuery-managed Iceberg tables (BigQuery exports NUMERIC as decimal(38,9)), and it turned out to be more than the panic I first saw.

The Arrow row filter in fluree-db-iceberg/src/io/arrow_reader.rs evaluates a pushed FILTER comparison on each decoded batch before the engine sees it, and the in-engine FILTER only runs on the rows it keeps (fluree-db-query/src/r2rml/rewrite.rs:655-683, operator.rs:529-541). So it can keep extra rows harmlessly, but a row it drops is gone. eval_comparison casts the literal into the column's type with Arrow's default (safe) cast, and that cast is lossy in three ways. Claude traced the mechanism and reproduced each of these end to end against 9420db4ca:

  1. A panic, for a decimal literal below one. scan_value_from_bigdecimal (rewrite.rs:1025) derives precision from the unscaled digit count only, so 0.05 decomposes to unscaled 5, precision 1, scale 2. literal_to_array (arrow_reader.rs:604) then calls .with_precision_and_scale(1, 2).expect(..), and FILTER(?d >= 0.05) panics the reader with scale 2 is greater than precision 1. The comment there says precision "is cosmetic for pruning", which is true for decimal_cmp but not for Arrow's builder.
  2. Silent row loss from rounding. When the literal has enough digits to get a valid precision, the cast to the column's scale rounds (half away from zero). ?d < 1.0500000001 on decimal(38,9) loses the row 1.050000000, and ?d > 1.0499999999 loses it too. No panic, just wrong results.
  3. Silent row loss from overflow. A literal outside the column's range casts to NULL rather than erroring, so the keep-all fallback (arrow_reader.rs:565) never fires and the NULL mask drops every row: ?d < 1000 on a decimal(5,2) column returns nothing. This one reaches JSON-LD too, since an integer FILTER literal against a decimal column is pushed as a scale-0 decimal (fluree-db-api/src/graph_source/r2rml.rs:353).

My first instinct was to fix the precision (max(digits, scale)), but that would've turned (1) into (2), fwiw, so I don't think patching the precision is the right fix. What seems right to me:

  • convert the literal into the column's comparison type once per file and only use it if the conversion is non-null and casts back unchanged; otherwise that comparison keeps every row and the in-engine FILTER decides. That check is type-generic, so it also covers integer narrowing and timestamp truncation, which have the same shape;
  • drop precision from ScanValue::Decimal / LiteralValue::Decimal (and the manifest TypedValue::Decimal). A literal doesn't have one, its only reader was the Arrow builder, and the column's own decimal(p, s) is what any comparison should use.

Tests should cover SPARQL and JSON-LD, though JSON-LD has no decimal FILTER literal (a fractional number parses as a double, which isn't pushed against a decimal column), so its twin is the integer-overflow case.

Activity

  1. added
    bug
    P1
    area:iceberg
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1area:icebergbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions