Skip to content

Fix ClassCastException in range filters on version 1 range indexes under null handling - #20331

Merged
Jackie-Jiang merged 3 commits into
apache:masterfrom
Indian-boult:fix/range-index-v1-null-handling
Nov 24, 2026
Merged

Jackie-Jiang merged 3 commits into
apache:masterfrom
Indian-boult:fix/range-index-v1-null-handling

Conversation

@Indian-boult

Copy link
Copy Markdown
Contributor

Fixes #20330

The partial range scan in RangeIndexBasedFilterOperator.evaluateLegacyRangeFilter now uses getNextBlockWithoutNullHandling() instead of getTrues(). With null handling enabled and a column that holds nulls, getTrues() returns an AndDocIdSet whose iterator is not a ScanBasedDocIdIterator, and the cast right after it threw. The operator still leaves the null rows out of the final result through BaseColumnFilterOperator.getTrues(), so the scan does not need to do it again.

This affects every multi-value column with a range index, since those always use the version 1 index, and single-value columns configured with rangeIndexVersion 1.

I added NullHandlingEnabledQueriesTest.testRangeFilterOnMultiValueColumnWithLegacyRangeIndex, which runs >, NOT > and BETWEEN on a nullable multi-value column with a range index. It fails on master with the ClassCastException and passes with this change. I also ran the rest of NullHandlingEnabledQueriesTest, RangeQueriesTest, NullEnabledQueriesTest, FilterOperatorUtilsTest and ExplainPlanQueriesTest, plus the pinot-core spotless, checkstyle and license checks.

…der null handling

The partial range scan in RangeIndexBasedFilterOperator took its doc ids
from ScanBasedFilterOperator.getTrues() and cast the iterator to
ScanBasedDocIdIterator. With null handling enabled and nulls in the
column, getTrues() returns an AndDocIdSet with a bitmap iterator and the
cast threw. The scan now uses getNextBlockWithoutNullHandling(), since
the outer operator already handles the null rows.

Fixes apache#20330
ScanBasedFilterOperator scanBasedFilterOperator =
new ScanBasedFilterOperator(_queryContext, _predicateEvaluator, _dataSource, _numDocs);
BlockDocIdSet scanBasedDocIdSet = scanBasedFilterOperator.getTrues();
BlockDocIdSet scanBasedDocIdSet = scanBasedFilterOperator.getNextBlockWithoutNullHandling();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

H3IndexFilterOperator.getFilterBlock casts ExpressionFilterOperator.getTrues().iterator() to ScanBasedDocIdIterator the same way. Can null handling wrap that result in an AndDocIdSet as well, or is it safe there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's safe there. ExpressionFilterOperator extends BaseFilterOperator directly, not BaseColumnFilterOperator, so its getTrues() never goes through excludeNulls. It always returns an ExpressionDocIdSet, whose iterator is an ExpressionScanDocIdIterator, and that implements ScanBasedDocIdIterator. For an expression, null handling comes from getNulls() and getFalses() and never wraps the true set. H3IndexQueriesTest.testH3IndexWithNullHandling already runs ST_Distance(...) > 0 with null handling on, which reaches that cast through the partial match path, and it passes on this branch.

@Jackie-Jiang Jackie-Jiang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. The fix preserves null exclusion and negation semantics while keeping the partial-range scan iterator compatible with applyAnd. Both the single-value and multi-value regression tests exercise the affected legacy range-index path.

Reviewed ea68cbd. No blocking findings; two optional improvements inline. This was a static review; I did not run tests locally. All six CI workflows currently report action_required, so required checks still need to pass before merge.

@Jackie-Jiang
Jackie-Jiang merged commit 4bd680a into apache:master Nov 24, 2026
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.

Range filter on a version 1 range index fails with ClassCastException when null handling is enabled

3 participants