You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/07/10 13:04:17 UTC

[GitHub] [flink] fhueske commented on a change in pull request #8064: [FLINK-7244] Add parquet table source

fhueske commented on a change in pull request #8064: [FLINK-7244] Add parquet table source
URL: https://github.com/apache/flink/pull/8064#discussion_r302039508
 
 

 ##########
 File path: flink-formats/flink-parquet/src/test/java/org/apache/flink/formats/parquet/ParquetTableSourceTest.java
 ##########
 @@ -0,0 +1,234 @@
+/*
+ * 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.formats.parquet;
+
+import org.apache.flink.api.common.io.InputFormat;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.api.java.operators.DataSource;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.api.java.typeutils.ObjectArrayTypeInfo;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.formats.parquet.utils.TestUtil;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.expressions.EqualTo;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.expressions.GetCompositeField;
+import org.apache.flink.table.expressions.GreaterThan;
+import org.apache.flink.table.expressions.ItemAt;
+import org.apache.flink.table.expressions.Literal;
+import org.apache.flink.table.expressions.PlannerResolvedFieldReference;
+import org.apache.flink.types.Row;
+
+import org.apache.avro.specific.SpecificRecord;
+import org.apache.parquet.avro.AvroSchemaConverter;
+import org.apache.parquet.filter2.predicate.FilterApi;
+import org.apache.parquet.filter2.predicate.FilterPredicate;
+import org.apache.parquet.schema.MessageType;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.mockito.ArgumentCaptor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test cases for {@link ParquetTableSource}.
+ */
+public class ParquetTableSourceTest extends TestUtil {
+	private static final AvroSchemaConverter SCHEMA_CONVERTER = new AvroSchemaConverter();
+	private static Path testPath;
+
+	@ClassRule
+	public static TemporaryFolder tempRoot = new TemporaryFolder();
+
+	@BeforeClass
+	public static void setup() throws Exception {
+		testPath = createTestParquetFile();
+	}
+
+	@Test
+	public void testGetReturnType() {
+		MessageType nestedSchema = SCHEMA_CONVERTER.convert(TestUtil.NESTED_SCHEMA);
+		ParquetTableSource parquetTableSource = ParquetTableSource.builder()
+			.path("dummy-path")
+			.forParquetSchema(nestedSchema)
+			.build();
+
+		TypeInformation<Row> returnType = parquetTableSource.getReturnType();
+		assertNotNull(returnType);
+		assertTrue(returnType instanceof RowTypeInfo);
+		RowTypeInfo rowType = (RowTypeInfo) returnType;
+		assertEquals(NESTED_ROW_TYPE, rowType);
+	}
+
+	@Test
+	public void testGetTableSchema() {
+		MessageType nestedSchema = SCHEMA_CONVERTER.convert(TestUtil.NESTED_SCHEMA);
+		ParquetTableSource parquetTableSource = ParquetTableSource.builder()
+			.path("dummy-path")
+			.forParquetSchema(nestedSchema)
+			.build();
+
+		TableSchema schema = parquetTableSource.getTableSchema();
+		assertNotNull(schema);
+
+		RowTypeInfo expectedSchema = (RowTypeInfo) NESTED_ROW_TYPE;
+		assertArrayEquals(expectedSchema.getFieldNames(), schema.getFieldNames());
+		assertArrayEquals(expectedSchema.getFieldTypes(), schema.getFieldTypes());
+	}
+
+	@Test
+	public void testFieldsProjection() throws Exception {
+		ParquetTableSource parquetTableSource = createNestedTestParquetTableSource(testPath);
+		ParquetTableSource projected = (ParquetTableSource) parquetTableSource.projectFields(new int[] {2, 4, 6});
+
+		// ensure copy is returned
+		assertTrue(projected != parquetTableSource);
+
+		// ensure table schema is the same
+		assertEquals(parquetTableSource.getTableSchema(), projected.getTableSchema());
+
+		String[] fieldNames = ((RowTypeInfo) NESTED_ROW_TYPE).getFieldNames();
+		TypeInformation[] fieldTypes =  ((RowTypeInfo) NESTED_ROW_TYPE).getFieldTypes();
+		assertEquals(
+			Types.ROW_NAMED(
+				new String[] {fieldNames[2], fieldNames[4], fieldNames[6]},
+				new TypeInformation[] {fieldTypes[2], fieldTypes[4], fieldTypes[6]}
+			),
+			projected.getReturnType()
+		);
+
+		// ensure ParquetInputFormat is configured with selected fields
+		ParquetTableSource spyPTS = spy(projected);
 
 Review comment:
   our new code style guidelines discourage the use of Mockito.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services