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

Abierto
#18,988 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@ViktorBystrov72 ya está trabajando en esto.

Desde el 16/11/2026.

  • #18991 de @ViktorBystrov72 — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
java
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Java
Estrellas
9.4k
Forks
3.7k
Merge medio
2 d 15 h
PR fusionados (30 d)
169

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/iceberg

Todos los issues de apache/iceberg

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.