-
Notifications
You must be signed in to change notification settings - Fork 153
Improve recursive normalized data read performance #2742
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
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
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 |
|---|---|---|
|
|
@@ -47,6 +47,80 @@ inline void apply_type_handlers(SegmentInMemory seg, std::any& handler_data, Out | |
| } | ||
| } | ||
|
|
||
| inline ReadResult create_python_read_result( | ||
|
Collaborator
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. Can this be moved to a .cpp file
Collaborator
Author
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. It has been marked |
||
| const std::variant<VersionedItem, std::vector<VersionedItem>>& version, OutputFormat output_format, | ||
| FrameAndDescriptor&& fd, | ||
| std::optional<std::vector<arcticdb::proto::descriptors::UserDefinedMetadata>>&& user_meta = std::nullopt, | ||
| std::vector<version_store::ReadVersionOutput>&& node_outputs = {} | ||
| ) { | ||
| auto result = std::move(fd); | ||
|
|
||
| // If version is a vector then this was a multi-symbol join, so the user_meta vector should have a value | ||
| // Otherwise, there is a single piece of metadata on the frame descriptor | ||
| util::check( | ||
| std::holds_alternative<VersionedItem>(version) ^ user_meta.has_value(), | ||
| "Unexpected argument combination to create_python_read_result" | ||
| ); | ||
|
|
||
| // Very old (pre Nov-2020) PandasIndex protobuf messages had no "start" or "step" fields. If is_physically_stored | ||
| // (renamed from is_not_range_index) was false, the index was always RangeIndex(num_rows, 1) | ||
| // This used to be handled in the Python layer by passing None to the DataFrame index parameter, which would then | ||
| // default to RangeIndex(num_rows, 1). However, the empty index also has is_physically_stored as false, and because | ||
| // integer protobuf fields default to zero if they are not present on the wire, it is impossible to tell from | ||
| // the normalization metadata alone if the data was written with an empty index, or with a very old range index. | ||
| // We therefore patch the normalization metadata here in this case | ||
| auto norm_meta = result.desc_.mutable_proto().mutable_normalization(); | ||
| if (norm_meta->has_df() || norm_meta->has_series()) { | ||
| auto common = norm_meta->has_df() ? norm_meta->mutable_df()->mutable_common() | ||
| : norm_meta->mutable_series()->mutable_common(); | ||
| if (common->has_index()) { | ||
| auto index = common->mutable_index(); | ||
| if (result.desc_.index().type() == IndexDescriptor::Type::ROWCOUNT && !index->is_physically_stored() && | ||
| index->start() == 0 && index->step() == 0) { | ||
| index->set_step(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| auto get_python_frame = [output_format](auto& result) -> OutputFrame { | ||
| if (output_format == OutputFormat::ARROW) { | ||
| return ArrowOutputFrame{segment_to_arrow_data(result.frame_)}; | ||
| } else { | ||
| return pipelines::PandasOutputFrame{result.frame_}; | ||
| } | ||
| }; | ||
| auto python_frame = get_python_frame(result); | ||
| util::print_total_mem_usage(__FILE__, __LINE__, __FUNCTION__); | ||
|
|
||
| const auto& desc_proto = result.desc_.proto(); | ||
| std::variant< | ||
| arcticdb::proto::descriptors::UserDefinedMetadata, | ||
| std::vector<arcticdb::proto::descriptors::UserDefinedMetadata>> | ||
| metadata; | ||
| if (user_meta.has_value()) { | ||
| metadata = std::move(*user_meta); | ||
| } else { | ||
| metadata = std::move(desc_proto.user_meta()); | ||
| } | ||
|
|
||
| std::vector<NodeReadResult> node_results; | ||
| for (auto& node_output : node_outputs) { | ||
| auto& node_fd = node_output.frame_and_descriptor_; | ||
| auto node_python_frame = get_python_frame(node_fd); | ||
| auto node_metadata = node_fd.desc_.proto().normalization(); | ||
| node_results.emplace_back( | ||
| node_output.versioned_item_.symbol(), std::move(node_python_frame), std::move(node_metadata) | ||
| ); | ||
| } | ||
| return {version, | ||
| std::move(python_frame), | ||
| output_format, | ||
| desc_proto.normalization(), | ||
| metadata, | ||
| desc_proto.multi_key_meta(), | ||
| std::move(node_results)}; | ||
| } | ||
|
|
||
| inline ReadResult read_result_from_single_frame( | ||
| FrameAndDescriptor& frame_and_desc, const AtomKey& key, std::any& handler_data, OutputFormat output_format | ||
| ) { | ||
|
|
||
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.
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.
Just moving existing function to a new place to resolve some circular dependency issue