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 19:44:28 UTC

[GitHub] [calcite] julianhyde 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

julianhyde 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_r330736412
 
 

 ##########
 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:
   Consider adding a helper method to reduce each of those 3 line blocks to a single line. Otherwise, looks good.

----------------------------------------------------------------
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