diff --git a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java index d2663d4316a..afb1a1fad78 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java @@ -867,9 +867,13 @@ public class RowBasedGrouperHelper fieldIndices.add(i); aggFlags.add(false); needsReverses.add(false); - final ValueType type = dimensions.get(i).getOutputType(); - isNumericField.add(ValueType.isNumeric(type)); - comparators.add(StringComparators.LEXICOGRAPHIC); + boolean isNumeric = ValueType.isNumeric(dimensions.get(i).getOutputType()); + isNumericField.add(isNumeric); + if (isNumeric) { + comparators.add(StringComparators.NUMERIC); + } else { + comparators.add(StringComparators.LEXICOGRAPHIC); + } } } diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java index 6270f6bf822..5bceb0b73eb 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java @@ -9952,6 +9952,85 @@ public class GroupByQueryRunnerTest TestHelper.assertExpectedObjects(expectedResults, results, "order-limit"); } + @Test + public void testGroupByLimitPushDownWithLongDimensionNotInLimitSpec() + { + // Cannot vectorize due to extraction dimension spec. + cannotVectorize(); + + if (!config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V2)) { + return; + } + GroupByQuery query = makeQueryBuilder() + .setDataSource(QueryRunnerTestHelper.DATA_SOURCE) + .setGranularity(QueryRunnerTestHelper.ALL_GRAN).setDimensions( + new ExtractionDimensionSpec("quality", "qualityLen", ValueType.LONG, StrlenExtractionFn.instance()) + ) + .setInterval(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC) + .setLimitSpec( + new DefaultLimitSpec( + Collections.EMPTY_LIST, + 6 + ) + ).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT) + .overrideContext(ImmutableMap.of(GroupByQueryConfig.CTX_KEY_FORCE_LIMIT_PUSH_DOWN, true)) + .build(); + + List expectedResults = Arrays.asList( + makeRow( + query, + "1970-01-01T00:00:00.000Z", + "qualityLen", + 4L, + "rows", + 93L + ), + makeRow( + query, + "1970-01-01T00:00:00.000Z", + "qualityLen", + 6L, + "rows", + 186L + ), + makeRow( + query, + "1970-01-01T00:00:00.000Z", + "qualityLen", + 7L, + "rows", + 279L + ), + makeRow( + query, + "1970-01-01T00:00:00.000Z", + "qualityLen", + 8L, + "rows", + 93L + ), + makeRow( + query, + "1970-01-01T00:00:00.000Z", + "qualityLen", + 9L, + "rows", + 279L + ), + makeRow( + query, + "1970-01-01T00:00:00.000Z", + "qualityLen", + 10L, + "rows", + 186L + ) + ); + + Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query); + TestHelper.assertExpectedObjects(expectedResults, results, "order-limit"); + } + @Test public void testMergeResultsWithLimitPushDown() {