You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/12/01 06:37:50 UTC
kylin git commit: KYLIN-3031 KeywordDefaultDirtyHack should ignore
case of default like other database does
Repository: kylin
Updated Branches:
refs/heads/master 81ba38bd5 -> a94b4796a
KYLIN-3031 KeywordDefaultDirtyHack should ignore case of default like other database does
Signed-off-by: Li Yang <li...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/a94b4796
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/a94b4796
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/a94b4796
Branch: refs/heads/master
Commit: a94b4796a6c4732af7b138e46f844d89bcdac8d9
Parents: 81ba38b
Author: Zhong <nj...@apache.org>
Authored: Wed Nov 29 09:30:55 2017 +0800
Committer: Li Yang <li...@apache.org>
Committed: Fri Dec 1 14:37:41 2017 +0800
----------------------------------------------------------------------
.../query/util/KeywordDefaultDirtyHack.java | 3 +-
.../query/util/KeywordDefaultDirtyHackTest.java | 60 ++++++++++++++++++++
2 files changed, 61 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/a94b4796/query/src/main/java/org/apache/kylin/query/util/KeywordDefaultDirtyHack.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/util/KeywordDefaultDirtyHack.java b/query/src/main/java/org/apache/kylin/query/util/KeywordDefaultDirtyHack.java
index 253660b..939f5bc 100644
--- a/query/src/main/java/org/apache/kylin/query/util/KeywordDefaultDirtyHack.java
+++ b/query/src/main/java/org/apache/kylin/query/util/KeywordDefaultDirtyHack.java
@@ -28,8 +28,7 @@ public class KeywordDefaultDirtyHack implements QueryUtil.IQueryTransformer {
return sql;
}
// KYLIN-2108, DEFAULT is hive default database, but a sql keyword too, needs quote
- sql = sql.replace("DEFAULT.", "\"DEFAULT\".");
- sql = sql.replace("default.", "\"default\".");
+ sql = sql.replaceAll("(?i)default\\.", "\"DEFAULT\".");
sql = sql.replace("defaultCatalog.", "");
return sql;
http://git-wip-us.apache.org/repos/asf/kylin/blob/a94b4796/query/src/test/java/org/apache/kylin/query/util/KeywordDefaultDirtyHackTest.java
----------------------------------------------------------------------
diff --git a/query/src/test/java/org/apache/kylin/query/util/KeywordDefaultDirtyHackTest.java b/query/src/test/java/org/apache/kylin/query/util/KeywordDefaultDirtyHackTest.java
new file mode 100644
index 0000000..afd775d
--- /dev/null
+++ b/query/src/test/java/org/apache/kylin/query/util/KeywordDefaultDirtyHackTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+*/
+
+package org.apache.kylin.query.util;
+
+import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class KeywordDefaultDirtyHackTest extends LocalFileMetadataTestCase {
+ private KeywordDefaultDirtyHack kwDefaultHack = new KeywordDefaultDirtyHack();
+
+ @Before
+ public void setUp() throws Exception {
+ this.createTestMetadata();
+ KylinConfig.getInstanceFromEnv().setProperty("kylin.query.escape-default-keyword", "true");
+ }
+
+ @After
+ public void after() throws Exception {
+ this.cleanupTestMetadata();
+ }
+
+ @Test
+ public void testTransform() {
+ {
+ String sql = "select count(*) from default.test_kylin_fact";
+ String s = kwDefaultHack.transform(sql, null, "DEFAULT");
+ Assert.assertEquals("select count(*) from \"DEFAULT\".test_kylin_fact", s);
+ }
+ {
+ String sql = "select count(*) from DEFAULT.test_kylin_fact";
+ String s = kwDefaultHack.transform(sql, null, "DEFAULT");
+ Assert.assertEquals("select count(*) from \"DEFAULT\".test_kylin_fact", s);
+ }
+ {
+ String sql = "select count(*) from defaulT.test_kylin_fact";
+ String s = kwDefaultHack.transform(sql, null, "DEFAULT");
+ Assert.assertEquals("select count(*) from \"DEFAULT\".test_kylin_fact", s);
+ }
+ }
+}