You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "twalthr (via GitHub)" <gi...@apache.org> on 2023/03/22 13:55:03 UTC

[GitHub] [flink] twalthr commented on a diff in pull request #19637: [FLINK-25567][table] Add support casting of multisets to multisets

twalthr commented on code in PR #19637:
URL: https://github.com/apache/flink/pull/19637#discussion_r1144847060


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/utils/ValuesOperationFactory.java:
##########
@@ -197,10 +199,18 @@ private Optional<ResolvedExpression> convertToExpectedType(
                     && targetLogicalType.is(ARRAY)) {
                 return convertArrayToExpectedType(
                         sourceExpression, (CollectionDataType) targetDataType, postResolverFactory);
-            } else if (functionDefinition == BuiltInFunctionDefinitions.MAP
-                    && targetLogicalType.is(MAP)) {
-                return convertMapToExpectedType(
-                        sourceExpression, (KeyValueDataType) targetDataType, postResolverFactory);
+            } else if (functionDefinition == BuiltInFunctionDefinitions.MAP) {
+                if (targetLogicalType.is(MAP)) {

Review Comment:
   This piece of code confuses me. Why is the function `MAP` but the target type MULTISET? On an API level those two data types should be treated completely different.



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -1693,6 +1693,14 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
                     .outputTypeStrategy(SpecificTypeStrategies.MAP)
                     .build();
 
+    public static final BuiltInFunctionDefinition MULTISET =
+            BuiltInFunctionDefinition.newBuilder()
+                    .name("multiset")

Review Comment:
   nit: let's use upper case for all new functions



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala:
##########
@@ -1433,7 +1435,10 @@ object ScalarOperatorGens {
       .map(_._2.last)
       .values
       .toSeq
-    val valueType = mapType.getValueType
+    val valueType = resultType match {
+      case mapType1: MapType => mapType1.getValueType
+      case _ => DataTypes.INT().getLogicalType

Review Comment:
   nit: it's better to call `new IntType()` at code gen level, I guess it should be not null?



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExprCodeGenerator.scala:
##########
@@ -715,9 +715,9 @@ class ExprCodeGenerator(ctx: CodeGeneratorContext, nullableInput: Boolean)
       case ARRAY_VALUE_CONSTRUCTOR =>
         generateArray(ctx, resultType, operands)
 
-      // maps
-      case MAP_VALUE_CONSTRUCTOR =>
-        generateMap(ctx, resultType, operands)
+      // maps and multisets
+      case MAP_VALUE_CONSTRUCTOR | MULTISET_VALUE =>

Review Comment:
   Let's also call it `MULTISET_VALUE_CONSTRUCTOR` to be in sync with map and array



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

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org