-
Notifications
You must be signed in to change notification settings - Fork 4
Add interval array #60
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
Alex-PLACET
wants to merge
4
commits into
QuantStack:main
Choose a base branch
from
Alex-PLACET:add_interval_array
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.
+242
−90
Open
Changes from all commits
Commits
Show all changes
4 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 |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #pragma once | ||
|
|
||
| #include <optional> | ||
| #include <unordered_set> | ||
| #include <vector> | ||
|
|
||
| #include <sparrow/arrow_interface/arrow_array_schema_proxy.hpp> | ||
|
|
||
| #include "Message_generated.h" | ||
| #include "sparrow_ipc/arrow_interface/arrow_array.hpp" | ||
| #include "sparrow_ipc/arrow_interface/arrow_schema.hpp" | ||
| #include "sparrow_ipc/deserialize_utils.hpp" | ||
|
|
||
| namespace sparrow_ipc::detail | ||
| { | ||
| /** | ||
| * @brief Generic implementation for deserializing non-owning arrays with simple layout. | ||
| * | ||
| * This function provides the common deserialization logic for array types that have | ||
| * a validity buffer and a single data buffer (e.g., primitive_array, interval_array). | ||
| * | ||
| * @tparam ArrayType The array type template (e.g., sparrow::primitive_array) | ||
| * @tparam T The element type | ||
| * | ||
| * @param record_batch The FlatBuffer RecordBatch containing metadata | ||
| * @param body The raw buffer data | ||
| * @param name The array column name | ||
| * @param metadata Optional metadata pairs | ||
| * @param nullable Whether the array is nullable | ||
| * @param buffer_index The current buffer index (incremented by this function) | ||
| * | ||
| * @return The deserialized array of type ArrayType<T> | ||
| */ | ||
| template <template<typename> class ArrayType, typename T> | ||
| [[nodiscard]] ArrayType<T> deserialize_non_owning_simple_array( | ||
| const org::apache::arrow::flatbuf::RecordBatch& record_batch, | ||
| std::span<const uint8_t> body, | ||
| std::string_view name, | ||
| const std::optional<std::vector<sparrow::metadata_pair>>& metadata, | ||
| bool nullable, | ||
| size_t& buffer_index | ||
| ) | ||
| { | ||
| const std::string_view format = data_type_to_format( | ||
| sparrow::detail::get_data_type_from_array<ArrayType<T>>::get() | ||
| ); | ||
|
|
||
| // Set up flags based on nullable | ||
| std::optional<std::unordered_set<sparrow::ArrowFlag>> flags; | ||
| if (nullable) | ||
| { | ||
| flags = std::unordered_set<sparrow::ArrowFlag>{sparrow::ArrowFlag::NULLABLE}; | ||
| } | ||
|
|
||
| ArrowSchema schema = make_non_owning_arrow_schema( | ||
| format, | ||
| name.data(), | ||
| metadata, | ||
| flags, | ||
| 0, | ||
| nullptr, | ||
| nullptr | ||
| ); | ||
|
|
||
| const auto compression = record_batch.compression(); | ||
| std::vector<arrow_array_private_data::optionally_owned_buffer> buffers; | ||
|
|
||
| auto validity_buffer_span = utils::get_buffer(record_batch, body, buffer_index); | ||
| auto data_buffer_span = utils::get_buffer(record_batch, body, buffer_index); | ||
|
|
||
| if (compression) | ||
| { | ||
| buffers.push_back(utils::get_decompressed_buffer(validity_buffer_span, compression)); | ||
| buffers.push_back(utils::get_decompressed_buffer(data_buffer_span, compression)); | ||
| } | ||
| else | ||
| { | ||
| buffers.emplace_back(validity_buffer_span); | ||
| buffers.emplace_back(data_buffer_span); | ||
| } | ||
|
|
||
| // TODO bitmap_ptr is not used anymore... Leave it for now, and remove later if no need confirmed | ||
| const auto [bitmap_ptr, null_count] = utils::get_bitmap_pointer_and_null_count(validity_buffer_span, record_batch.length()); | ||
|
|
||
| ArrowArray array = make_arrow_array<arrow_array_private_data>( | ||
| record_batch.length(), | ||
| null_count, | ||
| 0, | ||
| 0, | ||
| nullptr, | ||
| nullptr, | ||
| std::move(buffers) | ||
| ); | ||
|
|
||
| sparrow::arrow_proxy ap{std::move(array), std::move(schema)}; | ||
| return ArrayType<T>{std::move(ap)}; | ||
| } | ||
| } |
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,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <sparrow/arrow_interface/arrow_array_schema_proxy.hpp> | ||
| #include <sparrow/interval_array.hpp> | ||
|
|
||
| #include "Message_generated.h" | ||
| #include "sparrow_ipc/deserialize_array_impl.hpp" | ||
|
|
||
| namespace sparrow_ipc | ||
| { | ||
| template <typename T> | ||
| [[nodiscard]] sparrow::interval_array<T> deserialize_non_owning_interval_array( | ||
| const org::apache::arrow::flatbuf::RecordBatch& record_batch, | ||
| std::span<const uint8_t> body, | ||
| std::string_view name, | ||
| const std::optional<std::vector<sparrow::metadata_pair>>& metadata, | ||
| bool nullable, | ||
| size_t& buffer_index | ||
| ) | ||
| { | ||
| return detail::deserialize_non_owning_simple_array<sparrow::interval_array, T>( | ||
| record_batch, | ||
| body, | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index | ||
| ); | ||
| } | ||
| } | ||
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.
It seems this function is exactly the same (except from data type) as the one used in
primitive_array, so we should probably refactor and use some generic function.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 addressed your point, now there is a: deserialize_non_owning_simple_array