Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[NSE-97] optimize null check and refactor sort kernels #112

Merged
merged 6 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions cpp/src/codegen/arrow_compute/ext/array_appender.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ArrayAppender {};

template <typename T>
using is_number_or_date = std::integral_constant<bool, arrow::is_number_type<T>::value ||
arrow::is_date_type<T>::value>;
arrow::is_date_type<T>::value>;

template <typename DataType, typename R = void>
using enable_if_number_or_date = std::enable_if_t<is_number_or_date<DataType>::value, R>;
Expand Down Expand Up @@ -111,7 +111,8 @@ class ArrayAppender<DataType, enable_if_number_or_date<DataType>> : public Appen
}

arrow::Status Append(const uint16_t& array_id, const uint16_t& item_id) override {
if (has_null_ && cached_arr_[array_id]->IsNull(item_id)) {
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)));
Expand All @@ -122,7 +123,8 @@ class ArrayAppender<DataType, enable_if_number_or_date<DataType>> : public Appen
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]->IsNull(item_id)) {
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);
Expand All @@ -135,7 +137,8 @@ class ArrayAppender<DataType, enable_if_number_or_date<DataType>> : public Appen

arrow::Status Append(const std::vector<ArrayItemIndex>& index_list) {
for (auto tmp : index_list) {
if (has_null_ && cached_arr_[tmp.array_id]->IsNull(tmp.id)) {
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)));
Expand Down Expand Up @@ -195,7 +198,8 @@ class ArrayAppender<DataType, arrow::enable_if_string_like<DataType>>
}

arrow::Status Append(const uint16_t& array_id, const uint16_t& item_id) override {
if (has_null_ && cached_arr_[array_id]->IsNull(item_id)) {
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)));
Expand All @@ -206,7 +210,8 @@ class ArrayAppender<DataType, arrow::enable_if_string_like<DataType>>
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]->IsNull(item_id)) {
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);
Expand All @@ -219,7 +224,8 @@ class ArrayAppender<DataType, arrow::enable_if_string_like<DataType>>

arrow::Status Append(const std::vector<ArrayItemIndex>& index_list) {
for (auto tmp : index_list) {
if (has_null_ && cached_arr_[tmp.array_id]->IsNull(tmp.id)) {
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)));
Expand Down Expand Up @@ -277,7 +283,8 @@ class ArrayAppender<DataType, arrow::enable_if_boolean<DataType>> : public Appen
}

arrow::Status Append(const uint16_t& array_id, const uint16_t& item_id) override {
if (has_null_ && cached_arr_[array_id]->IsNull(item_id)) {
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)));
Expand All @@ -288,7 +295,8 @@ class ArrayAppender<DataType, arrow::enable_if_boolean<DataType>> : public Appen
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]->IsNull(item_id)) {
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);
Expand All @@ -301,7 +309,8 @@ class ArrayAppender<DataType, arrow::enable_if_boolean<DataType>> : public Appen

arrow::Status Append(const std::vector<ArrayItemIndex>& index_list) {
for (auto tmp : index_list) {
if (has_null_ && cached_arr_[tmp.array_id]->IsNull(tmp.id)) {
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)));
Expand Down
Loading