AHeise commented on a change in pull request #15725:
URL: https://github.com/apache/flink/pull/15725#discussion_r650899088



##########
File path: 
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/ParquetInputFormat.java
##########
@@ -168,6 +176,16 @@ public void open(FileInputSplit split) throws IOException {
         ParquetReadOptions options = ParquetReadOptions.builder().build();
         ParquetFileReader fileReader = new ParquetFileReader(inputFile, 
options);
         MessageType fileSchema = fileReader.getFileMetaData().getSchema();
+        if (expectedFileSchema == null) { // user did not provide a read 
schema, use the file schema
+            if (fieldNames == null) { // user did not provide projected 
fields, use all the fields
+                RowTypeInfo rowTypeInfo =
+                        (RowTypeInfo) 
ParquetSchemaConverter.fromParquetType(fileSchema);
+                fieldNames = rowTypeInfo.getFieldNames();
+                fieldTypes = rowTypeInfo.getFieldTypes();
+            } else { // user provided projected fields, get the corresponding 
types from file schema
+                fieldTypes = getFieldTypesFromSchema(fieldNames, fileSchema);
+            }
+        }

Review comment:
       :+1: you even covered the hard case with `selectFields`.

##########
File path: 
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/ParquetInputFormat.java
##########
@@ -97,11 +97,13 @@
      */
     protected ParquetInputFormat(Path path, MessageType messageType) {
         super(path);
-        this.expectedFileSchema = checkNotNull(messageType, "messageType");
-        RowTypeInfo rowTypeInfo =
-                (RowTypeInfo) 
ParquetSchemaConverter.fromParquetType(expectedFileSchema);
-        this.fieldTypes = rowTypeInfo.getFieldTypes();
-        this.fieldNames = rowTypeInfo.getFieldNames();
+        this.expectedFileSchema = messageType;

Review comment:
       Please annotate the nullable fields no with `@Nullable` and add a 
comment like, `can be null if it should be inferred from the file` or so.




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


Reply via email to