KYLIN-2029 distinct count query on lookup table
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/472e6d54 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/472e6d54 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/472e6d54 Branch: refs/heads/1.5.x-CDH5.7 Commit: 472e6d547f2f04b8d6f92b9affa173a9685d3d2d Parents: 7d716df Author: Hongbin Ma <mahong...@apache.org> Authored: Tue Sep 20 18:19:19 2016 +0800 Committer: Hongbin Ma <mahong...@apache.org> Committed: Tue Sep 20 21:17:12 2016 +0800 ---------------------------------------------------------------------- .../test/resources/query/sql_lookup/query05.sql | 19 +++++++++++++++++++ .../kylin/query/relnode/OLAPAggregateRel.java | 8 ++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/472e6d54/kylin-it/src/test/resources/query/sql_lookup/query05.sql ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_lookup/query05.sql b/kylin-it/src/test/resources/query/sql_lookup/query05.sql new file mode 100644 index 0000000..31fdf61 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_lookup/query05.sql @@ -0,0 +1,19 @@ +-- +-- 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 count(distinct META_CATEG_NAME) as CNT ,max(META_CATEG_NAME) as y from test_category_groupings http://git-wip-us.apache.org/repos/asf/kylin/blob/472e6d54/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java index f55c86f..97efb27 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java @@ -265,7 +265,7 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel { implementor.visitChild(this, getInput()); // only rewrite the innermost aggregation - if (!this.afterAggregate && RewriteImplementor.needRewrite(this.context)) { + if (!this.afterAggregate) { // rewrite the aggCalls this.rewriteAggCalls = new ArrayList<AggregateCall>(aggCalls.size()); for (int i = 0; i < this.aggCalls.size(); i++) { @@ -354,11 +354,15 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel { } } + private boolean noPrecaculatedFieldsAvailable() { + return !this.context.hasPrecalculatedFields() || !RewriteImplementor.needRewrite(this.context); + } + private AggregateCall rewriteAggregateCall(AggregateCall aggCall, FunctionDesc func) { //if it's not a cube, then the "needRewriteField func" should not resort to any rewrite fields, // which do not exist at all - if (!this.context.hasPrecalculatedFields() && func.needRewriteField()) { + if (noPrecaculatedFieldsAvailable() && func.needRewriteField()) { logger.info(func + "skip rewriteAggregateCall because no pre-aggregated field available"); return aggCall; }