API: Truncate projection of startsWith/notStartsWith miscounts surrogate pairs

オープン
#18,922 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@jin-won-park がすでに取り組んでいます。

2026年11月13日 から。

  • #18923 @jin-won-park による — オープン

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
data

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Java
スター
9.4k
フォーク
3.7k
平均マージ
2日 15時間
マージ済み PR(30日)
169

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/iceberg のほかの issue

apache/iceberg の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。