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

Commit

Permalink
[NSE-97] optimize null check and refactor sort kernels (#112)
Browse files Browse the repository at this point in the history
* remove null check if null count is zero

* refine memcopy in inplace sort

* refine append null

* refactor sort kernels

* use reference in comp function

* update notes
  • Loading branch information
rui-mo authored Feb 21, 2021
1 parent 79997bf commit df82b78
Show file tree
Hide file tree
Showing 2 changed files with 332 additions and 1,187 deletions.
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

0 comments on commit df82b78

Please sign in to comment.