You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by lu...@apache.org on 2015/09/06 09:59:27 UTC
[03/50] [abbrv] incubator-kylin git commit: KYLIN-985 Fix support of
AVG()
KYLIN-985 Fix support of AVG()
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/3fffb740
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/3fffb740
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/3fffb740
Branch: refs/heads/0.7
Commit: 3fffb7405ba96621a56e6184013f7ae1c41686c9
Parents: d2cffa2
Author: Yang Li <li...@apache.org>
Authored: Fri Sep 4 20:39:56 2015 +0800
Committer: Yang Li <li...@apache.org>
Committed: Fri Sep 4 20:39:56 2015 +0800
----------------------------------------------------------------------
.../kylin/query/optrule/OLAPAggregateRule.java | 19 ++++++++++++++++
.../resources/query/sql_tableau/query28.sql | 23 ++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3fffb740/query/src/main/java/org/apache/kylin/query/optrule/OLAPAggregateRule.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/optrule/OLAPAggregateRule.java b/query/src/main/java/org/apache/kylin/query/optrule/OLAPAggregateRule.java
index 1b74040..aaedab4 100644
--- a/query/src/main/java/org/apache/kylin/query/optrule/OLAPAggregateRule.java
+++ b/query/src/main/java/org/apache/kylin/query/optrule/OLAPAggregateRule.java
@@ -23,7 +23,10 @@ import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.InvalidRelException;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterRule;
+import org.apache.calcite.rel.core.AggregateCall;
import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.sql.SqlAggFunction;
+import org.apache.calcite.sql.fun.SqlAvgAggFunction;
import org.apache.kylin.query.relnode.OLAPAggregateRel;
import org.apache.kylin.query.relnode.OLAPRel;
@@ -40,6 +43,13 @@ public class OLAPAggregateRule extends ConverterRule {
@Override
public RelNode convert(RelNode rel) {
LogicalAggregate agg = (LogicalAggregate) rel;
+
+ // AVG() will be transformed into SUM()/COUNT() by AggregateReduceFunctionsRule.
+ // Here only let the transformed plan pass.
+ if (containsAvg(agg)) {
+ return null;
+ }
+
RelTraitSet traitSet = agg.getTraitSet().replace(OLAPRel.CONVENTION);
try {
return new OLAPAggregateRel(agg.getCluster(), traitSet, convert(agg.getInput(), traitSet), agg.getGroupSet(), agg.getAggCallList());
@@ -48,4 +58,13 @@ public class OLAPAggregateRule extends ConverterRule {
}
}
+ private boolean containsAvg(LogicalAggregate agg) {
+ for (AggregateCall call : agg.getAggCallList()) {
+ SqlAggFunction func = call.getAggregation();
+ if (func instanceof SqlAvgAggFunction)
+ return true;
+ }
+ return false;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3fffb740/query/src/test/resources/query/sql_tableau/query28.sql
----------------------------------------------------------------------
diff --git a/query/src/test/resources/query/sql_tableau/query28.sql b/query/src/test/resources/query/sql_tableau/query28.sql
new file mode 100644
index 0000000..48cc342
--- /dev/null
+++ b/query/src/test/resources/query/sql_tableau/query28.sql
@@ -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.
+--
+
+-- This query don't result exact same average number as H2 DB
+
+select lstg_format_name, avg(price) as GMV
+ from test_kylin_fact
+ group by lstg_format_name