slinkydeveloper commented on a change in pull request #18940:
URL: https://github.com/apache/flink/pull/18940#discussion_r829779528



##########
File path: 
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/FieldAccessFromTableITCase.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.planner.functions;
+
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.types.Row;
+
+import java.util.stream.Stream;
+
+import static java.util.Collections.singletonMap;
+import static org.apache.flink.table.api.DataTypes.ARRAY;
+import static org.apache.flink.table.api.DataTypes.BIGINT;
+import static org.apache.flink.table.api.DataTypes.FIELD;
+import static org.apache.flink.table.api.DataTypes.MAP;
+import static org.apache.flink.table.api.DataTypes.ROW;
+import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.apache.flink.table.api.Expressions.$;
+
+/**
+ * Regular tests. See also {@link ConstructedAccessFunctionsITCase} for tests 
that access a nested
+ * field of an expression or for {@link BuiltInFunctionDefinitions#FLATTEN} 
which produces multiple
+ * columns from a single one.
+ */
+class FieldAccessFromTableITCase extends BuiltInFunctionTestBase {
+
+    @Override
+    public Stream<TestSetSpec> getTestCaseSpecs() {
+        return Stream.of(
+
+                // Actually in case of SQL it does not use the GET method, but
+                // a custom logic for accessing nested fields of a Table.
+                TestSetSpec.forFunction(BuiltInFunctionDefinitions.GET)
+                        .onFieldsWithData(null, Row.of(1))
+                        .andDataTypes(
+                                ROW(FIELD("nested", 
BIGINT().notNull())).nullable(),
+                                ROW(FIELD("nested", 
BIGINT().notNull())).notNull())
+                        .testResult(
+                                resultSpec(
+                                        $("f0").get("nested"),
+                                        "f0.nested",
+                                        null,
+                                        BIGINT().nullable()),
+                                resultSpec(
+                                        $("f1").get("nested"),
+                                        "f1.nested",
+                                        1L,
+                                        BIGINT().notNull())),
+
+                // In Calcite it maps to FlinkSqlOperatorTable.ITEM
+                TestSetSpec.forFunction(BuiltInFunctionDefinitions.AT)
+                        .onFieldsWithData(
+                                null,
+                                new int[] {1},
+                                null,
+                                singletonMap("nested", 1),
+                                null,
+                                Row.of(1))
+                        .andDataTypes(
+                                ARRAY(BIGINT().notNull()).nullable(),
+                                ARRAY(BIGINT().notNull()).notNull(),
+                                MAP(STRING(), BIGINT().notNull()).nullable(),
+                                MAP(STRING(), BIGINT().notNull()).notNull(),
+                                ROW(FIELD("nested", 
BIGINT().notNull())).nullable(),
+                                ROW(FIELD("nested", 
BIGINT().notNull())).notNull())
+                        // accessing elements of MAP or ARRAY is a runtime 
operations,
+                        // we do not know about the size or contents during 
the inference
+                        // therefore the results are always nullable
+                        .testResult(
+                                resultSpec($("f0").at(1), "f0[1]", null, 
BIGINT().nullable()),

Review comment:
       in this case i'm not sure it does. `testResult` is either a vararg of 
result spec or a function taking 5 args. I rather prefer to keep it as it is.




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