You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2018/08/06 13:46:12 UTC
[kylin] 01/01: KYLIN-3476 fix TupleExpression verification when
parsing sql
This is an automated email from the ASF dual-hosted git repository.
shaofengshi pushed a commit to branch KYLIN-3476
in repository https://gitbox.apache.org/repos/asf/kylin.git
commit b938a1c53e5b5e894b9ca0cd6c6b3b757bdeca6a
Author: Zhong <nj...@apache.org>
AuthorDate: Tue Jul 31 18:40:52 2018 +0800
KYLIN-3476 fix TupleExpression verification when parsing sql
Signed-off-by: shaofengshi <sh...@apache.org>
---
.../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(-)
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<TupleExpression> {
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<TupleExpression> {
default:
tupleExpression = getRexCallTupleExpression(call);
}
- if (!afterAggregate) {
+ if (ifVerify) {
tupleExpression.verify();
}
return tupleExpression;