KYLIN-1471 - LIMIT after having clause should not be pushed down to storage context
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/85e9c30d Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/85e9c30d Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/85e9c30d Branch: refs/heads/1.4-rc Commit: 85e9c30d797693b4d9246b5e84888fb2a3f5ddc6 Parents: 83f49c3 Author: Hongbin Ma <mahong...@apache.org> Authored: Fri Mar 4 16:00:11 2016 +0800 Committer: Hongbin Ma <mahong...@apache.org> Committed: Tue Mar 8 14:31:16 2016 +0800 ---------------------------------------------------------------------- .../resources/query/sql_tableau/query29.sql | 29 ++++++++++++++++++++ .../apache/kylin/query/relnode/OLAPContext.java | 1 + .../kylin/query/relnode/OLAPFilterRel.java | 2 ++ .../kylin/query/relnode/OLAPLimitRel.java | 21 ++++++++------ 4 files changed, 44 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/85e9c30d/kylin-it/src/test/resources/query/sql_tableau/query29.sql ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_tableau/query29.sql b/kylin-it/src/test/resources/query/sql_tableau/query29.sql new file mode 100644 index 0000000..0858087 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_tableau/query29.sql @@ -0,0 +1,29 @@ +-- +-- 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 * + FROM ( + select test_kylin_fact.lstg_format_name, test_cal_dt.week_beg_dt,sum(test_kylin_fact.price) as GMV + , count(*) as TRANS_CNT + from test_kylin_fact + inner JOIN edw.test_cal_dt as test_cal_dt + ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt + where test_cal_dt.week_beg_dt between DATE '2013-05-01' and DATE '2013-08-01' + group by test_kylin_fact.lstg_format_name, test_cal_dt.week_beg_dt + ) "TableauSQL" + LIMIT 1 http://git-wip-us.apache.org/repos/asf/kylin/blob/85e9c30d/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java index 6865457..a6844e1 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java @@ -102,6 +102,7 @@ public class OLAPContext { public OLAPTableScan firstTableScan = null; // to be fact table scan except "select * from lookupTable" public TupleInfo returnTupleInfo = null; public boolean afterAggregate = false; + public boolean afterSkippedFilter = false; public boolean afterJoin = false; public boolean hasJoin = false; http://git-wip-us.apache.org/repos/asf/kylin/blob/85e9c30d/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java index 7b8bfdb..a847890 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java @@ -271,6 +271,8 @@ public class OLAPFilterRel extends Filter implements OLAPRel { // only translate where clause and don't translate having clause if (!context.afterAggregate) { translateFilter(context); + } else { + context.afterSkippedFilter = true;//having clause is skipped } } http://git-wip-us.apache.org/repos/asf/kylin/blob/85e9c30d/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java index 572a5c7..82aa9de 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java @@ -73,16 +73,19 @@ public class OLAPLimitRel extends SingleRel implements OLAPRel { implementor.visitChild(getInput(), this); this.columnRowType = buildColumnRowType(); - this.context = implementor.getContext(); - Number limitValue = (Number) (((RexLiteral) localFetch).getValue()); - int limit = limitValue.intValue(); - this.context.storageContext.setLimit(limit); - this.context.limit = limit; - if(localOffset != null) { - Number offsetValue = (Number) (((RexLiteral) localOffset).getValue()); - int offset = offsetValue.intValue(); - this.context.storageContext.setOffset(offset); + + if (!context.afterSkippedFilter) { + Number limitValue = (Number) (((RexLiteral) localFetch).getValue()); + int limit = limitValue.intValue(); + this.context.storageContext.setLimit(limit); + this.context.limit = limit; + + if (localOffset != null) { + Number offsetValue = (Number) (((RexLiteral) localOffset).getValue()); + int offset = offsetValue.intValue(); + this.context.storageContext.setOffset(offset); + } } }