From 40c98d656f08d403f5b1e2b8f19fe2e09f82979b Mon Sep 17 00:00:00 2001 From: Zhong Date: Wed, 29 Nov 2017 09:30:55 +0800 Subject: [PATCH] APACHE-KYLIN-3031: KeywordDefaultDirtyHack should ignore case of default like other database does --- .../kylin/query/util/KeywordDefaultDirtyHack.java | 3 +- .../query/util/KeywordDefaultDirtyHackTest.java | 60 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 query/src/test/java/org/apache/kylin/query/util/KeywordDefaultDirtyHackTest.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; 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); + } + } +} -- 2.5.4 (Apple Git-61)