You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2019/09/16 17:44:42 UTC

[calcite] branch master updated (2c19098 -> f3758a6)

This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.


 discard 2c19098  [CALCITE-3282] In JDBC adadpter, when generating SQL for Hive, generate INTEGER type as INT (huangfeng)
     new f3758a6  [CALCITE-3282] In JDBC adapter, when generating SQL for Hive, generate INTEGER type as INT (huangfeng)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (2c19098)
            \
             N -- N -- N   refs/heads/master (f3758a6)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[calcite] 01/01: [CALCITE-3282] In JDBC adapter, when generating SQL for Hive, generate INTEGER type as INT (huangfeng)

Posted by jh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git

commit f3758a6fa301cbd910ceabeca9075a3772ee4e8b
Author: ffmax <–f...@163.com>
AuthorDate: Thu Sep 5 19:51:32 2019 +0800

    [CALCITE-3282] In JDBC adapter, when generating SQL for Hive, generate INTEGER type as INT (huangfeng)
    
    This is necessary because Hive 1.x only supports INT, not INTEGER.
    
    Fix-up (by Danny):
    * Add issue link to the test case;
    * Fix some doc typos.
    
    close apache/calcite#1443
---
 .../main/java/org/apache/calcite/sql/SqlDialect.java   |  2 ++
 .../org/apache/calcite/sql/dialect/HiveSqlDialect.java | 18 ++++++++++++++++++
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java     | 12 ++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
index 8a740a8..7d802b4 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
@@ -749,6 +749,8 @@ public class SqlDialect {
     return true;
   }
 
+ /** Returns SqlNode for type in "cast(column as type)", which might be
+  * different between databases by type name, precision etc. */
   public SqlNode getCastSpec(RelDataType type) {
     if (type instanceof BasicSqlType) {
       int maxPrecision = -1;
diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/HiveSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/HiveSqlDialect.java
index 2525460..afc2290 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/HiveSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/HiveSqlDialect.java
@@ -17,15 +17,21 @@
 package org.apache.calcite.sql.dialect;
 
 import org.apache.calcite.config.NullCollation;
+import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDataTypeSpec;
 import org.apache.calcite.sql.SqlDialect;
+import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlLiteral;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlOperator;
 import org.apache.calcite.sql.SqlSyntax;
+import org.apache.calcite.sql.SqlUserDefinedTypeNameSpec;
 import org.apache.calcite.sql.SqlWriter;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.sql.fun.SqlTrimFunction;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.BasicSqlType;
 
 /**
  * A <code>SqlDialect</code> implementation for the Apache Hive database.
@@ -120,6 +126,18 @@ public class HiveSqlDialect extends SqlDialect {
   @Override public boolean supportsCharSet() {
     return false;
   }
+
+  @Override public SqlNode getCastSpec(final RelDataType type) {
+    if (type instanceof BasicSqlType) {
+      switch (type.getSqlTypeName()) {
+      case INTEGER:
+        SqlUserDefinedTypeNameSpec typeNameSpec = new SqlUserDefinedTypeNameSpec(
+            new SqlIdentifier("INT", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      }
+    }
+    return super.getCastSpec(type);
+  }
 }
 
 // End HiveSqlDialect.java
diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 7f9fc34..8d67024 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -804,6 +804,18 @@ public class RelToSqlConverterTest {
   }
 
   /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-3282">[CALCITE-3282]
+   * HiveSqlDialect unparse Interger type as Int in order
+   * to be compatible with Hive1.x</a>. */
+  @Test public void testHiveCastAsInt() {
+    String query = "select cast( cast(\"employee_id\" as varchar) as int) "
+        + "from \"foodmart\".\"reserve_employee\" ";
+    final String expected = "SELECT CAST(CAST(employee_id AS VARCHAR) AS INT)\n"
+        + "FROM foodmart.reserve_employee";
+    sql(query).withHive().ok(expected);
+  }
+
+  /** Test case for
    * <a href="https://issues.apache.org/jira/browse/CALCITE-3220">[CALCITE-3220]
    * HiveSqlDialect should transform the SQL-standard TRIM function to TRIM,
    * LTRIM or RTRIM</a>. */