KYLIN-2341 support sum(case.. when..) Signed-off-by: Yang Li <liy...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/20578319 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/20578319 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/20578319 Branch: refs/heads/master-hbase0.98 Commit: 20578319e11e504c2ba647a0593dd6eae2d4624b Parents: c85a0e7 Author: etherge <ethe...@163.com> Authored: Sun Feb 19 16:49:08 2017 +0800 Committer: Yang Li <liy...@apache.org> Committed: Mon Apr 3 16:19:46 2017 +0800 ---------------------------------------------------------------------- .../resources/query/sql_casewhen/query04.sql | 30 ++++++++++++++++++++ .../kylin/query/relnode/OLAPAggregateRel.java | 4 +-- .../kylin/query/relnode/OLAPProjectRel.java | 10 +------ 3 files changed, 33 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/20578319/kylin-it/src/test/resources/query/sql_casewhen/query04.sql ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_casewhen/query04.sql b/kylin-it/src/test/resources/query/sql_casewhen/query04.sql new file mode 100644 index 0000000..646da0a --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_casewhen/query04.sql @@ -0,0 +1,30 @@ +-- +-- 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 + SUM(CASE + WHEN lstg_format_name LIKE 'Other%' THEN price + ELSE 0 + END) AS gmv +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 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/20578319/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 d9385e9..c7f66a0 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 @@ -209,12 +209,12 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel { for (int i = 0; i < this.aggregations.size(); i++) { FunctionDesc aggFunc = this.aggregations.get(i); String aggOutName; - if (aggFunc.needRewriteField()) { + if (aggFunc != null && aggFunc.needRewriteField()) { aggOutName = aggFunc.getRewriteFieldName(); } else { AggregateCall aggCall = this.rewriteAggCalls.get(i); int index = aggCall.getArgList().get(0); - aggOutName = aggFunc.getExpression() + "_" + inputColumnRowType.getColumnByIndex(index).getIdentity() + "_"; + aggOutName = getSqlFuncName(aggCall) + "_" + inputColumnRowType.getColumnByIndex(index).getIdentity() + "_"; } TblColRef aggOutCol = TblColRef.newInnerColumn(aggOutName, TblColRef.InnerDataTypeEnum.LITERAL); columns.add(aggOutCol); http://git-wip-us.apache.org/repos/asf/kylin/blob/20578319/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java index 03b9ddd..aa03e3e 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java @@ -37,9 +37,9 @@ import org.apache.calcite.rel.RelNode; import org.apache.calcite.rel.core.Project; import org.apache.calcite.rel.metadata.RelMetadataQuery; import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rel.type.RelDataTypeFieldImpl; -import org.apache.calcite.rel.type.RelDataTypeFactory.FieldInfoBuilder; import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexInputRef; import org.apache.calcite.rex.RexLiteral; @@ -47,7 +47,6 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.rex.RexOver; import org.apache.calcite.rex.RexProgram; import org.apache.calcite.sql.SqlOperator; -import org.apache.calcite.sql.fun.SqlCaseOperator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.validate.SqlUserDefinedFunction; import org.apache.kylin.metadata.model.TblColRef; @@ -200,13 +199,6 @@ public class OLAPProjectRel extends Project implements OLAPRel { if (operator.getName().equals("QUARTER")) { return translateFirstRexInputRef(call, inputColumnRowType, fieldName, sourceCollector); } - } else if (operator instanceof SqlCaseOperator) { - for (RexNode operand : call.getOperands()) { - if (operand instanceof RexInputRef) { - RexInputRef inputRef = (RexInputRef) operand; - return translateRexInputRef(inputRef, inputColumnRowType, fieldName, sourceCollector); - } - } } for (RexNode operand : call.getOperands()) {