dawidwys commented on a change in pull request #11951:
URL: https://github.com/apache/flink/pull/11951#discussion_r418937589



##########
File path: 
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/typeutils/FieldInfoUtilsTest.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.typeutils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.types.DataType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.apache.flink.table.api.Expressions.$;
+
+/**
+ * Test suite for {@link FieldInfoUtils}.
+ */
+public class FieldInfoUtilsTest {
+
+       private static final RowTypeInfo typeInfo = new RowTypeInfo(
+               new TypeInformation[]{Types.INT, Types.LONG, Types.STRING},
+               new String[]{"f0", "f1", "f2"});
+
+       @Test
+       public void testByPositionMode() {
+               FieldInfoUtils.TypeInfoSchema schema = 
FieldInfoUtils.getFieldsInfo(
+                       typeInfo,
+                       new Expression[]{$("aa"), $("bb"), $("cc")});
+
+               Assert.assertEquals("[aa, bb, cc]", 
Arrays.asList(schema.getFieldNames()).toString());
+               Assert.assertArrayEquals(new DataType[]{DataTypes.INT(), 
DataTypes.BIGINT(), DataTypes.STRING()}, schema.getFieldTypes());
+       }
+
+       @Test
+       public void testByNameModeReorder() {
+               FieldInfoUtils.TypeInfoSchema schema = 
FieldInfoUtils.getFieldsInfo(
+                       typeInfo,
+                       new Expression[]{$("f2"), $("f1"), $("f0")});
+
+               Assert.assertEquals("[f2, f1, f0]", 
Arrays.asList(schema.getFieldNames()).toString());
+               Assert.assertArrayEquals(new DataType[]{DataTypes.STRING(), 
DataTypes.BIGINT(), DataTypes.INT()}, schema.getFieldTypes());
+       }
+
+       @Test
+       public void testByNameModeReorderAndRename() {

Review comment:
       
   
   Can you also add a test for extracting fields in byPosition mode when there 
is a rowtime/proctime attribute?
   
   select($("a"), $("b"), $("timestamp").rowtime().as("rowtime")) -> this 
should still use the by position mode. I know it might be a bit confusing but 
it is the behavior since very early.
   

##########
File path: 
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/typeutils/FieldInfoUtilsTest.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.typeutils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.types.DataType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.apache.flink.table.api.Expressions.$;
+
+/**
+ * Test suite for {@link FieldInfoUtils}.
+ */
+public class FieldInfoUtilsTest {

Review comment:
       Could you add tests to check if it works for `PojoTypeInfo` as well?

##########
File path: 
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/typeutils/FieldInfoUtilsTest.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.typeutils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.types.DataType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.apache.flink.table.api.Expressions.$;
+
+/**
+ * Test suite for {@link FieldInfoUtils}.
+ */
+public class FieldInfoUtilsTest {
+
+       private static final RowTypeInfo typeInfo = new RowTypeInfo(
+               new TypeInformation[]{Types.INT, Types.LONG, Types.STRING},
+               new String[]{"f0", "f1", "f2"});
+
+       @Test
+       public void testByPositionMode() {
+               FieldInfoUtils.TypeInfoSchema schema = 
FieldInfoUtils.getFieldsInfo(
+                       typeInfo,
+                       new Expression[]{$("aa"), $("bb"), $("cc")});
+
+               Assert.assertEquals("[aa, bb, cc]", 
Arrays.asList(schema.getFieldNames()).toString());

Review comment:
       Why don't you verify the array? Verifying a toString method is rather 
fragile.




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

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


Reply via email to