Skip to content

Conversation

@mshahid6
Copy link

Description

Some invalid queries, like:
select SPECTATOR_PERCENTILE(null, '99.99') from "foo"

throw

Error: UNCATEGORIZED (ADMIN)
class org.apache.calcite.util.NlsString cannot be cast to class java.lang.Number (org.apache.calcite.util.NlsString is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')

which causes Druid to incorrectly return 500 to the user instead of 400 (user error).

This change checks instanceof before casting RexLiteral.value() to Number in SQL aggregators. When users pass invalid queries (e.g., a string literal '99.99' where numeric literals are expected), InvalidSqlInput exception is thrown, which returns 400 (USER/INVALID_INPUT) instead of 500 (ADMIN/UNCATEGORIZED). This improves error diagnostics for invalid queries.

Key changed/added classes in this PR
  • SpectatorHistogramPercentileSqlAggregator
  • HllSketchBaseSqlAggregator
  • DoublesSketchApproxQuantileSqlAggregator
  • ThetaSketchBaseSqlAggregator
  • BloomFilterSqlAggregator
  • QuantileSqlAggregator
  • ArrayConcatSqlAggregator
  • ArraySqlAggregator
  • StringSqlAggregator

Release note

Improved: type validation for numeric literal parameters in SQL aggregator functions to prevent ClassCastException and provide better error message categorized as user error

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

…errors (InvalidSqlInput) for invalid queries
@jtuglu1 jtuglu1 self-requested a review January 23, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant