Skip to content

fix(spec): compare truncate width in code points when projecting strings - #3634

Open
compiler-segfault wants to merge 2 commits into
apache:mainfrom
compiler-segfault:fix/truncate-projection-code-points
Open

compiler-segfault wants to merge 2 commits into
apache:mainfrom
compiler-segfault:fix/truncate-projection-code-points

Conversation

@compiler-segfault

Copy link
Copy Markdown

Which issue does this PR close?

What changes are included in this PR?

truncate[N] truncates strings by Unicode code points, but the projection compared the literal length in UTF-8 bytes. A prefix of two code points and three bytes (Év) therefore looked as wide as truncate[3], STARTS WITH was rewritten to =, and scans silently returned no rows. NOT STARTS WITH was affected the same way.

The four comparisons in Transform::strict_project and Transform::adjust_operator now count code points for string literals; binary literals keep byte counting. The other evaluators (inclusive_metrics_evaluator, row_group_metrics_evaluator, page_index_evaluator) already use chars().count().

Are these changes tested?

Two unit tests in transform/truncate.rs cover the inclusive and the strict projection for prefixes of two, three and four code points over truncate[3]. Both fail before the change (city = "Év" instead of city STARTS WITH "Év") and pass with it. cargo test -p iceberg --lib passes: 2135 tests.

AI Disclosure

Diagnosis and patch were written with an AI assistant. I read the projection code paths and ran the full iceberg lib suite locally. Points worth a reviewer's attention: strict_project returns None for STARTS WITH when the prefix is wider than the truncate width (left unchanged, as it was), and binary literals are still compared in bytes, which matches truncate_binary.

The truncate transform truncates strings by Unicode code points, but the
projection compared the literal length in UTF-8 bytes. A prefix of two code
points and three bytes looked as wide as truncate[3], so STARTS WITH was
rewritten to an equality predicate and scans dropped matching rows.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unicode prefix predicates can silently drop rows from string truncate partitions

2 participants