Skip to content

[BugFix] Fix bin/chart NPE with null values (#5174)#24

Closed
qianheng-aws wants to merge 2 commits intorefactor/dedupe-reusable-workflowfrom
fix/5174-chart-npe
Closed

[BugFix] Fix bin/chart NPE with null values (#5174)#24
qianheng-aws wants to merge 2 commits intorefactor/dedupe-reusable-workflowfrom
fix/5174-chart-npe

Conversation

@qianheng-aws
Copy link
Copy Markdown
Owner

Summary

  • Fix NullPointerException when using bin then chart with null values in the binned field
  • Root cause: bin bucket functions (SpanBucketFunction, MinspanBucketFunction, RangeBucketFunction) declared non-nullable VARCHAR return type, causing Calcite to optimize away IS NOT NULL filters, allowing null group keys to reach Enumerable aggregation's TreeMap which crashes in compareTo
  • Fix: declare return type as nullable using FORCE_NULLABLE so null-filtering in visitAggregation works correctly
  • Also add nullsLast to chart command sorts as a defensive measure

Resolves opensearch-project#5174

Test plan

  • Unit test (CalcitePPLChartNullTest) verifying logical plan includes null filter
  • Integration test (CalciteBinChartNullIT) verifying bin+chart with null values works end-to-end
  • YAML REST test (5174.yml) reproducing the exact scenario from the issue
  • Existing chart and bin tests pass without regressions

…pensearch-project#5269) (opensearch-project#5293)

When querying across indices with conflicting field mappings (boolean vs
text), numeric values like 0 were not coerced to boolean, causing
"node must be a boolean, found NUMBER" error. Added numeric handling to
parseBooleanValue() consistent with ObjectContent.booleanValue().

Signed-off-by: Heng Qian <qianheng@amazon.com>
The bin bucket functions (SpanBucketFunction, MinspanBucketFunction,
RangeBucketFunction) declared a non-nullable VARCHAR return type via
ReturnTypes.VARCHAR_2000, even though they return null for null inputs.
This caused Calcite's optimizer to remove IS NOT NULL filters as
trivially true, allowing null group keys to reach the Enumerable
aggregation's TreeMap, which crashed with NPE in compareTo.

Fix the return type to be nullable using FORCE_NULLABLE, so the
null-filtering logic in visitAggregation works correctly. Also add
nullsLast to chart command sorts as a defensive measure.

Signed-off-by: Heng Qian <qianheng@amazon.com>
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.

[BUG] bin then chart with null values causes NullPointerException in compareTo

1 participant