From e76a5077efe64ea3108ff1133339c1ba5d19163f Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Fri, 17 Jun 2022 16:15:50 -0700 Subject: [PATCH] Fix self-referential shape inspection in BaseExpressionColumnValueSelector. (#12669) * Fix self-referential shape inspection in BaseExpressionColumnValueSelector. The new test would throw StackOverflowError on the old code. * Restore prior test. --- .../BaseExpressionColumnValueSelector.java | 2 +- .../druid/query/topn/TopNQueryRunnerTest.java | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/processing/src/main/java/org/apache/druid/segment/virtual/BaseExpressionColumnValueSelector.java b/processing/src/main/java/org/apache/druid/segment/virtual/BaseExpressionColumnValueSelector.java index 868196c600b..a9fd30a130c 100644 --- a/processing/src/main/java/org/apache/druid/segment/virtual/BaseExpressionColumnValueSelector.java +++ b/processing/src/main/java/org/apache/druid/segment/virtual/BaseExpressionColumnValueSelector.java @@ -86,7 +86,7 @@ public abstract class BaseExpressionColumnValueSelector implements ColumnValueSe @Override public void inspectRuntimeShape(final RuntimeShapeInspector inspector) { - inspector.visit("rowIdSupplier", this); + inspector.visit("rowIdSupplier", rowIdSupplier); } /** diff --git a/processing/src/test/java/org/apache/druid/query/topn/TopNQueryRunnerTest.java b/processing/src/test/java/org/apache/druid/query/topn/TopNQueryRunnerTest.java index 2a2f0c68b6d..d475cc9f7f1 100644 --- a/processing/src/test/java/org/apache/druid/query/topn/TopNQueryRunnerTest.java +++ b/processing/src/test/java/org/apache/druid/query/topn/TopNQueryRunnerTest.java @@ -4614,6 +4614,48 @@ public class TopNQueryRunnerTest extends InitializedNullHandlingTest assertExpectedResults(expectedResults, query); } + @Test + public void testFullOnTopNAggregateLongVirtualColumn() + { + TopNQuery query = new TopNQueryBuilder() + .dataSource(QueryRunnerTestHelper.DATA_SOURCE) + .granularity(QueryRunnerTestHelper.ALL_GRAN) + .virtualColumns(new ExpressionVirtualColumn("v0", "index", ColumnType.LONG, ExprMacroTable.nil())) + .dimension(new DefaultDimensionSpec("quality", "quality")) + .metric("sumIndex") + .threshold(4) + .intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC) + .aggregators(Collections.singletonList(new LongSumAggregatorFactory("sumIndex", "v0"))) + .build(); + + List> expectedResults = Collections.singletonList( + new Result<>( + DateTimes.of("2011-01-12T00:00:00.000Z"), + new TopNResultValue( + Arrays.>asList( + ImmutableMap.builder() + .put("quality", "mezzanine") + .put("sumIndex", 217586L) + .build(), + ImmutableMap.builder() + .put("quality", "premium") + .put("sumIndex", 210722L) + .build(), + ImmutableMap.builder() + .put("quality", "automotive") + .put("sumIndex", 12226L) + .build(), + ImmutableMap.builder() + .put("quality", "entertainment") + .put("sumIndex", 12038L) + .build() + ) + ) + ) + ); + assertExpectedResults(expectedResults, query); + } + @Test public void testTopNStringVirtualColumn() {