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/11/26 06:13:43 UTC

kylin git commit: KYLIN-2966 add pushdown jdbc columntype mapping [Forced Update!]

Repository: kylin
Updated Branches:
  refs/heads/KYLIN-2966 0b6b0625d -> 85d7e6260 (forced update)


KYLIN-2966 add pushdown jdbc columntype mapping

This closes #82

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/85d7e626
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/85d7e626
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/85d7e626

Branch: refs/heads/KYLIN-2966
Commit: 85d7e6260e61ab004186bdd26cfb9543ed3b795d
Parents: d837e18
Author: zhaiyuyong <zh...@126.com>
Authored: Wed Oct 25 17:06:04 2017 +0800
Committer: Li Yang <li...@apache.org>
Committed: Sun Nov 26 14:12:59 2017 +0800

----------------------------------------------------------------------
 .../query/adhoc/PushDownRunnerJdbcImpl.java     | 45 +++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/85d7e626/query/src/main/java/org/apache/kylin/query/adhoc/PushDownRunnerJdbcImpl.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/adhoc/PushDownRunnerJdbcImpl.java b/query/src/main/java/org/apache/kylin/query/adhoc/PushDownRunnerJdbcImpl.java
index 503e273..7283d66 100644
--- a/query/src/main/java/org/apache/kylin/query/adhoc/PushDownRunnerJdbcImpl.java
+++ b/query/src/main/java/org/apache/kylin/query/adhoc/PushDownRunnerJdbcImpl.java
@@ -23,6 +23,7 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Types;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -66,7 +67,7 @@ public class PushDownRunnerJdbcImpl implements IPushDownRunner {
                 columnMetas.add(new SelectedColumnMeta(metaData.isAutoIncrement(i), metaData.isCaseSensitive(i), false,
                         metaData.isCurrency(i), metaData.isNullable(i), false, metaData.getColumnDisplaySize(i),
                         metaData.getColumnLabel(i), metaData.getColumnName(i), null, null, null,
-                        metaData.getPrecision(i), metaData.getScale(i), metaData.getColumnType(i),
+                        metaData.getPrecision(i), metaData.getScale(i), toSqlType(metaData.getColumnTypeName(i)),
                         metaData.getColumnTypeName(i), metaData.isReadOnly(i), false, false));
             }
         } finally {
@@ -76,6 +77,48 @@ public class PushDownRunnerJdbcImpl implements IPushDownRunner {
         }
     }
 
+    // calcite does not understand all java SqlTypes, for example LONGNVARCHAR -16, thus need this mapping (KYLIN-2966)
+    public static int toSqlType(String type) throws SQLException {
+        if ("string".equalsIgnoreCase(type)) {
+            return Types.VARCHAR;
+        } else if ("varchar".equalsIgnoreCase(type)) {
+            return Types.VARCHAR;
+        } else if ("char".equalsIgnoreCase(type)) {
+            return Types.CHAR;
+        } else if ("float".equalsIgnoreCase(type)) {
+            return Types.FLOAT;
+        } else if ("real".equalsIgnoreCase(type)) {
+            return Types.REAL;
+        } else if ("double".equalsIgnoreCase(type)) {
+            return Types.DOUBLE;
+        } else if ("boolean".equalsIgnoreCase(type)) {
+            return Types.BOOLEAN;
+        } else if ("tinyint".equalsIgnoreCase(type)) {
+            return Types.TINYINT;
+        } else if ("smallint".equalsIgnoreCase(type)) {
+            return Types.SMALLINT;
+        } else if ("int".equalsIgnoreCase(type)) {
+            return Types.INTEGER;
+        } else if ("bigint".equalsIgnoreCase(type)) {
+            return Types.BIGINT;
+        } else if ("date".equalsIgnoreCase(type)) {
+            return Types.DATE;
+        } else if ("timestamp".equalsIgnoreCase(type)) {
+            return Types.TIMESTAMP;
+        } else if ("decimal".equalsIgnoreCase(type)) {
+            return Types.DECIMAL;
+        } else if ("binary".equalsIgnoreCase(type)) {
+            return Types.BINARY;
+        } else if ("map".equalsIgnoreCase(type)) {
+            return Types.JAVA_OBJECT;
+        } else if ("array".equalsIgnoreCase(type)) {
+            return Types.ARRAY;
+        } else if ("struct".equalsIgnoreCase(type)) {
+            return Types.STRUCT;
+        }
+        throw new SQLException("Unrecognized column type: " + type);
+    }
+
     @Override
     public void executeUpdate(String sql) throws Exception {
         Statement statement = null;