Skip to content

ORC-2237: Compare string statistics in UTF-8 order - #2746

Open
Dcastroro wants to merge 2 commits into
apache:mainfrom
Dcastroro:orc-2237-utf8-statistics
Open

Dcastroro wants to merge 2 commits into
apache:mainfrom
Dcastroro:orc-2237-utf8-statistics

Conversation

@Dcastroro

Copy link
Copy Markdown

What changes were proposed in this pull request?

Compare Java reader string statistics bounds and search literals in UTF-8 byte order during min/max predicate evaluation. Add regression coverage for a supplementary character above a BMP bound and for equality within a mixed range.

Why are the changes needed?

ORC writes string statistics in UTF-8 byte order. Java's UTF-16 ordering can place supplementary characters before BMP values that sort below them in UTF-8. When those orders differ, predicate pushdown can discard a row group containing a match. ORC-2237

How was this patch tested?

  • The new regression on the unpatched main base failed with expected NO, got YES. It passed with this change.
  • ./mvnw -B -ntp -pl core -am -Dtest=TestRecordReaderImpl,TestColumnStatistics -Dsurefire.failIfNoSpecifiedTests=false test from java/ passed 100 tests.
  • ./mvnw -B -ntp test from java/ passed 1,667 tests with 21 skipped and zero failures or errors.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: OpenAI Codex 0.171.0-alpha.13.2

Generated-by: OpenAI Codex 0.171.0-alpha.13.2
Copilot AI balanced review requested due to automatic review settings December 3, 2026 00:23

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.

🟡 Changes recommended

The change still has unresolved review findings, notably a potential hot-path performance regression from allocating/encoding a new Text on each string comparison in RecordReaderImpl.compare(), plus a test that doesn’t accurately exercise the production string evaluation path.

2 open issues
What changed in this PR

Aligns Java reader string min/max predicate evaluation with ORC’s UTF-8 byte ordering to avoid incorrect predicate pushdown when UTF-16 ordering differs (e.g., supplementary characters).

Changes:

  • Compare string statistics bounds and search literals using UTF-8 byte order during min/max predicate evaluation.
  • Add regression tests covering supplementary-character vs BMP ordering and equality within a mixed range.
File Description
java/​core/​src/​test/​org/​apache/​orc/​impl/​TestRecordReaderImpl.java Adds regression coverage to validate correct predicate outcomes for UTF-8 ordering, including supplementary-character boundary cases and equality in a mixed range.
java/​core/​src/​java/​org/​apache/​orc/​impl/​RecordReaderImpl.java Updates string range comparisons in min/max predicate evaluation to use UTF-8 byte-order comparison (via Text) instead of Java UTF-16 String ordering.

Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

Comment on lines +534 to +536
// String statistics are written in UTF-8 byte order, not UTF-16 code unit order.
Text utf8 = point instanceof String value ? new Text(value) : null;
int minCompare = utf8 == null ? point.compareTo(lower) : utf8.compareTo(lowerUtf8);
Comment on lines +801 to +809
PredicateLeaf atMostBmp = createPredicateLeaf(PredicateLeaf.Operator.LESS_THAN_EQUALS,
PredicateLeaf.Type.STRING, "x", bmp, null);
assertEquals(TruthValue.NO,
evaluateInteger(createStringStats(supplementary, supplementary, false), atMostBmp));

PredicateLeaf equalToSupplementary = createPredicateLeaf(PredicateLeaf.Operator.EQUALS,
PredicateLeaf.Type.STRING, "x", supplementary, null);
assertEquals(TruthValue.YES_NO,
evaluateInteger(createStringStats(bmp, supplementary, false), equalToSupplementary));
Generated-by: OpenAI Codex 0.171.0-alpha.13.2

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.

2 participants