-
Notifications
You must be signed in to change notification settings - Fork 117
feat(parquet): support reading list columns as Arrow large_list #714
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
Open
rahulsmahadev
wants to merge
2
commits into
apache:main
Choose a base branch
from
rahulsmahadev:feat-parquet-large-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| #include "iceberg/result.h" | ||
| #include "iceberg/schema_internal.h" | ||
| #include "iceberg/schema_util.h" | ||
| #include "iceberg/util/checked_cast.h" | ||
| #include "iceberg/util/macros.h" | ||
|
|
||
| namespace iceberg::parquet { | ||
|
|
@@ -84,6 +85,41 @@ class EmptyRecordBatchReader : public ::arrow::RecordBatchReader { | |
| } | ||
| }; | ||
|
|
||
| std::shared_ptr<::arrow::Field> UseLargeListField( | ||
| const std::shared_ptr<::arrow::Field>& field); | ||
|
|
||
| // Rebuild a data type with all nested list types replaced by large_list. | ||
| std::shared_ptr<::arrow::DataType> UseLargeListType( | ||
| const std::shared_ptr<::arrow::DataType>& type) { | ||
| switch (type->id()) { | ||
| case ::arrow::Type::LIST: { | ||
| const auto& list_type = internal::checked_cast<const ::arrow::ListType&>(*type); | ||
| return ::arrow::large_list(UseLargeListField(list_type.value_field())); | ||
| } | ||
| case ::arrow::Type::STRUCT: { | ||
| ::arrow::FieldVector fields; | ||
| fields.reserve(type->num_fields()); | ||
| for (const auto& field : type->fields()) { | ||
| fields.push_back(UseLargeListField(field)); | ||
| } | ||
| return ::arrow::struct_(std::move(fields)); | ||
| } | ||
| case ::arrow::Type::MAP: { | ||
| const auto& map_type = internal::checked_cast<const ::arrow::MapType&>(*type); | ||
| return std::make_shared<::arrow::MapType>(UseLargeListField(map_type.key_field()), | ||
| UseLargeListField(map_type.item_field()), | ||
| map_type.keys_sorted()); | ||
| } | ||
| default: | ||
| return type; | ||
| } | ||
| } | ||
|
|
||
| std::shared_ptr<::arrow::Field> UseLargeListField( | ||
| const std::shared_ptr<::arrow::Field>& field) { | ||
| return field->WithType(UseLargeListType(field->type())); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // A stateful context to keep track of the reading progress. | ||
|
|
@@ -118,6 +154,10 @@ class ParquetReader::Impl { | |
| arrow_reader_properties.set_batch_size( | ||
| options.properties.Get(ReaderProperties::kBatchSize)); | ||
| arrow_reader_properties.set_arrow_extensions_enabled(true); | ||
| use_large_list_ = options.properties.Get(ReaderProperties::kArrowUseLargeList); | ||
| if (use_large_list_) { | ||
| arrow_reader_properties.set_list_type(::arrow::Type::LARGE_LIST); | ||
| } | ||
|
|
||
| // Open the Parquet file reader | ||
| ICEBERG_ASSIGN_OR_RAISE(input_stream_, OpenInputStream(options)); | ||
|
|
@@ -214,6 +254,17 @@ class ParquetReader::Impl { | |
| ICEBERG_RETURN_UNEXPECTED(ToArrowSchema(*read_schema_, &arrow_schema)); | ||
| ICEBERG_ARROW_ASSIGN_OR_RETURN(context_->output_arrow_schema_, | ||
| ::arrow::ImportSchema(&arrow_schema)); | ||
| if (use_large_list_) { | ||
| // Align the output schema with the large_list arrays produced by the | ||
| // Parquet reader when kArrowUseLargeList is enabled. | ||
| ::arrow::FieldVector fields; | ||
| fields.reserve(context_->output_arrow_schema_->fields().size()); | ||
| for (const auto& field : context_->output_arrow_schema_->fields()) { | ||
| fields.push_back(UseLargeListField(field)); | ||
| } | ||
|
Comment on lines
+260
to
+264
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is duplicated logic. |
||
| context_->output_arrow_schema_ = | ||
| ::arrow::schema(std::move(fields), context_->output_arrow_schema_->metadata()); | ||
| } | ||
|
|
||
| // Row group pruning based on the split | ||
| // TODO(gangwu): add row group filtering based on zone map, bloom filter, etc. | ||
|
|
@@ -255,6 +306,8 @@ class ParquetReader::Impl { | |
| ::arrow::MemoryPool* pool_ = ::arrow::default_memory_pool(); | ||
| // The split to read from the Parquet file. | ||
| std::optional<Split> split_; | ||
| // Whether to read list columns as large_list (64-bit offsets). | ||
| bool use_large_list_ = false; | ||
| // Schema to read from the Parquet file. | ||
| std::shared_ptr<::iceberg::Schema> read_schema_; | ||
| // The projection result to apply to the read schema. | ||
|
|
||
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
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.
add comment: