[ https://issues.apache.org/jira/browse/FLINK-4294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15428173#comment-15428173 ]
ASF GitHub Bot commented on FLINK-4294: --------------------------------------- Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/2319#discussion_r75479103 --- Diff: flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/expressions/CompositeAccessTest.scala --- @@ -0,0 +1,167 @@ +/* + * 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.api.table.expressions + +import org.apache.calcite.tools.ValidationException +import org.apache.flink.api.common.typeinfo.TypeInformation +import org.apache.flink.api.java.typeutils.{TupleTypeInfo, TypeExtractor} +import org.apache.flink.api.scala.createTypeInformation +import org.apache.flink.api.scala.table._ +import org.apache.flink.api.table +import org.apache.flink.api.table.{Row, Types} +import org.apache.flink.api.table.expressions.CompositeAccessTest.{MyCaseClass, MyCaseClass2, MyPojo} +import org.apache.flink.api.table.expressions.utils.ExpressionTestBase +import org.apache.flink.api.table.typeutils.RowTypeInfo +import org.junit.Test + + +class CompositeAccessTest extends ExpressionTestBase { + + @Test + def testGetField(): Unit = { + + testAllApis( + 'f0.getField("intField"), + "f0.getField('intField')", + "testTable.f0.intField", + "42") + + testTableApi( + 'f0.getField(0), + "f0.getField(0)", + "42") + + testSqlApi("testTable.f0.stringField", "Bob") + + testSqlApi("testTable.f0.booleanField", "true") + + testAllApis( + 'f1.getField("objectField").getField("intField"), + "f1.getField('objectField').getField('intField')", + "testTable.f1.objectField.intField", + "25") + + testSqlApi("testTable.f1.objectField.stringField", "Timo") + + testSqlApi("testTable.f1.objectField.booleanField", "false") + + testAllApis( + 'f2.getField(0), + "f2.getField(0)", + "testTable.f2._1", + "a") + + testSqlApi("testTable.f3.f1", "b") + + testSqlApi("testTable.f4.myString", "Hello") + + testSqlApi("testTable.f5", "13") + + testSqlApi("testTable.f6", "null") + + testAllApis( + 'f7.getField("_1"), + "getField(f7, '_1')", + "testTable.f7._1", + "true") + + // TODO Not supported by Calcite + // you cannot get a composite type + // testSqlApi("testTable.f1.objectField", "25") --- End diff -- I tried this case and got a Calcite exception which was not very helpful. Can we improve the exception for this error? Do you think we should open an issue in the Calcite JIRA to support this case, @twalthr? > Allow access of composite type fields > ------------------------------------- > > Key: FLINK-4294 > URL: https://issues.apache.org/jira/browse/FLINK-4294 > Project: Flink > Issue Type: New Feature > Components: Table API & SQL > Reporter: Timo Walther > Assignee: Timo Walther > > Currently all Flink CompositeTypes are treated as GenericRelDataTypes. It > would be better to access individual fields of composite types, too. e.g. > {code} > SELECT composite.name FROM composites > SELECT tuple.f0 FROM tuples > 'f0.getField(0) > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)