From 8539d5e577b0d5f03fd2773c69e39487946546c2 Mon Sep 17 00:00:00 2001 From: Zhong Date: Fri, 3 Aug 2018 11:10:02 +0800 Subject: [PATCH] KYLIN-3480 change the sql conformance of calcite from default to lenient to enable groupby & orderby ordinal --- .../src/main/resources/kylin-defaults.properties | 3 ++ .../org/apache/kylin/common/KylinConfigTest.java | 3 ++ .../org/apache/kylin/query/ITKylinQueryTest.java | 12 ++++++++ .../test/resources/query/sql_ordinal/query01.sql | 32 ++++++++++++++++++++++ .../test/resources/query/sql_ordinal/query02.sql | 27 ++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 kylin-it/src/test/resources/query/sql_ordinal/query01.sql create mode 100644 kylin-it/src/test/resources/query/sql_ordinal/query02.sql diff --git a/core-common/src/main/resources/kylin-defaults.properties b/core-common/src/main/resources/kylin-defaults.properties index 23c0730..913945f 100644 --- a/core-common/src/main/resources/kylin-defaults.properties +++ b/core-common/src/main/resources/kylin-defaults.properties @@ -236,6 +236,9 @@ kylin.query.calcite.extras-props.unquotedCasing=TO_UPPER # quoting method, default: DOUBLE_QUOTE, available options: DOUBLE_QUOTE, BACK_TICK, BRACKET # @see org.apache.calcite.config.CalciteConnectionProperty.QUOTING kylin.query.calcite.extras-props.quoting=DOUBLE_QUOTE +# change SqlConformance from DEFAULT to LENIENT to enable group by ordinal +# @see org.apache.calcite.sql.validate.SqlConformance.SqlConformanceEnum +kylin.query.calcite.extras-props.conformance=LENIENT # TABLE ACL kylin.query.security.table-acl-enabled=true diff --git a/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java b/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java index c9939e7..fec3de5 100644 --- a/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java +++ b/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java @@ -154,13 +154,16 @@ public class KylinConfigTest extends HotLoadKylinPropertiesTestCase { assertEquals("true", extras.getProperty("caseSensitive")); assertEquals("TO_UPPER", extras.getProperty("unquotedCasing")); assertEquals("DOUBLE_QUOTE", extras.getProperty("quoting")); + assertEquals("LENIENT", extras.getProperty("conformance")); conf.setProperty("kylin.query.calcite.extras-props.caseSensitive", "false"); conf.setProperty("kylin.query.calcite.extras-props.unquotedCasing", "UNCHANGED"); conf.setProperty("kylin.query.calcite.extras-props.quoting", "BRACKET"); + conf.setProperty("kylin.query.calcite.extras-props.conformance", "DEFAULT"); extras = conf.getCalciteExtrasProperties(); assertEquals("false", extras.getProperty("caseSensitive")); assertEquals("UNCHANGED", extras.getProperty("unquotedCasing")); assertEquals("BRACKET", extras.getProperty("quoting")); + assertEquals("DEFAULT", extras.getProperty("conformance")); } } 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..1d94bc0 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 @@ -423,6 +423,18 @@ public class ITKylinQueryTest extends KylinTestBase { } @Test + public void testOrdinalQuery() throws Exception { + String sqlConformance = config.getCalciteExtrasProperties().getProperty("conformance"); + if (!"LENIENT".equalsIgnoreCase(sqlConformance)) { + config.setProperty("kylin.query.calcite.extras-props.conformance", "LENIENT"); + } + batchExecuteQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_ordinal"); + if (!"LENIENT".equalsIgnoreCase(sqlConformance)) { + config.setProperty("kylin.query.calcite.extras-props.conformance", sqlConformance); + } + } + + @Test public void testValues() throws Exception { execAndCompQuery(getQueryFolderPrefix() + "src/test/resources/query/sql_values", null, true); } diff --git a/kylin-it/src/test/resources/query/sql_ordinal/query01.sql b/kylin-it/src/test/resources/query/sql_ordinal/query01.sql new file mode 100644 index 0000000..08856b7 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_ordinal/query01.sql @@ -0,0 +1,32 @@ +-- +-- 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 LSTG_FORMAT_NAME, (case + when USER_DEFINED_FIELD1 < 0 then 0 + when USER_DEFINED_FIELD1 < 10 then 1 + else 3 + end), + sum(price) +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 +WHERE SLR_SEGMENT_CD < 16 and USER_DEFINED_FIELD1 is not null +group by 1, 2 +order by 1, 2 \ No newline at end of file diff --git a/kylin-it/src/test/resources/query/sql_ordinal/query02.sql b/kylin-it/src/test/resources/query/sql_ordinal/query02.sql new file mode 100644 index 0000000..be55ca4 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_ordinal/query02.sql @@ -0,0 +1,27 @@ +-- +-- 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 "TEST_KYLIN_FACT"."CAL_DT", SUM("TEST_KYLIN_FACT"."PRICE") AS "sum_PRICE_ok" FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT" + RIGHT JOIN ( + SELECT COUNT(1) AS "XTableau_join_flag", SUM("TEST_KYLIN_FACT"."PRICE") AS "X__alias__A", "TEST_KYLIN_FACT"."CAL_DT" AS "none_CAL_DT_ok" FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT" + GROUP BY 3 ORDER BY 2 DESC LIMIT 7 ) + "t0" ON + CASE WHEN 1 = 1 + THEN ("TEST_KYLIN_FACT"."CAL_DT" = "t0"."none_CAL_DT_ok") + ELSE "TEST_KYLIN_FACT"."CAL_DT" = "t0"."none_CAL_DT_ok" + END + GROUP BY 1 -- 2.5.4 (Apple Git-61)