[2/2] kylin git commit: KYLIN-2029 distinct count query on lookup table

2016-09-20 Thread mahongbin
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/a98bea49
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/a98bea49
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/a98bea49

Branch: refs/heads/KYLIN-2030-2
Commit: a98bea49e6255dadff6cbed7f6e47aa9187b648f
Parents: 506cd78
Author: Hongbin Ma 
Authored: Tue Sep 20 18:19:19 2016 +0800
Committer: Hongbin Ma 
Committed: Tue Sep 20 18:59:27 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/a98bea49/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 000..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/a98bea49/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(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;
 }



[2/2] kylin git commit: KYLIN-2029 distinct count query on lookup table

2016-09-20 Thread mahongbin
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/d6b96502
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/d6b96502
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/d6b96502

Branch: refs/heads/KYLIN-2030
Commit: d6b9650246af1b2331b694a7becda5f804fe2449
Parents: 5a049a5
Author: Hongbin Ma 
Authored: Tue Sep 20 18:19:19 2016 +0800
Committer: Hongbin Ma 
Committed: Tue Sep 20 18:45:41 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/d6b96502/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 000..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/d6b96502/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(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;
 }