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 parser-level expansion for the STATS and EXTENDED_STATS compound aggregates, matching legacy V1 SQL plugin output. A query like SELECT STATS(price) FROM orders now expands to its primitive
components at AST-building time, so the analyzer/planner sees only standard primitives.
Compound
Expanded columns
STATS(f)
count, sum, avg, min, max
EXTENDED_STATS(f)
above + sumOfSquares, variance, stdDeviation
variance and stdDeviation use population variants (var_pop, stddev_pop), matching V1. sumOfSquares lowers to SUM(f * f).
Display-name format matches V1: STATS(price).count, or p.count when an explicit AS p is given. FILTER (WHERE …) propagates to every primitive.
The loop at line 132 iterates over ctx.selectElements().selectElement() but never adds non-compound items to the builder when ctx.selectElements().star is null and there are no compound aggregates. If all select elements are non-compound, the builder remains empty after the star check, resulting in an empty Project. The old code always added every field; this change only adds items inside the loop body, which may skip additions if the condition at line 134 is false for all items.
for (SelectElementContextelement : ctx.selectElements().selectElement()) {
UnresolvedExpressionitem = visitSelectItem(element);
if (CompoundAggregateExpander.isCompoundAggregateAlias(item)) {
builder.addAll(expandCompoundAggregate(item));
} else {
builder.add(item);
}
}
returnnewProject(builder.build());
The SQUARE transform at line 46-47 constructs new Function("*", List.of(field, field)) by passing the same field reference twice. If field is a mutable expression or if downstream code mutates one of the references, both operands could be affected. While UnresolvedExpression implementations may be immutable, the contract is not enforced here, and shared references can lead to unexpected aliasing issues if the expression tree is modified later.
privatestaticfinalUnaryOperator<UnresolvedExpression> SQUARE =
field -> newFunction("*", List.of(field, field));
The resolveComponents method should validate that the compoundName is not empty before attempting to look it up. An empty string will pass the null check but fail to match any registered aggregate, resulting in a less informative error message.
private static List<Component> resolveComponents(String compoundName) {
- if (compoundName == null) {- throw new IllegalArgumentException("compoundName is null");+ if (compoundName == null || compoundName.isEmpty()) {+ throw new IllegalArgumentException("compoundName is null or empty");
}
List<Component> components = COMPOUND_AGGREGATES.get(compoundName.toUpperCase(Locale.ROOT));
if (components == null) {
throw new IllegalArgumentException("Not a compound aggregate: " + compoundName);
}
return components;
}
Suggestion importance[1-10]: 4
__
Why: Adding an empty string check improves error handling by providing a more specific error message. However, the impact is minimal since the existing code already handles this case by throwing an exception when the lookup fails. The improvement is primarily in error message clarity rather than correctness.
The reason will be displayed to describe this comment to others. Learn more.
Please fix DCO and add IT to verify. I assume this will enable in SQL V2 engine too (previously query with such function falls back to legacy engine), I recall many legacy IT was ignored after 3.0
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.
Description
Adds parser-level expansion for the
STATSandEXTENDED_STATScompound aggregates, matching legacy V1 SQL plugin output. A query likeSELECT STATS(price) FROM ordersnow expands to its primitivecomponents at AST-building time, so the analyzer/planner sees only standard primitives.
STATS(f)count, sum, avg, min, maxEXTENDED_STATS(f)sumOfSquares, variance, stdDeviationvarianceandstdDeviationuse population variants (var_pop,stddev_pop), matching V1.sumOfSquareslowers toSUM(f * f).Display-name format matches V1:
STATS(price).count, orp.countwhen an explicitAS pis given.FILTER (WHERE …)propagates to every primitive.