KYLIN-1301 TRUE/FALSE filter pruning
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/c02582f2 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/c02582f2 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/c02582f2 Branch: refs/heads/KYLIN-1122 Commit: c02582f2a3c0ba473748a670e3837a3f0ce7935d Parents: d3b157a Author: honma <ho...@ebay.com> Authored: Wed Jan 13 17:50:41 2016 +0800 Committer: Xiaoyu Wang <wangxia...@apache.org> Committed: Mon Jan 18 13:38:30 2016 +0800 ---------------------------------------------------------------------- .../kylin/gridtable/GTScanRangePlanner.java | 12 ++++++--- .../kylin/gridtable/DictGridTableTest.java | 21 +++++++++++++++ query/src/test/resources/query/sql/query97.sql | 28 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/c02582f2/core-cube/src/main/java/org/apache/kylin/gridtable/GTScanRangePlanner.java ---------------------------------------------------------------------- diff --git a/core-cube/src/main/java/org/apache/kylin/gridtable/GTScanRangePlanner.java b/core-cube/src/main/java/org/apache/kylin/gridtable/GTScanRangePlanner.java index 27fa6b4..6ff1ab4 100644 --- a/core-cube/src/main/java/org/apache/kylin/gridtable/GTScanRangePlanner.java +++ b/core-cube/src/main/java/org/apache/kylin/gridtable/GTScanRangePlanner.java @@ -18,6 +18,7 @@ import org.apache.kylin.common.util.ImmutableBitSet; import org.apache.kylin.common.util.Pair; import org.apache.kylin.cube.common.FuzzyValueCombination; import org.apache.kylin.metadata.filter.CompareTupleFilter; +import org.apache.kylin.metadata.filter.ConstantTupleFilter; import org.apache.kylin.metadata.filter.LogicalTupleFilter; import org.apache.kylin.metadata.filter.TupleFilter; import org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum; @@ -49,7 +50,6 @@ public class GTScanRangePlanner { * @param partitionColRef the TblColRef in GT */ public GTScanRangePlanner(GTInfo info, Pair<ByteArray, ByteArray> segmentStartAndEnd, TblColRef partitionColRef) { - this.info = info; this.segmentStartAndEnd = segmentStartAndEnd; @@ -188,7 +188,9 @@ public class GTScanRangePlanner { throw new IllegalStateException("Filter should be AND instead of " + andFilter); Collection<ColumnRange> andRanges = translateToAndDimRanges(andFilter.getChildren()); - result.add(andRanges); + if (andRanges != null) { + result.add(andRanges); + } } return preEvaluateConstantConditions(result); @@ -198,7 +200,11 @@ public class GTScanRangePlanner { Map<TblColRef, ColumnRange> rangeMap = new HashMap<TblColRef, ColumnRange>(); for (TupleFilter filter : andFilters) { if ((filter instanceof CompareTupleFilter) == false) { - continue; + if (filter instanceof ConstantTupleFilter && !filter.evaluate(null, null)) { + return null; + } else { + continue; + } } CompareTupleFilter comp = (CompareTupleFilter) filter; http://git-wip-us.apache.org/repos/asf/kylin/blob/c02582f2/core-cube/src/test/java/org/apache/kylin/gridtable/DictGridTableTest.java ---------------------------------------------------------------------- diff --git a/core-cube/src/test/java/org/apache/kylin/gridtable/DictGridTableTest.java b/core-cube/src/test/java/org/apache/kylin/gridtable/DictGridTableTest.java index 4588051..df69c17 100644 --- a/core-cube/src/test/java/org/apache/kylin/gridtable/DictGridTableTest.java +++ b/core-cube/src/test/java/org/apache/kylin/gridtable/DictGridTableTest.java @@ -89,6 +89,7 @@ public class DictGridTableTest { ageComp2 = compare(info.colRef(1), FilterOperatorEnum.EQ, enc(info, 1, "20")); ageComp3 = compare(info.colRef(1), FilterOperatorEnum.EQ, enc(info, 1, "30")); ageComp4 = compare(info.colRef(1), FilterOperatorEnum.NEQ, enc(info, 1, "30")); + } @Test @@ -138,6 +139,26 @@ public class DictGridTableTest { assertEquals("[1421193600000, null]-[null, null]", r.get(0).toString()); assertEquals(0, r.get(0).fuzzyKeys.size()); } + { + //skip FALSE filter + LogicalTupleFilter filter = and(ageComp1, ConstantTupleFilter.FALSE); + List<GTScanRange> r = planner.planScanRanges(filter); + assertEquals(0, r.size()); + } + { + //TRUE or FALSE filter + LogicalTupleFilter filter = or(ConstantTupleFilter.TRUE, ConstantTupleFilter.FALSE); + List<GTScanRange> r = planner.planScanRanges(filter); + assertEquals(1, r.size()); + assertEquals("[null, null]-[null, null]", r.get(0).toString()); + } + { + //TRUE or other filter + LogicalTupleFilter filter = or(ageComp1, ConstantTupleFilter.TRUE); + List<GTScanRange> r = planner.planScanRanges(filter); + assertEquals(1, r.size()); + assertEquals("[null, null]-[null, null]", r.get(0).toString()); + } } @Test http://git-wip-us.apache.org/repos/asf/kylin/blob/c02582f2/query/src/test/resources/query/sql/query97.sql ---------------------------------------------------------------------- diff --git a/query/src/test/resources/query/sql/query97.sql b/query/src/test/resources/query/sql/query97.sql new file mode 100644 index 0000000..c9c0c6f --- /dev/null +++ b/query/src/test/resources/query/sql/query97.sql @@ -0,0 +1,28 @@ +-- +-- 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 test_cal_dt.cal_dt, count(*) as 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 + inner JOIN test_category_groupings + ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND test_kylin_fact.lstg_site_id = test_category_groupings.site_id + inner JOIN edw.test_sites as test_sites + ON test_kylin_fact.lstg_site_id = test_sites.site_id + where test_kylin_fact.lstg_format_name='XXXUnknown' + group by test_cal_dt.cal_dt