You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds parse-time support for histogram and date_histogram in V2 SQL with named-argument invocation. Each call lowers to existing AST primitives (Span, COALESCE, DATE_FORMAT, TIMESTAMPADD).
Supported parameters
histogram: field, interval, offset, missing
date_histogram: field, interval / fixed_interval / calendar_interval, format, time_zone, missing
Deferred to follow-up PR
min_doc_count, order, alias — need parser-side plumbing to mutate the surrounding query (HAVING / ORDER BY / SELECT-list alias).
date_histogramoffset — needs a duration-string parser distinct from time_zone's ZoneOffset format.
The time_zone parameter is validated at parse time as a ZoneOffset (e.g., '+05:30', 'Z'), but named time zones like 'America/New_York' are not supported. If users expect full time zone support (as the parameter name suggests), this will fail at parse time with a confusing error. The error message mentions "offset like '+05:30' or 'Z'" but does not clarify that named zones are unsupported.
privatestaticUnresolvedExpressionapplyTimeZoneShift(
UnresolvedExpressionfield, LiteraltimeZoneLiteral) {
StringtzString = timeZoneLiteral.getValue().toString();
intoffsetSeconds;
try {
offsetSeconds = ZoneOffset.of(tzString).getTotalSeconds();
} catch (RuntimeExceptionex) {
thrownewSemanticCheckException(
"time_zone must be a valid offset like '+05:30' or 'Z'; got '" + tzString + "'");
}
The original buildFunction method call was removed without verifying that all its logic is preserved. If buildFunction performed additional validation or transformation beyond constructing a Function object, that logic is now lost. This could break existing scalar function calls if they relied on that behavior.
The catch block catches all RuntimeException types, which may mask unexpected errors. Consider catching only DateTimeException to specifically handle invalid timezone offset parsing failures while allowing other runtime exceptions to propagate.
private static UnresolvedExpression applyTimeZoneShift(
UnresolvedExpression field, Literal timeZoneLiteral) {
String tzString = timeZoneLiteral.getValue().toString();
int offsetSeconds;
try {
offsetSeconds = ZoneOffset.of(tzString).getTotalSeconds();
- } catch (RuntimeException ex) {+ } catch (DateTimeException ex) {
throw new SemanticCheckException(
"time_zone must be a valid offset like '+05:30' or 'Z'; got '" + tzString + "'");
}
return new Function(
"timestampadd",
List.of(AstDSL.stringLiteral("SECOND"), AstDSL.intLiteral(offsetSeconds), field));
}
Suggestion importance[1-10]: 7
__
Why: Catching DateTimeException instead of RuntimeException is more precise and prevents masking unexpected errors. However, this is a minor improvement in exception handling that doesn't address a critical bug.
Medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds parse-time support for
histogramanddate_histogramin V2 SQL with named-argument invocation. Each call lowers to existing AST primitives (Span,COALESCE,DATE_FORMAT,TIMESTAMPADD).Supported parameters
histogram:field,interval,offset,missingdate_histogram:field,interval/fixed_interval/calendar_interval,format,time_zone,missingDeferred to follow-up PR
min_doc_count,order,alias— need parser-side plumbing to mutate the surrounding query (HAVING / ORDER BY / SELECT-list alias).date_histogramoffset— needs a duration-string parser distinct fromtime_zone'sZoneOffsetformat.