From 2fe0036016d94fac799243814b5ab57d1c09e82f Mon Sep 17 00:00:00 2001 From: Zhong Date: Tue, 31 Jul 2018 18:40:52 +0800 Subject: [PATCH] KYLIN-3476 fix TupleExpression verification when parsing sql --- .../org/apache/kylin/query/ITKylinQueryTest.java | 9 ++++- .../resources/query/sql_expression/query06.sql | 43 ++++++++++++++++++++++ .../apache/kylin/query/relnode/OLAPProjectRel.java | 3 +- .../relnode/visitor/TupleExpressionVisitor.java | 8 ++-- 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 kylin-it/src/test/resources/query/sql_expression/query06.sql diff --git a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java index 2d0c7b5..e6afbe0 100644 --- a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java +++ b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java @@ -417,8 +417,13 @@ public class ITKylinQueryTest extends KylinTestBase { @Test public void testExpressionQuery() throws Exception { - if (config.isDynamicColumnEnabled()) { - batchExecuteQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_expression"); + boolean ifDynamicColumnEnabled = config.isDynamicColumnEnabled(); + if (!ifDynamicColumnEnabled) { + config.setProperty("kylin.query.enable-dynamic-column", "true"); + } + batchExecuteQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_expression"); + if (!ifDynamicColumnEnabled) { + config.setProperty("kylin.query.enable-dynamic-column", "false"); } } diff --git a/kylin-it/src/test/resources/query/sql_expression/query06.sql b/kylin-it/src/test/resources/query/sql_expression/query06.sql new file mode 100644 index 0000000..5f8b1d3 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_expression/query06.sql @@ -0,0 +1,43 @@ +-- +-- 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 T1.LSTG_FORMAT_NAME, avg(T1.gmv/T2.gmv) +from +(select LSTG_FORMAT_NAME, SLR_SEGMENT_CD, + sum(0.9*(price+50)) 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 +group by LSTG_FORMAT_NAME, SLR_SEGMENT_CD) T1 +inner join +(select LSTG_FORMAT_NAME, SLR_SEGMENT_CD, + sum(case + when LSTG_FORMAT_NAME = 'ABIN' then 0.8*(price+50) + else price + 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 +group by LSTG_FORMAT_NAME, SLR_SEGMENT_CD) T2 +on T1.LSTG_FORMAT_NAME = T2.LSTG_FORMAT_NAME and T1.SLR_SEGMENT_CD = T2.SLR_SEGMENT_CD +group by T1.LSTG_FORMAT_NAME +order by T1.LSTG_FORMAT_NAME \ No newline at end of file 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 39f4bb0..de4b438 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 @@ -145,7 +145,8 @@ public class OLAPProjectRel extends Project implements OLAPRel { OLAPRel olapChild = (OLAPRel) getInput(); ColumnRowType inputColumnRowType = olapChild.getColumnRowType(); - TupleExpressionVisitor visitor = new TupleExpressionVisitor(inputColumnRowType, afterAggregate); + boolean ifVerify = !hasSubQuery() && !afterAggregate; + TupleExpressionVisitor visitor = new TupleExpressionVisitor(inputColumnRowType, ifVerify); for (int i = 0; i < this.rewriteProjects.size(); i++) { RexNode rex = this.rewriteProjects.get(i); RelDataTypeField columnField = this.rowType.getFieldList().get(i); diff --git a/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java b/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java index 4007754..d0ad23a 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java @@ -50,12 +50,12 @@ import com.google.common.collect.Lists; public class TupleExpressionVisitor extends RexVisitorImpl { final ColumnRowType inputRowType; - final boolean afterAggregate; + final boolean ifVerify; - public TupleExpressionVisitor(ColumnRowType inputRowType, boolean afterAggregate) { + public TupleExpressionVisitor(ColumnRowType inputRowType, boolean ifVerify) { super(true); this.inputRowType = inputRowType; - this.afterAggregate = afterAggregate; + this.ifVerify = ifVerify; } @Override @@ -91,7 +91,7 @@ public class TupleExpressionVisitor extends RexVisitorImpl { default: tupleExpression = getRexCallTupleExpression(call); } - if (!afterAggregate) { + if (ifVerify) { tupleExpression.verify(); } return tupleExpression; -- 2.5.4 (Apple Git-61)