API: Truncate projection of startsWith/notStartsWith miscounts surrogate pairs

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

I maintainer di solito rispondono entro 1 giorno

@jin-won-park ci sta già lavorando.

Dal 13/11/2026.

  • #18923 di @jin-won-park — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
data

Direzione di ricerca

Start with the string truncate transform: the TruncateString project and projectStrict methods, which compare the prefix's String.length() with the width, and UnicodeUtil.truncateString, which counts code points. Run the reproduction from the issue (startsWith and notStartsWith on "😀" with truncate width 2) to see the wrong projections. Done means both methods compare code point counts, and tests cover surrogate-pair prefixes while ASCII and BMP cases still pass.

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

Descrizione

bug
Apache Iceberg version

main (development)

Query engine

None

Please describe the bug 🐞
Problem

truncate[W] on strings truncates to W code points (UnicodeUtil.truncateString), but TruncateString.project and projectStrict decide how to project startsWith/notStartsWith by comparing the prefix's String.length() (UTF-16 chars) with W.

A prefix with supplementary characters such as emoji can have length() == W and still have fewer than W code points. The projection then treats it as a full partition value and turns it into an equality, while the partition values of matching rows are longer.

Reproduce
Schema schema = new Schema(Types.NestedField.optional(1, "s", Types.StringType.get()));
PartitionSpec spec = PartitionSpec.builderFor(schema).truncate("s", 2).build();

// "😀" is 1 code point but 2 chars. A row "😀abc" lands in partition s_trunc = "😀a".
Projections.inclusive(spec).project(Expressions.startsWith("s", "😀"));
// actual:   ref(name="s_trunc") == "😀"         -> partition "😀a" is pruned
// expected: ref(name="s_trunc") startsWith "😀"

Projections.strict(spec).project(Expressions.notStartsWith("s", "😀"));
// actual:   ref(name="s_trunc") != "😀"         -> partition "😀a" is treated as all-matching
// expected: ref(name="s_trunc") notStartsWith "😀"
Impact
  • Inclusive projection prunes partitions that contain matching rows, so scans with such a startsWith filter silently return fewer rows.
  • Strict projection reports partitions as fully matching when none of their rows match, which affects residuals and partition-level decisions such as metadata-only deletes.

It only happens for string truncate partitions when the prefix's UTF-16 length equals the width but its code point count is smaller. ASCII and BMP-only prefixes are unaffected.

Proposed fix

Compare the prefix's code point count with the width in both methods. I have a fix with tests and can open a PR.

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 16h
PR unite (30g)
160

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.