Fix aggregation filter expression processing in the absense of projection (#14893)

* test

* fix

* add 33 test

* crap

* Revert "crap"

This reverts commit 2751198deb.

* cleanup test

* celanup

* rename test
This commit is contained in:
Zoltan Haindrich 2023-08-22 19:17:14 +02:00 committed by GitHub
parent 9376d8d6e1
commit b9a33949fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -73,12 +73,13 @@ public class GroupByRules
if (call.filterArg >= 0) {
// AGG(xxx) FILTER(WHERE yyy)
if (project == null) {
// We need some kind of projection to support filtered aggregations.
return null;
}
final RexNode expression = project.getProjects().get(call.filterArg);
final RexNode expression = Expressions.fromFieldAccess(
rexBuilder.getTypeFactory(),
rowSignature,
project,
call.filterArg);
final DimFilter nonOptimizedFilter = Expressions.toFilter(
plannerContext,
rowSignature,

View File

@ -32,6 +32,7 @@ import org.apache.druid.query.LookupDataSource;
import org.apache.druid.query.QueryDataSource;
import org.apache.druid.query.aggregation.CountAggregatorFactory;
import org.apache.druid.query.aggregation.DoubleSumAggregatorFactory;
import org.apache.druid.query.aggregation.FilteredAggregatorFactory;
import org.apache.druid.query.dimension.DefaultDimensionSpec;
import org.apache.druid.query.extraction.SubstringDimExtractionFn;
import org.apache.druid.query.groupby.GroupByQuery;
@ -1923,4 +1924,26 @@ public class CalciteSelectQueryTest extends BaseCalciteQueryTest
)
);
}
@Test
public void testAggregateFilterInTheAbsenceOfProjection()
{
cannotVectorize();
testQuery(
"select count(1) filter (where __time > date '2023-01-01') " +
" from druid.foo where 'a' = 'b'",
ImmutableList.of(
Druids.newTimeseriesQueryBuilder()
.dataSource(InlineDataSource.fromIterable(
ImmutableList.of(),
RowSignature.builder().add("$f1", ColumnType.LONG).build()))
.intervals(querySegmentSpec(Filtration.eternity()))
.granularity(Granularities.ALL)
.aggregators(aggregators(
new FilteredAggregatorFactory(
new CountAggregatorFactory("a0"), expressionFilter("\"$f1\""))))
.context(QUERY_CONTEXT_DEFAULT)
.build()),
ImmutableList.of(new Object[] {0L}));
}
}