jnh5y commented on code in PR #23622:
URL: https://github.com/apache/flink/pull/23622#discussion_r1380418763


##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/inference/ItemAtIndexArgumentTypeStrategyTest.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import 
org.apache.flink.table.types.inference.strategies.ItemAtIndexArgumentTypeStrategy;
+import org.apache.flink.table.types.utils.DataTypeFactoryMock;
+
+import java.util.stream.Stream;
+
+/** Tests for {@link ItemAtIndexArgumentTypeStrategy}. */
+class ItemAtIndexArgumentTypeStrategyTest extends InputTypeStrategiesTestBase {
+
+    private static final InputTypeStrategy ITEM_AT_INPUT_STRATEGY =
+            BuiltInFunctionDefinitions.AT
+                    .getTypeInference(new DataTypeFactoryMock())
+                    .getInputTypeStrategy();
+
+    @Override
+    protected Stream<TestSpec> testData() {
+
+        return Stream.of(
+                TestSpec.forStrategy("Validate integer index for an array", 
ITEM_AT_INPUT_STRATEGY)
+                        .calledWithArgumentTypes(
+                                DataTypes.ARRAY(DataTypes.STRING().notNull()),
+                                DataTypes.SMALLINT().notNull())
+                        .expectSignature(
+                                "f([<ARRAY> | <MAP>], [<INTEGER NUMERIC> | 
<MAP_KEY_TYPE>])")
+                        .expectArgumentTypes(
+                                DataTypes.ARRAY(DataTypes.STRING().notNull()),
+                                DataTypes.SMALLINT().notNull()),
+                TestSpec.forStrategy(
+                                "Validate not an integer index for an array",
+                                ITEM_AT_INPUT_STRATEGY)
+                        .calledWithArgumentTypes(
+                                DataTypes.ARRAY(DataTypes.STRING().notNull()), 
DataTypes.STRING())
+                        .expectErrorMessage(
+                                "Array can be indexed only using an INTEGER 
NUMERIC type."),
+                TestSpec.forStrategy("Validate correct map key", 
ITEM_AT_INPUT_STRATEGY)
+                        .calledWithArgumentTypes(
+                                DataTypes.MAP(DataTypes.BIGINT(), 
DataTypes.STRING().notNull()),
+                                DataTypes.SMALLINT())
+                        .expectSignature(
+                                "f([<ARRAY> | <MAP>], [<INTEGER NUMERIC> | 
<MAP_KEY_TYPE>])")
+                        .expectArgumentTypes(
+                                DataTypes.MAP(DataTypes.BIGINT(), 
DataTypes.STRING().notNull()),
+                                DataTypes.BIGINT()),
+                TestSpec.forStrategy("Validate incorrect map key", 
ITEM_AT_INPUT_STRATEGY)

Review Comment:
   Is it worth adding a test which shows that implicit casts will work?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to