You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kylin.apache.org by GitBox <gi...@apache.org> on 2018/08/02 03:38:40 UTC

[GitHub] shaofengshi closed pull request #180: KYLIN-3475 Make calcite connection is more configurable

shaofengshi closed pull request #180: KYLIN-3475 Make calcite connection is more configurable
URL: https://github.com/apache/kylin/pull/180
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
index b2331e1627..4683ce05fe 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
@@ -1236,6 +1236,16 @@ public boolean isConvertCreateTableToWith() {
         return Boolean.valueOf(getOptional("kylin.query.convert-create-table-to-with", "false"));
     }
 
+    /**
+     * Extras calcite properties to config Calcite connection
+     */
+    public Properties getCalciteExtrasProperties() {
+        Properties properties = new Properties();
+        Map<String, String> map = getPropertiesByPrefix("kylin.query.calcite.extras-props.");
+        properties.putAll(map);
+        return properties;
+    }
+
     /**
      * Rule is usually singleton as static field, the configuration of this property is like:
      * RuleClassName1#FieldName1,RuleClassName2#FieldName2,...
diff --git a/core-common/src/main/resources/kylin-defaults.properties b/core-common/src/main/resources/kylin-defaults.properties
index c01d3a8236..23c0730afa 100644
--- a/core-common/src/main/resources/kylin-defaults.properties
+++ b/core-common/src/main/resources/kylin-defaults.properties
@@ -225,6 +225,18 @@ kylin.query.max-scan-bytes=0
 
 kylin.query.cache-enabled=true
 
+# Controls extras properties for Calcite jdbc driver
+# all extras properties should undder prefix "kylin.query.calcite.extras-props."
+# case sensitive, default: true, to enable case insensitive set it to false
+# @see org.apache.calcite.config.CalciteConnectionProperty.CASE_SENSITIVE
+kylin.query.calcite.extras-props.caseSensitive=true
+# how to handle unquoted identity, defualt: TO_UPPER, available options: UNCHANGED, TO_UPPER, TO_LOWER
+# @see org.apache.calcite.config.CalciteConnectionProperty.UNQUOTED_CASING
+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
+
 # 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 811c574c3a..c9939e7fae 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
@@ -146,4 +146,21 @@ public void testUnexpectedBlackInPro() {
         String s = override.get("test2");
         assertEquals("test2", s);
     }
+
+    @Test
+    public void testCalciteExtrasProperties() {
+        KylinConfig conf = KylinConfig.getInstanceFromEnv();
+        Properties extras = conf.getCalciteExtrasProperties();
+        assertEquals("true", extras.getProperty("caseSensitive"));
+        assertEquals("TO_UPPER", extras.getProperty("unquotedCasing"));
+        assertEquals("DOUBLE_QUOTE", extras.getProperty("quoting"));
+
+        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");
+        extras = conf.getCalciteExtrasProperties();
+        assertEquals("false", extras.getProperty("caseSensitive"));
+        assertEquals("UNCHANGED", extras.getProperty("unquotedCasing"));
+        assertEquals("BRACKET", extras.getProperty("quoting"));
+    }
 }
diff --git a/query/src/main/java/org/apache/kylin/query/QueryConnection.java b/query/src/main/java/org/apache/kylin/query/QueryConnection.java
index ed9065447a..b2db178c55 100644
--- a/query/src/main/java/org/apache/kylin/query/QueryConnection.java
+++ b/query/src/main/java/org/apache/kylin/query/QueryConnection.java
@@ -46,6 +46,7 @@ public static Connection getConnection(String project) throws SQLException {
         }
         File olapTmp = OLAPSchemaFactory.createTempOLAPJson(project, KylinConfig.getInstanceFromEnv());
         Properties info = new Properties();
+        info.putAll(KylinConfig.getInstanceFromEnv().getCalciteExtrasProperties());
         info.put("model", olapTmp.getAbsolutePath());
         info.put("typeSystem", "org.apache.kylin.query.calcite.KylinRelDataTypeSystem");
         return DriverManager.getConnection("jdbc:calcite:", info);
diff --git a/query/src/test/java/org/apache/kylin/query/QueryConnectionTest.java b/query/src/test/java/org/apache/kylin/query/QueryConnectionTest.java
new file mode 100644
index 0000000000..e0bdf223c8
--- /dev/null
+++ b/query/src/test/java/org/apache/kylin/query/QueryConnectionTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+
+import org.apache.calcite.avatica.InternalProperty;
+import org.apache.calcite.avatica.util.Casing;
+import org.apache.calcite.avatica.util.Quoting;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.kylin.common.HotLoadKylinPropertiesTestCase;
+import org.apache.kylin.common.KylinConfig;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class QueryConnectionTest extends HotLoadKylinPropertiesTestCase {
+
+    private static final String SQL_WITH_MIXED_CASE = "select 1 as value_ALIAS";
+
+    @Test
+    public void testGetConnection() throws SQLException, IllegalAccessException {
+        Connection connection = QueryConnection.getConnection("default");
+        assertNotNull(connection);
+        Map<InternalProperty, Object> properties = dirtyReadProperties(connection);
+        assertEquals(true, properties.get(InternalProperty.CASE_SENSITIVE));
+        assertEquals(Casing.TO_UPPER, properties.get(InternalProperty.UNQUOTED_CASING));
+        assertEquals(Quoting.DOUBLE_QUOTE, properties.get(InternalProperty.QUOTING));
+
+        ResultSet resultSet = connection.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery();
+        String columnName = resultSet.getMetaData().getColumnName(1);
+        assertEquals("VALUE_ALIAS", columnName);
+
+        // override connection properties
+        KylinConfig conf = KylinConfig.getInstanceFromEnv();
+        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");
+        Connection conn2 = QueryConnection.getConnection("default");
+        Map<InternalProperty, Object> props = dirtyReadProperties(conn2);
+        assertEquals(false, props.get(InternalProperty.CASE_SENSITIVE));
+        assertEquals(Casing.UNCHANGED, props.get(InternalProperty.UNQUOTED_CASING));
+        assertEquals(Quoting.BRACKET, props.get(InternalProperty.QUOTING));
+
+        ResultSet resultSet1 = conn2.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery();
+        assertEquals("value_ALIAS", resultSet1.getMetaData().getColumnName(1));
+    }
+
+    @SuppressWarnings("unchecked")
+    private static Map<InternalProperty, Object> dirtyReadProperties(Connection connection) throws IllegalAccessException {
+        assertTrue(connection instanceof CalciteConnection);
+        return (Map<InternalProperty, Object>) FieldUtils.readField(connection, "properties");
+
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services