ZijieSong946 commented on a change in pull request #12027:
URL: https://github.com/apache/beam/pull/12027#discussion_r442427555



##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/ZetaSqlCalciteTranslationUtils.java
##########
@@ -43,55 +40,38 @@
 import 
org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.rex.RexBuilder;
 import 
org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.sql.type.SqlTypeName;
 import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
-import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
 
-/** Utility to convert types from Calcite Schema types. */
+/**
+ * Utility methods for ZetaSQL <=> Calcite translation.
+ *
+ * <p>Unsupported ZetaSQL types: INT32, UINT32, UINT64, FLOAT, ENUM, PROTO, 
GEOGRAPHY
+ * TODO[BEAM-10238]: support ZetaSQL types: TIME, DATETIME, NUMERIC
+ */
 @Internal
-public class TypeUtils {
-
-  private static final ImmutableMap<SqlTypeName, Type> 
CALCITE_TO_ZETA_SIMPLE_TYPES =
-      ImmutableMap.<SqlTypeName, Type>builder()
-          .put(SqlTypeName.BIGINT, TypeFactory.createSimpleType(TYPE_INT64))
-          .put(SqlTypeName.INTEGER, TypeFactory.createSimpleType(TYPE_INT32))
-          .put(SqlTypeName.VARCHAR, TypeFactory.createSimpleType(TYPE_STRING))
-          .put(SqlTypeName.BOOLEAN, TypeFactory.createSimpleType(TYPE_BOOL))
-          .put(SqlTypeName.FLOAT, TypeFactory.createSimpleType(TYPE_FLOAT))
-          .put(SqlTypeName.DOUBLE, TypeFactory.createSimpleType(TYPE_DOUBLE))
-          .put(SqlTypeName.VARBINARY, TypeFactory.createSimpleType(TYPE_BYTES))
-          .put(SqlTypeName.TIMESTAMP, 
TypeFactory.createSimpleType(TYPE_TIMESTAMP))
-          .put(SqlTypeName.DATE, TypeFactory.createSimpleType(TYPE_DATE))
-          .put(SqlTypeName.TIME, TypeFactory.createSimpleType(TYPE_TIME))
-          .build();
-
-  private static final ImmutableMap<TypeKind, Function<RexBuilder, 
RelDataType>>
-      ZETA_TO_CALCITE_SIMPLE_TYPES =
-          ImmutableMap.<TypeKind, Function<RexBuilder, RelDataType>>builder()
-              .put(TYPE_NUMERIC, relDataTypeFactory(SqlTypeName.DECIMAL))
-              .put(TYPE_INT32, relDataTypeFactory(SqlTypeName.INTEGER))
-              .put(TYPE_INT64, relDataTypeFactory(SqlTypeName.BIGINT))
-              .put(TYPE_FLOAT, relDataTypeFactory(SqlTypeName.FLOAT))
-              .put(TYPE_DOUBLE, relDataTypeFactory(SqlTypeName.DOUBLE))
-              .put(TYPE_STRING, relDataTypeFactory(SqlTypeName.VARCHAR))
-              .put(TYPE_BOOL, relDataTypeFactory(SqlTypeName.BOOLEAN))
-              .put(TYPE_BYTES, relDataTypeFactory(SqlTypeName.VARBINARY))
-              .put(TYPE_DATE, relDataTypeFactory(SqlTypeName.DATE))
-              .put(TYPE_TIME, relDataTypeFactory(SqlTypeName.TIME))
-              // TODO: handle timestamp with time zone.
-              .put(TYPE_TIMESTAMP, relDataTypeFactory(SqlTypeName.TIMESTAMP))
-              .build();
-
-  /** Returns a type matching the corresponding Calcite type. */
-  static Type toZetaType(RelDataType calciteType) {
-
-    if 
(CALCITE_TO_ZETA_SIMPLE_TYPES.containsKey(calciteType.getSqlTypeName())) {
-      return CALCITE_TO_ZETA_SIMPLE_TYPES.get(calciteType.getSqlTypeName());
-    }
+public class ZetaSqlCalciteTranslationUtils {
 
+  // Type conversion: Calcite => ZetaSQL
+  static Type toZetaType(RelDataType calciteType) {
     switch (calciteType.getSqlTypeName()) {
+      case BIGINT:
+        return TypeFactory.createSimpleType(TYPE_INT64);
+      case DOUBLE:
+        return TypeFactory.createSimpleType(TYPE_DOUBLE);
+      case BOOLEAN:
+        return TypeFactory.createSimpleType(TYPE_BOOL);
+      case VARCHAR:
+        return TypeFactory.createSimpleType(TYPE_STRING);
+      case VARBINARY:
+        return TypeFactory.createSimpleType(TYPE_BYTES);
+      case DATE:
+        return TypeFactory.createSimpleType(TYPE_DATE);
+      case TIME:

Review comment:
       Thanks. I got it.




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


Reply via email to