This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
[NSE-183] add Timestamp in native side #184
Closed
+205
−32
Closed
Changes from all commits
Commits
Show all changes
3 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 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 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 |
---|---|---|
|
@@ -87,6 +87,10 @@ using is_number_or_date = std::integral_constant<bool, arrow::is_number_type<T>: | |
template <typename DataType, typename R = void> | ||
using enable_if_number_or_date = std::enable_if_t<is_number_or_date<DataType>::value, R>; | ||
|
||
template <typename DataType, typename R = void> | ||
using enable_if_timestamp = | ||
std::enable_if_t<arrow::is_timestamp_type<DataType>::value, R>; | ||
|
||
template <typename DataType> | ||
class ArrayAppender<DataType, enable_if_number_or_date<DataType>> : public AppenderBase { | ||
public: | ||
|
@@ -150,7 +154,10 @@ class ArrayAppender<DataType, enable_if_number_or_date<DataType>> : public Appen | |
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status AppendNull() override { return builder_->AppendNull(); } | ||
arrow::Status AppendNull() override { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Finish(std::shared_ptr<arrow::Array>* out_) override { | ||
auto status = builder_->Finish(out_); | ||
|
@@ -237,7 +244,10 @@ class ArrayAppender<DataType, arrow::enable_if_string_like<DataType>> | |
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status AppendNull() override { return builder_->AppendNull(); } | ||
arrow::Status AppendNull() override { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Finish(std::shared_ptr<arrow::Array>* out_) override { | ||
auto status = builder_->Finish(out_); | ||
|
@@ -322,7 +332,10 @@ class ArrayAppender<DataType, arrow::enable_if_boolean<DataType>> : public Appen | |
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status AppendNull() override { return builder_->AppendNull(); } | ||
arrow::Status AppendNull() override { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status AppendExistence(bool is_exist) { return builder_->Append(is_exist); } | ||
|
||
|
@@ -406,7 +419,97 @@ class ArrayAppender<DataType, enable_if_decimal<DataType>> : public AppenderBase | |
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status AppendNull() override { return builder_->AppendNull(); } | ||
arrow::Status AppendNull() override { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Finish(std::shared_ptr<arrow::Array>* out_) override { | ||
auto status = builder_->Finish(out_); | ||
return status; | ||
} | ||
|
||
arrow::Status Reset() override { | ||
builder_->Reset(); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
private: | ||
using BuilderType_ = typename arrow::TypeTraits<DataType>::BuilderType; | ||
using ArrayType_ = typename arrow::TypeTraits<DataType>::ArrayType; | ||
std::unique_ptr<BuilderType_> builder_; | ||
std::vector<std::shared_ptr<ArrayType_>> cached_arr_; | ||
arrow::compute::ExecContext* ctx_; | ||
AppenderType type_; | ||
bool has_null_ = false; | ||
}; | ||
|
||
template <typename DataType> | ||
class ArrayAppender<DataType, enable_if_timestamp<DataType>> : public AppenderBase { | ||
public: | ||
ArrayAppender(arrow::compute::ExecContext* ctx, AppenderType type = left) | ||
: ctx_(ctx), type_(type) { | ||
std::unique_ptr<arrow::ArrayBuilder> array_builder; | ||
arrow::MakeBuilder(ctx_->memory_pool(), arrow::int64(), &array_builder); | ||
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. @zhouyuan this is because TimestampType does not contain "arrow::TypeTraits::type_singleton()", so it is separated out. |
||
builder_.reset(arrow::internal::checked_cast<BuilderType_*>(array_builder.release())); | ||
} | ||
~ArrayAppender() {} | ||
|
||
AppenderType GetType() override { return type_; } | ||
arrow::Status AddArray(const std::shared_ptr<arrow::Array>& arr) override { | ||
auto typed_arr_ = std::dynamic_pointer_cast<ArrayType_>(arr); | ||
cached_arr_.emplace_back(typed_arr_); | ||
if (typed_arr_->null_count() > 0) has_null_ = true; | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status PopArray() override { | ||
cached_arr_.pop_back(); | ||
has_null_ = false; | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Append(const uint16_t& array_id, const uint16_t& item_id) override { | ||
if (has_null_ && cached_arr_[array_id]->null_count() > 0 && | ||
cached_arr_[array_id]->IsNull(item_id)) { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
} else { | ||
RETURN_NOT_OK(builder_->Append(cached_arr_[array_id]->GetView(item_id))); | ||
} | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Append(const uint16_t& array_id, const uint16_t& item_id, | ||
int repeated) override { | ||
if (repeated == 0) return arrow::Status::OK(); | ||
if (has_null_ && cached_arr_[array_id]->null_count() > 0 && | ||
cached_arr_[array_id]->IsNull(item_id)) { | ||
RETURN_NOT_OK(builder_->AppendNulls(repeated)); | ||
} else { | ||
auto val = cached_arr_[array_id]->GetView(item_id); | ||
std::vector<CType> values; | ||
values.resize(repeated, val); | ||
RETURN_NOT_OK(builder_->AppendValues(values.data(), repeated)); | ||
} | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Append(const std::vector<ArrayItemIndex>& index_list) { | ||
for (auto tmp : index_list) { | ||
if (has_null_ && cached_arr_[tmp.array_id]->null_count() > 0 && | ||
cached_arr_[tmp.array_id]->IsNull(tmp.id)) { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
} else { | ||
RETURN_NOT_OK(builder_->Append(cached_arr_[tmp.array_id]->GetView(tmp.id))); | ||
} | ||
} | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status AppendNull() override { | ||
RETURN_NOT_OK(builder_->AppendNull()); | ||
return arrow::Status::OK(); | ||
} | ||
|
||
arrow::Status Finish(std::shared_ptr<arrow::Array>* out_) override { | ||
auto status = builder_->Finish(out_); | ||
|
@@ -421,6 +524,7 @@ class ArrayAppender<DataType, enable_if_decimal<DataType>> : public AppenderBase | |
private: | ||
using BuilderType_ = typename arrow::TypeTraits<DataType>::BuilderType; | ||
using ArrayType_ = typename arrow::TypeTraits<DataType>::ArrayType; | ||
using CType = typename arrow::TypeTraits<DataType>::CType; | ||
std::unique_ptr<BuilderType_> builder_; | ||
std::vector<std::shared_ptr<ArrayType_>> cached_arr_; | ||
arrow::compute::ExecContext* ctx_; | ||
|
@@ -442,7 +546,8 @@ class ArrayAppender<DataType, enable_if_decimal<DataType>> : public AppenderBase | |
PROCESS(arrow::DoubleType) \ | ||
PROCESS(arrow::Date32Type) \ | ||
PROCESS(arrow::Date64Type) \ | ||
PROCESS(arrow::StringType) | ||
PROCESS(arrow::StringType) \ | ||
PROCESS(arrow::TimestampType) | ||
static arrow::Status MakeAppender(arrow::compute::ExecContext* ctx, | ||
std::shared_ptr<arrow::DataType> type, | ||
AppenderBase::AppenderType appender_type, | ||
|
This file contains 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 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 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 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 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 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 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 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 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.
it looks like we could merge this with number, date, decimal?