@@ -382,6 +382,18 @@ private static void checkCategorizeGrouping(Aggregate agg, Set<Failure> failures
382
382
);
383
383
}
384
384
})));
385
+ agg .aggregates ().forEach (a -> a .forEachDown (FilteredExpression .class , fe -> fe .filter ().forEachDown (Attribute .class , attribute -> {
386
+ var categorize = categorizeByAttribute .get (attribute );
387
+ if (categorize != null ) {
388
+ failures .add (
389
+ fail (
390
+ attribute ,
391
+ "cannot reference CATEGORIZE grouping function [{}] within an aggregation filter" ,
392
+ attribute .sourceText ()
393
+ )
394
+ );
395
+ }
396
+ })));
385
397
}
386
398
387
399
private static void checkRateAggregates (Expression expr , int nestedLevel , Set <Failure > failures ) {
@@ -421,7 +433,8 @@ private static void checkInvalidNamedExpressionUsage(
421
433
Expression filter = fe .filter ();
422
434
failures .add (fail (filter , "WHERE clause allowed only for aggregate functions, none found in [{}]" , fe .sourceText ()));
423
435
}
424
- Expression f = fe .filter (); // check the filter has to be a boolean term, similar as checkFilterConditionType
436
+ Expression f = fe .filter ();
437
+ // check the filter has to be a boolean term, similar as checkFilterConditionType
425
438
if (f .dataType () != NULL && f .dataType () != BOOLEAN ) {
426
439
failures .add (fail (f , "Condition expression needs to be boolean, found [{}]" , f .dataType ()));
427
440
}
@@ -432,9 +445,10 @@ private static void checkInvalidNamedExpressionUsage(
432
445
fail (af , "cannot use aggregate function [{}] in aggregate WHERE clause [{}]" , af .sourceText (), fe .sourceText ())
433
446
);
434
447
}
435
- // check the bucketing function against the group
448
+ // check the grouping function against the group
436
449
else if (c instanceof GroupingFunction gf ) {
437
- if (Expressions .anyMatch (groups , ex -> ex instanceof Alias a && a .child ().semanticEquals (gf )) == false ) {
450
+ if (c instanceof Categorize
451
+ || Expressions .anyMatch (groups , ex -> ex instanceof Alias a && a .child ().semanticEquals (gf )) == false ) {
438
452
failures .add (fail (gf , "can only use grouping function [{}] as part of the BY clause" , gf .sourceText ()));
439
453
}
440
454
}
0 commit comments