|
@@ -593,20 +593,36 @@ public final class Verifier {
|
|
|
// 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 -> e.forEachDown(f ->
|
|
|
+ proj.projections().forEach(e -> e.forEachDown(f ->
|
|
|
localFailures.add(fail(f, "[{}] needs to be part of the grouping", Expressions.name(f))), GroupingFunction.class));
|
|
|
} else if (p instanceof Aggregate) {
|
|
|
- // if it does have a GROUP BY, check if the groupings contain the grouping functions (Histograms)
|
|
|
+ // if it does have a GROUP BY, check if the groupings contain the grouping functions (Histograms)
|
|
|
Aggregate a = (Aggregate) p;
|
|
|
a.aggregates().forEach(agg -> agg.forEachDown(e -> {
|
|
|
- if (a.groupings().size() == 0
|
|
|
+ if (a.groupings().size() == 0
|
|
|
|| Expressions.anyMatch(a.groupings(), g -> g instanceof Function && e.functionEquals((Function) g)) == false) {
|
|
|
localFailures.add(fail(e, "[{}] needs to be part of the grouping", Expressions.name(e)));
|
|
|
}
|
|
|
+ else {
|
|
|
+ checkGroupingFunctionTarget(e, localFailures);
|
|
|
+ }
|
|
|
+ }, GroupingFunction.class));
|
|
|
+
|
|
|
+ a.groupings().forEach(g -> g.forEachDown(e -> {
|
|
|
+ checkGroupingFunctionTarget(e, localFailures);
|
|
|
}, GroupingFunction.class));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void checkGroupingFunctionTarget(GroupingFunction f, Set<Failure> localFailures) {
|
|
|
+ f.field().forEachDown(e -> {
|
|
|
+ if (e instanceof GroupingFunction) {
|
|
|
+ localFailures.add(fail(f.field(), "Cannot embed grouping functions within each other, found [{}] in [{}]",
|
|
|
+ Expressions.name(f.field()), Expressions.name(f)));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private static void checkFilterOnAggs(LogicalPlan p, Set<Failure> localFailures) {
|
|
|
if (p instanceof Filter) {
|
|
|
Filter filter = (Filter) p;
|