kylin-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KYLIN-3475) Make calcite case handling and quoting method more configurable.
Date Thu, 02 Aug 2018 03:39:00 GMT

    [ https://issues.apache.org/jira/browse/KYLIN-3475?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16566309#comment-16566309
] 

ASF GitHub Bot commented on KYLIN-3475:
---------------------------------------

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


> Make calcite case handling and quoting method more configurable.
> ----------------------------------------------------------------
>
>                 Key: KYLIN-3475
>                 URL: https://issues.apache.org/jira/browse/KYLIN-3475
>             Project: Kylin
>          Issue Type: Improvement
>          Components: Query Engine
>            Reporter: Ian Hu
>            Assignee: Ian Hu
>            Priority: Major
>             Fix For: v2.5.0
>
>
> >> Do you know whether Calcite supports that? If Calcite already supports it with
some parameter, Kylin can expose that as a configuration. Yes, Calcite support to customize
some sql handle feature by connection properties. We can customize it by provide an Properties
when use jdbc's DriverManager.getConnection(url, extraProperties). Here is my commit (with
UT) to achieve this [https://github.com/ian4hu/kylin/commit/88ee638fb4c8b55b089294107ad361ec3fc6dae9]  For
short lookup see QueryConnection.getConnection(project)@ [https://github.com/apache/kylin/blob/25b300c1f654561e561565ebf35c4e0e93ae0a04/query/src/main/java/org/apache/kylin/query/QueryConnection.java#L51]  the
key is the info variable.
>  
> Background (from mailing list [http://mail-archives.apache.org/mod_mbox/kylin-dev//201807.mbox/%3C4247fe2a.634d.164e995a707.Coremail.hu2008yinxiang%40163.com%3E] ):
> We use kylin in our BI system as a sub-query engine. we met some problems in our use
case like bellow.
>  # Our visual design tool use source table schema as metadata, and the source table column
is lower case or mixed case, and visual tool generate SQL for kylin query.
>  # Kylin execute sql and return result
>  # we use a parser to parse result and assembly it to entities (like ORM engine did)
> but the problem is that kylin now always casting the column to UPPER case, that break
our parser and whe can not change that behavior by configure kylin. like "select 1 as value_ALIAS"
we always get the column named "VALUE_ALIAS" instead of "value_ALIAS" from Kylin.
>  
> although we can use 'select 1 as "value_ALIAS"' (with double-qouted alias) and it will
be better if we can configure the quoting method.
>  
> I would like contribute features to make the query engine is more flexible
>  # First of all, make the case handling and quoting method is configurable by kylin.properties,
that a global configuration.
>  # Second make case handling and quoting method available by JDBC connection url parameters
or connection properties by DriverManager.getConnection(url-with-parameters, extra-properties)
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message