diff --git a/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java b/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java index 2273dbea2f1..9b6007680df 100644 --- a/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java +++ b/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java @@ -103,7 +103,8 @@ public ITupleIterator search(StorageContext context, SQLDigest sqlDigest, TupleI return ITupleIterator.EMPTY_TUPLE_ITERATOR; return new SequentialCubeTupleIterator(scanners, request.getCuboid(), request.getDimensions(), - request.getDynGroups(), request.getGroups(), request.getMetrics(), returnTupleInfo, request.getContext(), sqlDigest); + request.getDynGroups(), request.getGroups(), request.getMetrics(), returnTupleInfo, + request.getContext(), sqlDigest); } public GTCubeStorageQueryRequest getStorageQueryRequest(StorageContext context, SQLDigest sqlDigest, @@ -177,7 +178,7 @@ public GTCubeStorageQueryRequest getStorageQueryRequest(StorageContext context, // set limit push down enableStorageLimitIfPossible(cuboid, groups, dynGroups, derivedPostAggregation, groupsD, filterD, - loosenedColumnD, sqlDigest.aggregations, context); + loosenedColumnD, sqlDigest, context); // set whether to aggregate results from multiple partitions enableStreamAggregateIfBeneficial(cuboid, groupsD, context); // check query deadline @@ -421,7 +422,8 @@ private void collectColumnsRecursively(TupleFilter filter, Set collec private void enableStorageLimitIfPossible(Cuboid cuboid, Collection groups, List dynGroups, Set derivedPostAggregation, Collection groupsD, TupleFilter filter, - Set loosenedColumnD, Collection functionDescs, StorageContext context) { + Set loosenedColumnD, SQLDigest sqlDigest, StorageContext context) { + Collection functionDescs = sqlDigest.aggregations; StorageLimitLevel storageLimitLevel = StorageLimitLevel.LIMIT_ON_SCAN; @@ -469,6 +471,11 @@ private void enableStorageLimitIfPossible(Cuboid cuboid, Collection g } } + if (sqlDigest.groupByExpression) { + storageLimitLevel = StorageLimitLevel.NO_LIMIT; + logger.debug("storageLimitLevel set to NO_LIMIT because group by clause is an expression"); + } + context.applyLimitPushDown(cubeInstance, storageLimitLevel); } diff --git a/kylin-it/src/test/resources/query/sql_casewhen/query57.sql b/kylin-it/src/test/resources/query/sql_casewhen/query57.sql new file mode 100644 index 00000000000..76ae6496cb5 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_casewhen/query57.sql @@ -0,0 +1,23 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SELECT (CASE WHEN ("TEST_KYLIN_FACT"."LSTG_FORMAT_NAME" IN ('Auction', 'FP-GTC')) THEN 'Auction' ELSE "TEST_KYLIN_FACT"."LSTG_FORMAT_NAME" END) AS "LSTG_FORMAT_NAME__group_", + SUM("TEST_KYLIN_FACT"."PRICE") AS "sum_PRICE_ok" +FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT" +GROUP BY (CASE WHEN ("TEST_KYLIN_FACT"."LSTG_FORMAT_NAME" IN ('Auction', 'FP-GTC')) THEN 'Auction' ELSE "TEST_KYLIN_FACT"."LSTG_FORMAT_NAME" END) +LIMIT 4 \ No newline at end of file