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_r330785314
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
 ##########
 @@ -132,6 +138,43 @@ 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:
+        return createSqlDataTypeSpecByName("INT64");
+      case DOUBLE:
+        return createSqlDataTypeSpecByName("FLOAT64");
+      case DECIMAL:
+        return createSqlDataTypeSpecByName("NUMERIC");
+      case BOOLEAN:
+        return createSqlDataTypeSpecByName("BOOL");
+      case VARCHAR:
+        return createSqlDataTypeSpecByName("STRING");
+      case VARBINARY:
+        return createSqlDataTypeSpecByName("BYTES");
+      case DATE:
+        return createSqlDataTypeSpecByName("DATE");
+      case TIME:
+        return createSqlDataTypeSpecByName("TIME");
+      case TIMESTAMP:
+        return createSqlDataTypeSpecByName("TIMESTAMP");
+      }
+    }
+    return super.getCastSpec(type);
+  }
+
+  private static SqlDataTypeSpec createSqlDataTypeSpecByName(String 
identifierName) {
 
 Review comment:
   Make it as non-static. thanks for the example of Calcite practice.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to