Skip to content

fix: add column-type precondition check in isFitForNonScanBasedPlan for MINLONG/MAXLONG/MINSTRING/MAXSTRING - #19146

Open
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/aggregation-non-scan-type-check-19145
Open

fix: add column-type precondition check in isFitForNonScanBasedPlan for MINLONG/MAXLONG/MINSTRING/MAXSTRING#19146
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/aggregation-non-scan-type-check-19145

Conversation

@waterWang

Copy link
Copy Markdown

Description

Fixes #19145

The non-scan (metadata/dictionary based) aggregation path treats MINLONG, MAXLONG, MINSTRING, and MAXSTRING as resolvable if the column merely has a dictionary, without checking that the column type is one the function actually supports. This causes inconsistent behavior:

  • MINLONG/MAXLONG over FLOAT/DOUBLE/BIG_DECIMAL: IllegalArgumentException is thrown (the non-scan path is too strict — the scan path computes the result fine).
  • MINSTRING/MAXSTRING over numeric columns: silently returns a wrong result from the dictionary (the non-scan path is too lax — the scan path correctly rejects with BadQueryRequestException).

Fix

Add type precondition checks in isFitForNonScanBasedPlan() so unsupported column-type combinations fall back to the scan path:

  • MINLONG / MAXLONG: require stored type INT or LONG
  • MINSTRING / MAXSTRING: require stored type STRING

Testing

  • MINLONG(doubleCol), MAXLONG(doubleCol), MINSTRING(intCol), MAXSTRING(intCol) on a single dictionary-encoded column with no filter now correctly fall back to the scan path, matching the behavior of mixed queries like MINLONG(doubleCol), SUM(intCol).

…or MINLONG/MAXLONG/MINSTRING/MAXSTRING (apache#19145)

The non-scan (metadata/dictionary based) aggregation path treats MINLONG,
MAXLONG, MINSTRING, and MAXSTRING as resolvable if the column merely has a
dictionary, without checking the column type is one the function actually
supports. This causes:
- MINLONG/MAXLONG over FLOAT/DOUBLE/BIG_DECIMAL: IllegalArgumentException
  (the non-scan path is too strict)
- MINSTRING/MAXSTRING over numeric columns: silently returns wrong result
  from dictionary (the non-scan path is too lax)

Fix: Add type precondition checks in isFitForNonScanBasedPlan() so
unsupported combinations fall back to the scan path:
- MINLONG/MAXLONG: require stored type INT or LONG
- MINSTRING/MAXSTRING: require stored type STRING
@Jackie-Jiang
Jackie-Jiang requested review from yashmayya and a lite review from Copilot August 6, 2026 19:31
@Jackie-Jiang Jackie-Jiang added bug Something is not working as expected query Related to query processing labels Aug 6, 2026

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

bug Something is not working as expected query Related to query processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata/dictionary based aggregation ignores column-type preconditions for MINLONG/MAXLONG and MINSTRING/MAXSTRING

3 participants