hanyuzheng7 commented on code in PR #22730:
URL: https://github.com/apache/flink/pull/22730#discussion_r1243824282


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/ArrayComparableElementTypeStrategy.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.types.inference.strategies;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.types.CollectionDataType;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.ArgumentCount;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.inference.ConstantArgumentCount;
+import org.apache.flink.table.types.inference.InputTypeStrategy;
+import org.apache.flink.table.types.inference.Signature;
+import org.apache.flink.table.types.logical.LegacyTypeInformationType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import 
org.apache.flink.table.types.logical.StructuredType.StructuredComparison;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * An {@link InputTypeStrategy} that checks if the input argument is an ARRAY 
type and check whether
+ * its' elements are comparable.
+ *
+ * <p>It requires one argument.
+ *
+ * <p>For the rules which types are comparable with which types see {@link
+ * #areComparable(LogicalType, LogicalType)}.
+ */
+@Internal
+public final class ArrayComparableElementTypeStrategy implements 
InputTypeStrategy {
+    private final StructuredComparison requiredComparison;
+    private final ConstantArgumentCount argumentCount;
+
+    public ArrayComparableElementTypeStrategy(StructuredComparison 
requiredComparison) {
+        Preconditions.checkArgument(requiredComparison != 
StructuredComparison.NONE);
+        this.requiredComparison = requiredComparison;
+        this.argumentCount = ConstantArgumentCount.of(1);
+    }
+
+    @Override
+    public ArgumentCount getArgumentCount() {
+        return argumentCount;
+    }
+
+    @Override
+    public Optional<List<DataType>> inferInputTypes(
+            CallContext callContext, boolean throwOnFailure) {
+        final List<DataType> argumentDataTypes = 
callContext.getArgumentDataTypes();
+        List<LogicalType> argumentTypes =
+                argumentDataTypes.stream()
+                        .map(DataType::getLogicalType)
+                        .collect(Collectors.toList());
+
+        if (!argumentTypes.stream()
+                .allMatch(logicalType -> 
logicalType.is(LogicalTypeRoot.ARRAY))) {
+            return callContext.fail(throwOnFailure, "All arguments requires to 
be a ARRAY type");
+        }

Review Comment:
   It seem I didn't omit potential checks. So what potential checks should be 
added?
   ```
   
       public Optional<List<DataType>> inferInputTypes(
               CallContext callContext, boolean throwOnFailure) {
           final List<DataType> argumentDataTypes = 
callContext.getArgumentDataTypes();
           List<LogicalType> argumentTypes =
                   argumentDataTypes.stream()
                           .map(DataType::getLogicalType)
                           .collect(Collectors.toList());
   
           if (!argumentTypes.stream()
                   .allMatch(logicalType -> 
logicalType.is(LogicalTypeRoot.ARRAY))) {
               return callContext.fail(throwOnFailure, "All arguments requires 
to be a ARRAY type");
           }
           if (argumentDataTypes.size() == 1) {
               final DataType elementDataType =
                       ((CollectionDataType) 
argumentDataTypes.get(0)).getElementDataType();
               final LogicalType elementLogicalDataType = 
elementDataType.getLogicalType();
               if (!areComparable(elementLogicalDataType, 
elementLogicalDataType)) {
                   return callContext.fail(
                           throwOnFailure,
                           "Type '%s' should support %s comparison with 
itself.",
                           elementLogicalDataType,
                           comparisonToString());
               }
           }
           return Optional.of(argumentDataTypes);
       }
   ```
   
   But I can  simplify 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.

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

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

Reply via email to