Nested GroupBy query got wrong/empty result when using virtual column and filter (#11081)

* fix nested groupby got empty result when using virtual column

* move to query.getVirtualColumns().wrap instead of new VirtualizedColumnSelectorFactory

* move test to GroupByQueryRunnerTest

* Update processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java

Co-authored-by: huagnhui.bigrey <huanghui.bigrey@bytedance.com>
Co-authored-by: Jihoon Son <jihoonson@apache.org>
This commit is contained in:
BIGrey 2021-04-11 12:29:41 +08:00 committed by GitHub
parent 95b82dd325
commit d33fdd093b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 2 deletions

View File

@ -399,7 +399,7 @@ public class RowBasedGrouperHelper
final SettableSupplier<ResultRow> rowSupplier = new SettableSupplier<>();
final ColumnSelectorFactory columnSelectorFactory =
RowBasedGrouperHelper.createResultRowBasedColumnSelectorFactory(subquery, rowSupplier);
query.getVirtualColumns().wrap(RowBasedGrouperHelper.createResultRowBasedColumnSelectorFactory(subquery, rowSupplier));
final ValueMatcher filterMatcher = filter == null
? BooleanValueMatcher.of(true)

View File

@ -10767,6 +10767,79 @@ public class GroupByQueryRunnerTest extends InitializedNullHandlingTest
TestHelper.assertExpectedObjects(expectedResults, results, "limit-pushdown");
}
@Test
public void testVirtualColumnFilterOnInnerQuery()
{
GroupByQuery subquery = makeQueryBuilder()
.setDataSource(QueryRunnerTestHelper.DATA_SOURCE)
.setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD)
.setDimensions(new DefaultDimensionSpec("quality", "alias"))
.setLimitSpec(
new DefaultLimitSpec(
Collections.singletonList(new OrderByColumnSpec("alias", OrderByColumnSpec.Direction.DESCENDING)),
12
)
)
.setAggregatorSpecs(
QueryRunnerTestHelper.ROWS_COUNT,
new LongSumAggregatorFactory("idx", "index")
)
.setGranularity(QueryRunnerTestHelper.DAY_GRAN)
.build();
GroupByQuery query = makeQueryBuilder()
.setDataSource(subquery)
.setQuerySegmentSpec(
new MultipleIntervalSegmentSpec(
ImmutableList.of(
Intervals.of("2011-04-01T00:00:00.000Z/2011-04-01T23:58:00.000Z"),
Intervals.of("2011-04-02T00:00:00.000Z/2011-04-03T00:00:00.000Z")
)
)
).setDimensions(new DefaultDimensionSpec("alias", "alias"))
.setVirtualColumns(
new ExpressionVirtualColumn(
"v",
"case_searched(idx > 1000, 1, 0)",
ValueType.LONG,
TestExprMacroTable.INSTANCE
)
)
.setDimFilter(
new BoundDimFilter(
"v",
"0",
null,
true,
false,
null,
null,
StringComparators.NUMERIC
)
)
.setLimitSpec(
new DefaultLimitSpec(
Collections.singletonList(new OrderByColumnSpec("alias", OrderByColumnSpec.Direction.DESCENDING)),
15
)
)
.setAggregatorSpecs(
new LongSumAggregatorFactory("rows", "rows"),
new LongSumAggregatorFactory("idx", "idx")
)
.setGranularity(QueryRunnerTestHelper.DAY_GRAN)
.build();
List<ResultRow> expectedResults = Arrays.asList(
makeRow(query, "2011-04-01", "alias", "premium", "rows", 3L, "idx", 2900L),
makeRow(query, "2011-04-01", "alias", "mezzanine", "rows", 3L, "idx", 2870L),
makeRow(query, "2011-04-02", "alias", "premium", "rows", 3L, "idx", 2505L)
);
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "virtual column filter on inner query");
}
@Test
public void testRejectForceLimitPushDownWithHaving()
{

View File

@ -148,7 +148,6 @@ public class NestedQueryPushDownTest
@Before
public void setup() throws Exception
{
tmpDir = FileUtils.createTempDir();