You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/10/02 20:36:18 UTC

[GitHub] [calcite] amaliujia commented on a change in pull request #1482: [CALCITE-3381] When converting rel to bigquery sql dialect, types should be converted to BigQuery's data types

amaliujia commented on a change in pull request #1482: [CALCITE-3381] When converting rel to bigquery sql dialect, types should be converted to BigQuery's data types
URL: https://github.com/apache/calcite/pull/1482#discussion_r330758625
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
 ##########
 @@ -132,6 +138,55 @@ public BigQuerySqlDialect(SqlDialect.Context context) {
     }
   }
 
+  /** BigQuery data type reference:
+   * <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types">
+   * Bigquery Standard SQL Data Types</a>
+   */
+  @Override public SqlNode getCastSpec(final RelDataType type) {
+    if (type instanceof BasicSqlType) {
+      SqlUserDefinedTypeNameSpec typeNameSpec;
+      switch (type.getSqlTypeName()) {
+      case BIGINT:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("INT64", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case DOUBLE:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("FLOAT64", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case DECIMAL:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("NUMERIC", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case BOOLEAN:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("BOOL", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case VARCHAR:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("STRING", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case VARBINARY:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("BYTES", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case DATE:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("DATE", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case TIME:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("TIME", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      case TIMESTAMP:
+        typeNameSpec = new SqlUserDefinedTypeNameSpec(
+                new SqlIdentifier("TIMESTAMP", SqlParserPos.ZERO), SqlParserPos.ZERO);
+        return new SqlDataTypeSpec(typeNameSpec, SqlParserPos.ZERO);
+      }
+    }
+    return super.getCastSpec(type);
+  }
+
 
 Review comment:
   Good idea. Done.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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