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

[GitHub] [flink] liuyongvs commented on a diff in pull request #21993: [FLINK-31166][table] Fix array_contains does not support null argumen…

liuyongvs commented on code in PR #21993:
URL: https://github.com/apache/flink/pull/21993#discussion_r1116473617


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/SpecificInputTypeStrategies.java:
##########
@@ -71,7 +71,11 @@ public final class SpecificInputTypeStrategies {
 
     /** Argument type derived from the array element type. */
     public static final ArgumentTypeStrategy ARRAY_ELEMENT_ARG =
-            new ArrayElementArgumentTypeStrategy();
+            new ArrayElementArgumentTypeStrategy(false);
+
+    /** Argument type derived from the array element type. But leaves nullability untouched. */

Review Comment:
   this comment copy from InputTypeStrategies.COMMON_ARG_NULLABLE, you can look it



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/ArrayElementArgumentTypeStrategy.java:
##########
@@ -31,24 +31,28 @@
 
 import java.util.Optional;
 
-import static org.apache.flink.table.types.logical.utils.LogicalTypeCasts.supportsImplicitCast;
-
 /** Specific {@link ArgumentTypeStrategy} for {@link BuiltInFunctionDefinitions#ARRAY_CONTAINS}. */
 @Internal
 class ArrayElementArgumentTypeStrategy implements ArgumentTypeStrategy {
 
+    private final boolean preserveNullability;
+
+    public ArrayElementArgumentTypeStrategy(boolean preserveNullability) {
+        this.preserveNullability = preserveNullability;
+    }
+
     @Override
     public Optional<DataType> inferArgumentType(
             CallContext callContext, int argumentPos, boolean throwOnFailure) {
         final ArrayType haystackType =
                 (ArrayType) callContext.getArgumentDataTypes().get(0).getLogicalType();
         final LogicalType haystackElementType = haystackType.getElementType();
-        final LogicalType needleType =
-                callContext.getArgumentDataTypes().get(argumentPos).getLogicalType();
-        if (supportsImplicitCast(needleType, haystackElementType)) {

Review Comment:
   - first 
     SELECT array_contains(array[1, 2, 3], cast(null as int)); it will throw exception.
     array type is: ARRAR<INT NOT NULL> NOT NULL, 
     arg type is : INT
     
     the logical current always return false **supportsImplicitCast(needleType, haystackElementType)**, so it will throw exception
   
   - second
     the outer logical also will check function args type and the call arg using  supportsImplicitCast at TypeInferenceUtil.adaptArguments



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