-
Notifications
You must be signed in to change notification settings - Fork 4
Add support of time related arrays #69
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
Hind-M
wants to merge
15
commits into
QuantStack:main
Choose a base branch
from
Hind-M:ts_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.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8e27af3
Add deserialization of ts_array, without timezone, date and time
Hind-M 786ebe2
Some cleanup
Hind-M cfd5eb5
Refactor
Hind-M f03e2dc
Add debug
Hind-M e142955
Check tests log
Hind-M bf91b87
Add matrix config
Hind-M ce009af
Link sparrow-ipc to date
Hind-M 0f0395d
Add find_package
Hind-M 902769f
Link publically
Hind-M 5f14576
Add logs for debug
Hind-M 84e1192
Use sparrow 2.0.0 and remove debug logs
Hind-M 54a092e
USE_DATE_POLYFILL=ON when building sparrow only if not windows
Hind-M 1a791d7
Clean up
Hind-M 92db709
Fix after rebase
Hind-M 111fbdd
Remove leftovers
Hind-M 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
108 changes: 108 additions & 0 deletions
108
include/sparrow_ipc/deserialize_time_related_arrays.hpp
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,108 @@ | ||
| #pragma once | ||
|
|
||
| #include <optional> | ||
| #include <span> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <vector> | ||
|
|
||
| #include <sparrow/arrow_interface/arrow_array_schema_proxy.hpp> | ||
| #include <sparrow/date_array.hpp> | ||
| #include <sparrow/time_array.hpp> | ||
| #include <sparrow/timestamp_array.hpp> | ||
| #include <sparrow/timestamp_without_timezone_array.hpp> | ||
|
|
||
| #include "Message_generated.h" | ||
| #include "sparrow_ipc/deserialize_array_impl.hpp" | ||
|
|
||
| namespace sparrow_ipc | ||
| { | ||
| template <typename T> | ||
| [[nodiscard]] sparrow::date_array<T> deserialize_non_owning_date_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::date_array, T>( | ||
| record_batch, | ||
| body, | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index, | ||
| std::nullopt | ||
| ); | ||
| } | ||
|
|
||
| template <typename T> | ||
| [[nodiscard]] sparrow::timestamp_array<T> deserialize_non_owning_timestamp_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& timezone | ||
| ) | ||
| { | ||
| std::string format = std::string(data_type_to_format( | ||
| sparrow::detail::get_data_type_from_array<sparrow::timestamp_array<T>>::get() | ||
| )) + timezone; | ||
|
|
||
| return detail::deserialize_non_owning_simple_array<sparrow::timestamp_array, T>( | ||
| record_batch, | ||
| body, | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index, | ||
| std::move(format) | ||
| ); | ||
| } | ||
|
|
||
| template <typename T> | ||
| [[nodiscard]] sparrow::timestamp_without_timezone_array<T> deserialize_non_owning_timestamp_without_timezone_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::timestamp_without_timezone_array, T>( | ||
| record_batch, | ||
| body, | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index, | ||
| std::nullopt | ||
| ); | ||
| } | ||
|
|
||
| template <typename T> | ||
| [[nodiscard]] sparrow::time_array<T> deserialize_non_owning_time_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::time_array, T>( | ||
| record_batch, | ||
| body, | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index, | ||
| std::nullopt | ||
| ); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| #include "sparrow_ipc/deserialize.hpp" | ||
|
|
||
| #include <sparrow/types/data_type.hpp> | ||
|
|
@@ -8,6 +8,7 @@ | |
| #include "sparrow_ipc/deserialize_interval_array.hpp" | ||
| #include "sparrow_ipc/deserialize_null_array.hpp" | ||
| #include "sparrow_ipc/deserialize_primitive_array.hpp" | ||
| #include "sparrow_ipc/deserialize_time_related_arrays.hpp" | ||
| #include "sparrow_ipc/deserialize_variable_size_binary_array.hpp" | ||
| #include "sparrow_ipc/encapsulated_message.hpp" | ||
| #include "sparrow_ipc/magic_values.hpp" | ||
|
|
@@ -81,7 +82,7 @@ | |
| for (const auto field : *(schema.fields())) | ||
| { | ||
| const ::flatbuffers::Vector<::flatbuffers::Offset<org::apache::arrow::flatbuf::KeyValue>>* | ||
| fb_custom_metadata = field->custom_metadata(); | ||
| const std::optional<std::vector<sparrow::metadata_pair>>& metadata = field_metadata[field_idx++]; | ||
| const std::string name = field->name() == nullptr ? "" : field->name()->str(); | ||
| const bool nullable = field->nullable(); | ||
|
|
@@ -98,6 +99,56 @@ | |
| buffer_index | ||
| ); | ||
| }; | ||
|
|
||
| const auto deserialize_non_owning_date_array_lambda = [&]<typename T>() | ||
| { | ||
| return deserialize_non_owning_date_array<T>( | ||
| record_batch, | ||
| encapsulated_message.body(), | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index | ||
| ); | ||
| }; | ||
|
|
||
| const auto deserialize_non_owning_timestamp_array_lambda = [&]<typename T>(const std::string& timezone) | ||
| { | ||
| return deserialize_non_owning_timestamp_array<T>( | ||
| record_batch, | ||
| encapsulated_message.body(), | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index, | ||
| timezone | ||
| ); | ||
| }; | ||
|
|
||
| const auto deserialize_non_owning_timestamp_without_timezone_array_lambda = [&]<typename T>() | ||
| { | ||
| return deserialize_non_owning_timestamp_without_timezone_array<T>( | ||
| record_batch, | ||
| encapsulated_message.body(), | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index | ||
| ); | ||
| }; | ||
|
|
||
| const auto deserialize_non_owning_time_array_lambda = [&]<typename T>() | ||
| { | ||
| return deserialize_non_owning_time_array<T>( | ||
| record_batch, | ||
| encapsulated_message.body(), | ||
| name, | ||
| metadata, | ||
| nullable, | ||
| buffer_index | ||
| ); | ||
| }; | ||
|
|
||
| switch (field_type) | ||
| { | ||
| case org::apache::arrow::flatbuf::Type::Bool: | ||
|
|
@@ -336,6 +387,87 @@ | |
| } | ||
| } | ||
| break; | ||
| case org::apache::arrow::flatbuf::Type::Timestamp: | ||
|
Member
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 swith start to be a bit big. We should create functions for each of the types. Let's do that in another PR |
||
| { | ||
| const auto timestamp_type = field->type_as_Timestamp(); | ||
| const auto time_unit = timestamp_type->unit(); | ||
| const bool has_timezone = timestamp_type->timezone() != nullptr; | ||
|
|
||
| if (has_timezone) | ||
| { | ||
| const std::string timezone = timestamp_type->timezone()->str(); | ||
| switch (time_unit) | ||
| { | ||
| case org::apache::arrow::flatbuf::TimeUnit::SECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_array_lambda.template operator()<sparrow::timestamp_second>(timezone)); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::MILLISECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_array_lambda.template operator()<sparrow::timestamp_millisecond>(timezone)); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::MICROSECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_array_lambda.template operator()<sparrow::timestamp_microsecond>(timezone)); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::NANOSECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_array_lambda.template operator()<sparrow::timestamp_nanosecond>(timezone)); | ||
| break; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| switch (time_unit) | ||
| { | ||
| case org::apache::arrow::flatbuf::TimeUnit::SECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_without_timezone_array_lambda.template operator()<sparrow::zoned_time_without_timezone_seconds>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::MILLISECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_without_timezone_array_lambda.template operator()<sparrow::zoned_time_without_timezone_milliseconds>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::MICROSECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_without_timezone_array_lambda.template operator()<sparrow::zoned_time_without_timezone_microseconds>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::NANOSECOND: | ||
| arrays.emplace_back(deserialize_non_owning_timestamp_without_timezone_array_lambda.template operator()<sparrow::zoned_time_without_timezone_nanoseconds>()); | ||
| break; | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| case org::apache::arrow::flatbuf::Type::Date: | ||
| { | ||
| const auto date_type = field->type_as_Date(); | ||
| const auto date_unit = date_type->unit(); | ||
| switch (date_unit) | ||
| { | ||
| case org::apache::arrow::flatbuf::DateUnit::DAY: | ||
| arrays.emplace_back(deserialize_non_owning_date_array_lambda.template operator()<sparrow::date_days>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::DateUnit::MILLISECOND: | ||
| arrays.emplace_back(deserialize_non_owning_date_array_lambda.template operator()<sparrow::date_milliseconds>()); | ||
| break; | ||
| } | ||
| break; | ||
| } | ||
| case org::apache::arrow::flatbuf::Type::Time: | ||
| { | ||
| const auto time_type = field->type_as_Time(); | ||
| const auto time_unit = time_type->unit(); | ||
| switch (time_unit) | ||
| { | ||
| case org::apache::arrow::flatbuf::TimeUnit::SECOND: | ||
| arrays.emplace_back(deserialize_non_owning_time_array_lambda.template operator()<sparrow::chrono::time_seconds>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::MILLISECOND: | ||
| arrays.emplace_back(deserialize_non_owning_time_array_lambda.template operator()<sparrow::chrono::time_milliseconds>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::MICROSECOND: | ||
| arrays.emplace_back(deserialize_non_owning_time_array_lambda.template operator()<sparrow::chrono::time_microseconds>()); | ||
| break; | ||
| case org::apache::arrow::flatbuf::TimeUnit::NANOSECOND: | ||
| arrays.emplace_back(deserialize_non_owning_time_array_lambda.template operator()<sparrow::chrono::time_nanoseconds>()); | ||
| break; | ||
| } | ||
| break; | ||
| } | ||
| case org::apache::arrow::flatbuf::Type::Null: | ||
| arrays.emplace_back(deserialize_non_owning_null( | ||
| record_batch, | ||
|
|
@@ -351,7 +483,7 @@ | |
| const auto decimal_field = field->type_as_Decimal(); | ||
| const auto scale = decimal_field->scale(); | ||
| const auto precision = decimal_field->precision(); | ||
| if (decimal_field->bitWidth() == 32) | ||
| { | ||
| arrays.emplace_back( | ||
| deserialize_non_owning_decimal<sparrow::decimal<int32_t>>( | ||
|
|
@@ -366,7 +498,7 @@ | |
| ) | ||
| ); | ||
| } | ||
| else if (decimal_field->bitWidth() == 64) | ||
| { | ||
| arrays.emplace_back( | ||
| deserialize_non_owning_decimal<sparrow::decimal<int64_t>>( | ||
|
|
@@ -381,7 +513,7 @@ | |
| ) | ||
| ); | ||
| } | ||
| else if (decimal_field->bitWidth() == 128) | ||
| { | ||
| arrays.emplace_back( | ||
| deserialize_non_owning_decimal<sparrow::decimal<sparrow::int128_t>>( | ||
|
|
||
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.
Why is in the hpp now ?