-
Notifications
You must be signed in to change notification settings - Fork 3k
Implement the parquet value reader & writer for apache flink #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ab0c7e4
Implement the parquet value reader & writer for apache flink
openinx e33d2cd
Fix the failure unit tests.
openinx 1c37f6d
Remove the StructWriterFactory & StructReaderFactory.
openinx f4799a0
Revert the generic type in GenericParquetReaders#buildReader
openinx 0350b9b
Add test suits for DictionaryEncodedData and FallbackData
openinx 17845b1
Revert to user the StructWriterFactory & StructReaderFactory
openinx 95e197a
Use the Record instead of GenericRecord
openinx 5bffced
Make the flink parquet reader/write inherit the generic parquet reade…
openinx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
flink/src/main/java/org/apache/iceberg/flink/data/FlinkParquetReaders.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * 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.iceberg.flink.data; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.flink.types.Row; | ||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.data.parquet.GenericParquetReaders; | ||
| import org.apache.iceberg.parquet.ParquetSchemaUtil; | ||
| import org.apache.iceberg.parquet.ParquetValueReader; | ||
| import org.apache.iceberg.parquet.ParquetValueReaders; | ||
| import org.apache.iceberg.parquet.TypeWithSchemaVisitor; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.apache.parquet.schema.MessageType; | ||
| import org.apache.parquet.schema.Type; | ||
|
|
||
| public class FlinkParquetReaders extends GenericParquetReaders { | ||
| private FlinkParquetReaders() { | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static ParquetValueReader<Row> buildRowReader(Schema expectedSchema, | ||
| MessageType fileSchema) { | ||
| if (ParquetSchemaUtil.hasIds(fileSchema)) { | ||
| return (ParquetValueReader<Row>) | ||
| TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, | ||
| new ReadBuilder(fileSchema, ImmutableMap.of())); | ||
| } else { | ||
| return (ParquetValueReader<Row>) | ||
| TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, | ||
| new FallbackReadBuilder(fileSchema, ImmutableMap.of())); | ||
| } | ||
| } | ||
|
|
||
| private static class FallbackReadBuilder extends GenericParquetReaders.FallbackReadBuilder { | ||
|
|
||
| private FallbackReadBuilder(MessageType type, Map<Integer, ?> idToConstant) { | ||
| super(type, idToConstant); | ||
| } | ||
|
|
||
| @Override | ||
| protected ParquetValueReaders.StructReader<?, ?> createStructReader(List<Type> types, | ||
| List<ParquetValueReader<?>> readers, | ||
| Types.StructType struct) { | ||
| return new RowReader(types, readers, struct); | ||
| } | ||
| } | ||
|
|
||
| private static class ReadBuilder extends GenericParquetReaders.ReadBuilder { | ||
|
|
||
| private ReadBuilder(MessageType type, Map<Integer, ?> idToConstant) { | ||
| super(type, idToConstant); | ||
| } | ||
|
|
||
| @Override | ||
| protected ParquetValueReaders.StructReader<Row, Row> createStructReader(List<Type> types, | ||
| List<ParquetValueReader<?>> readers, | ||
| Types.StructType struct) { | ||
| return new RowReader(types, readers, struct); | ||
| } | ||
| } | ||
|
|
||
| static class RowReader extends ParquetValueReaders.StructReader<Row, Row> { | ||
| private final Types.StructType structType; | ||
|
|
||
| RowReader(List<Type> types, List<ParquetValueReader<?>> readers, Types.StructType struct) { | ||
| super(types, readers); | ||
| this.structType = struct; | ||
| } | ||
|
|
||
| @Override | ||
| protected Row newStructData(Row reuse) { | ||
| if (reuse != null) { | ||
| return reuse; | ||
| } else { | ||
| return new Row(structType.fields().size()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected Object getField(Row row, int pos) { | ||
| return row.getField(pos); | ||
| } | ||
|
|
||
| @Override | ||
| protected Row buildStruct(Row row) { | ||
| return row; | ||
| } | ||
|
|
||
| @Override | ||
| protected void set(Row row, int pos, Object value) { | ||
| row.setField(pos, value); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the
buildReadertobuildRowReaderbecause the parentbuildReaderwill return with aParquetValueReader <Record>data type, which clashes with this FlinkParquetReaders 'sbuildReaderreturnedParquetValueReader <Row>.