Skip to content

Commit

Permalink
#KYLIN-4158, limit not push down to storage scan level if group by is…
Browse files Browse the repository at this point in the history
… an expression
  • Loading branch information
ZhengshuaiPENG authored and nichunen committed Sep 11, 2019
1 parent 12655bf commit 661f5ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -421,7 +422,8 @@ private void collectColumnsRecursively(TupleFilter filter, Set<TblColRef> collec

private void enableStorageLimitIfPossible(Cuboid cuboid, Collection<TblColRef> groups, List<TblColRef> dynGroups,
Set<TblColRef> derivedPostAggregation, Collection<TblColRef> groupsD, TupleFilter filter,
Set<TblColRef> loosenedColumnD, Collection<FunctionDesc> functionDescs, StorageContext context) {
Set<TblColRef> loosenedColumnD, SQLDigest sqlDigest, StorageContext context) {
Collection<FunctionDesc> functionDescs = sqlDigest.aggregations;

StorageLimitLevel storageLimitLevel = StorageLimitLevel.LIMIT_ON_SCAN;

Expand Down Expand Up @@ -469,6 +471,11 @@ private void enableStorageLimitIfPossible(Cuboid cuboid, Collection<TblColRef> 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);
}

Expand Down
23 changes: 23 additions & 0 deletions kylin-it/src/test/resources/query/sql_casewhen/query57.sql
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 661f5ac

Please sign in to comment.