bucket(decimal) partition pruning silently drops rows when the query literal's scale differs from the column scale

Aperta
#18,988 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@ViktorBystrov72 ci sta già lavorando.

Dal 16/11/2026.

  • #18991 di @ViktorBystrov72 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
java
Ambito
databases

Direzione di ricerca

Read Literals.DecimalLiteral.to, StringLiteral.to, Binder, BucketUtil.hash, Bucket.project, ProjectionUtil.transformSet, and BoundSetPredicate.test; inspect the decimal bucket and IN predicate tests. Reproduce the scale mismatch for decimal(9,2), then verify numeric equality is handled consistently in bucket pruning and residual evaluation without changing hashes for stored values. Issue #18991 already has an open linked pull request.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Apache Iceberg version

None

Query engine

None

Please describe the bug 🐞

Description

With a decimal(9,2) column partitioned by bucket(value, 16), the query WHERE value = 100.0 silently misses rows holding 100.00, because the literal keeps its written scale when bound but the bucket hash is scale-sensitive.

Literals.DecimalLiteral.to(DECIMAL) and StringLiteral.to(DECIMAL) both say "do not change decimal scale" and return the literal unchanged, while IntegerLiteral/LongLiteral/FloatLiteral/DoubleLiteral.to(DECIMAL) all setScale(column scale, HALF_UP). Binder converts literals via Literal.to(type), so a decimal literal keeps its written scale. But BucketUtil.hash(BigDecimal) hashes the raw unscaled-value bytes, so numerically equal decimals at different scales hash differently.

The spec (format/spec.md) says hash results are "not dependent on decimal scale, which is part of the type, not the data value". That holds for stored data, where the column scale is fixed, but not for un-normalized query literals.

To Reproduce

Schema decimal(9,2), partition spec bucket(value, 16):

  • value = 100.00 projects to value_bucket == 8
  • value = 100.0 projects to value_bucket == 0

A manifest whose stored partition value is 8 is then pruned by ManifestEvaluator.eq (lower == upper == 8 vs projected 0 returns ROWS_CANNOT_MATCH), so the rows are silently missing from WHERE value = 100.0. The same flaw reaches IN lists via Bucket.project -> ProjectionUtil.transformSet.

Same family at row level: binding IN(1.1, 2.2) on decimal(9,2), then BoundSetPredicate.test(1.100) returns false, because Evaluator.in / BoundSetPredicate.test use Set.contains on raw BigDecimals and BigDecimal.equals/hashCode are scale-sensitive (equals false, compareTo == 0, contains false). Residual evaluation drops matching rows.

Verified on current main (bc94d8e, 2026-11-16): calibration BucketUtil.hash(14.20) = -500754589 matches the spec example.

Expected behavior

Numerically equal decimal literals project to the same bucket regardless of written scale, and IN evaluation matches numerically equal decimals.

Possible fix

Normalize the decimal literal to the column scale at bind time (DecimalLiteral.to / StringLiteral.to), taking care that values with more fractional digits than the column scale must not be silently rounded for EQ; or scale-normalize inside the bucket projection. Changing BucketUtil.hash itself would break spec compatibility with existing data.

Notes

  • Closest prior report is #7882 (closed, Hive-side trimming, identity partition); it did not fix this code path, Set.contains is still in current main.
  • I can contribute a fix for this bug independently.
Willingness to contribute
  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time
Lingua principale
Java
Stelle
9.4k
Fork
3.7k
Merge medio
2g 15h
PR unite (30g)
169

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/iceberg

Tutte le issue di apache/iceberg

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.