robinyqiu commented on a change in pull request #12027:
URL: https://github.com/apache/beam/pull/12027#discussion_r442354625
##########
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:
Could you mark this utility class as `final` and add a private
constructor, like `ZetaSqlBeamTranslationUtils.java`?
##########
File path:
sdks/java/extensions/sql/zetasql/src/test/java/org/apache/beam/sdk/extensions/sql/zetasql/ZetaSQLPushDownTest.java
##########
@@ -195,7 +195,8 @@ private static void
initializeCalciteEnvironmentWithContext(Context... extraCont
private static void initializeBeamTableProvider() {
Table projectTable = getTable("InMemoryTableProject",
PushDownOptions.PROJECT);
Table bothTable = getTable("InMemoryTableBoth", PushDownOptions.BOTH);
- Row[] rows = {row(BASIC_SCHEMA, 100, 1, "one", 100), row(BASIC_SCHEMA,
200, 2, "two", 200)};
+ Row[] rows = {row(BASIC_SCHEMA, (long) 100, (long) 1, "one", (long) 100),
Review comment:
You can write `100L` to create a java `Long` literal.
##########
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:
We don't have TIME support at this point. Can we get this entry removed?
(Also, just curious can the MAP entry below be removed as well? Not sure if
any code is using that.)
----------------------------------------------------------------
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]