-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL: Generate relevant error message when grouping functions are not used in GROUP BY #38017
Changes from 1 commit
2707a44
51b19ef
f1f7397
08f75e5
2658b70
36244c7
ff39950
08a2bf7
597eeaa
0e1b6c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,7 @@ Collection<Failure> verify(LogicalPlan plan) { | |
validateInExpression(p, localFailures); | ||
validateConditional(p, localFailures); | ||
|
||
checkHistogramInGrouping(p, localFailures); | ||
checkFilterOnAggs(p, localFailures); | ||
checkFilterOnGrouping(p, localFailures); | ||
|
||
|
@@ -560,6 +561,37 @@ private static boolean checkGroupMatch(Expression e, Node<?> source, List<Expres | |
} | ||
return false; | ||
} | ||
|
||
private static void checkHistogramInGrouping(LogicalPlan p, Set<Failure> localFailures) { | ||
// check if the query has a grouping function (Histogram) but no GROUP BY | ||
if (p instanceof Project) { | ||
Project proj = (Project) p; | ||
|
||
proj.projections().forEach(e -> { | ||
if (Functions.isGrouping(e) == false) { | ||
e.collectFirstChildren(c -> { | ||
if (Functions.isGrouping(c)) { | ||
localFailures.add(fail(c, "[%s] needs to be part of the grouping", Expressions.name(c))); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} else { | ||
localFailures.add(fail(e, "[%s] needs to be part of the grouping", Expressions.name(e))); | ||
} | ||
}); | ||
} else if (p instanceof Aggregate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this block is a bit condensed and could use some whitespace and indentation to make it more readable. |
||
// if it does have a GROUP BY, check if the groupings contain the grouping functions (Histograms) | ||
Aggregate a = (Aggregate) p; | ||
|
||
a.aggregates().forEach(as -> { | ||
Expression exp = as instanceof Alias ? ((Alias) as).child() : as; | ||
if (Functions.isGrouping(exp) && false == Expressions.anyMatch(a.groupings(), g -> exp.semanticEquals(g))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the histogram is wrapped with a Scalar function? is it caught somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was already handled. See the test here. |
||
localFailures.add(fail(exp, "[%s] needs to be part of the grouping", Expressions.name(exp))); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
private static void checkFilterOnAggs(LogicalPlan p, Set<Failure> localFailures) { | ||
if (p instanceof Filter) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collectFirstChildren
uses a List to add the matches which we don't need in this impl.Why don't you use
forEachDown
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the approach and pushed a new commit.