[ 
https://issues.apache.org/jira/browse/BEAM-9179?focusedWorklogId=447974&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-447974
 ]

ASF GitHub Bot logged work on BEAM-9179:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Jun/20 18:30
            Start Date: 18/Jun/20 18:30
    Worklog Time Spent: 10m 
      Work Description: ZijieSong946 commented on a change in pull request 
#12027:
URL: https://github.com/apache/beam/pull/12027#discussion_r442422797



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

Review comment:
       Done. Thanks for the suggestion.




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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 447974)
    Time Spent: 2h 40m  (was: 2.5h)

> Refactor Beam ZetaSQL type translation code
> -------------------------------------------
>
>                 Key: BEAM-9179
>                 URL: https://issues.apache.org/jira/browse/BEAM-9179
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql-zetasql
>            Reporter: Robin Qiu
>            Assignee: Zijie Song
>            Priority: P2
>          Time Spent: 2h 40m
>  Remaining Estimate: 0h
>
> Currently, how types work in Beam ZetaSQL is very confusing: code that does 
> type conversion between Calcite/Beam/ZetaSQL type systems are everywhere and 
> is likely to be not consistent. In addition, the recent migration to 
> BeamZetaSqlCalcRel makes the situation even worse: it adds another layer for 
> type conversion and makes a lot of code (for making ZetaSQL functions 
> manually) obsolete. This makes debugging and supporting new features very 
> hard. A few examples:
>  * Support new ZetaSQL types (e.g. DATE/TIME/DATETIME)
>  * Fix the long-standing precision & timezone issue of TIMESTMAP type
>  * Support BeamSQL query parameters
> Therefore, I propose we work on the following items to make the story of Beam 
> ZetaSQL type clearer:
>  * Define a clear mapping between Calcite/Beam/ZetaSQL types and values
>  * Refactor the codebase to move all type conversion code to a single source 
> of truth
>  * Add thorough testing for it
>  * Remove obsolete code that is added to make functions work before 
> BeamZetaSqlCalcRel



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to