diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_item_index.h b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_item_index.h index 8d5897a2d..4cc39bd10 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_item_index.h +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_item_index.h @@ -28,13 +28,6 @@ struct ArrayItemIndex { ArrayItemIndex() : array_id(0), id(0) {} ArrayItemIndex(uint16_t array_id, uint16_t id) : array_id(array_id), id(id) {} }; -struct ArrayItemIndexS { - uint16_t id = 0; - uint16_t array_id = 0; - ArrayItemIndexS() : array_id(0), id(0) {} - ArrayItemIndexS(uint16_t array_id, uint16_t id) : array_id(array_id), id(id) {} -}; - } // namespace extra } // namespace arrowcompute } // namespace codegen diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_taker.h b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_taker.h index 4c9704c2f..a05e08493 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_taker.h +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/array_taker.h @@ -53,7 +53,7 @@ class TakerBase { return arrow::Status::NotImplemented("TakerBase Finish is abstract."); } - virtual arrow::Status TakeFromIndices(ArrayItemIndexS* indices_begin, int64_t length, + virtual arrow::Status TakeFromIndices(ArrayItemIndex* indices_begin, int64_t length, std::shared_ptr* out) { return arrow::Status::NotImplemented("TakerBase TakeFromIndices is abstract."); } @@ -101,7 +101,7 @@ class ArrayTaker> : public T return arrow::Status::OK(); } - arrow::Status TakeFromIndices(ArrayItemIndexS* indices_begin, int64_t length, + arrow::Status TakeFromIndices(ArrayItemIndex* indices_begin, int64_t length, std::shared_ptr* out) { arrow::ArrayData out_data; out_data.length = length; @@ -181,7 +181,7 @@ class ArrayTaker> : public T return arrow::Status::OK(); } - arrow::Status TakeFromIndices(ArrayItemIndexS* indices_begin, int64_t length, + arrow::Status TakeFromIndices(ArrayItemIndex* indices_begin, int64_t length, std::shared_ptr* out) { arrow::ArrayData out_data; out_data.length = length; @@ -266,7 +266,7 @@ class ArrayTaker> : public TakerBas return arrow::Status::OK(); } - arrow::Status TakeFromIndices(ArrayItemIndexS* indices_begin, int64_t length, + arrow::Status TakeFromIndices(ArrayItemIndex* indices_begin, int64_t length, std::shared_ptr* out) { arrow::ArrayData out_data; out_data.length = length; @@ -352,7 +352,7 @@ class ArrayTaker* out) { for (int64_t position = 0; position < length; position++) { auto item = indices_begin + position; @@ -410,7 +410,7 @@ class ComplexArrayTaker : public TakerBase { return arrow::Status::OK(); } - arrow::Status TakeFromIndices(ArrayItemIndexS* indices_begin, int64_t length, + arrow::Status TakeFromIndices(ArrayItemIndex* indices_begin, int64_t length, std::shared_ptr* out) { for (int64_t position = 0; position < length; position++) { auto item = indices_begin + position; @@ -458,7 +458,7 @@ class ArrayTaker> : public TakerB return arrow::Status::OK(); } - arrow::Status TakeFromIndices(ArrayItemIndexS* indices_begin, int64_t length, + arrow::Status TakeFromIndices(ArrayItemIndex* indices_begin, int64_t length, std::shared_ptr* out) { arrow::ArrayData out_data; out_data.length = length; diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/conditioned_merge_join_kernel.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/conditioned_merge_join_kernel.cc index 0bf504f82..13d0250bb 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/conditioned_merge_join_kernel.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/conditioned_merge_join_kernel.cc @@ -246,11 +246,11 @@ class ConditionedMergeJoinKernel::Impl { auto function_name = "ConditionCheck_" + std::to_string(relation_id_[0]); if (use_relation_for_stream) { function_define_ss << "inline bool " << function_name - << "(ArrayItemIndexS idx_0, ArrayItemIndexS idx_1) {" + << "(ArrayItemIndex idx_0, ArrayItemIndex idx_1) {" << std::endl; } else { function_define_ss << "inline bool " << function_name - << "(ArrayItemIndexS idx_0) {" << std::endl; + << "(ArrayItemIndex idx_0) {" << std::endl; } function_define_ss << condition_node_visitor->GetPrepare() << std::endl; function_define_ss << "return " << condition_node_visitor->GetResult() << ";" @@ -346,11 +346,11 @@ class ConditionedMergeJoinKernel::Impl { << "->GetItemIndexWithShift(" << streamed_range_id << ");" << std::endl; std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << right_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << right_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); } std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << left_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << left_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); if (cache_right) { codes_ss << right_for_loop_codes.str(); @@ -435,11 +435,11 @@ class ConditionedMergeJoinKernel::Impl { << "->GetItemIndexWithShift(" << streamed_range_id << ");" << std::endl; std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << right_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << right_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); } std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << left_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << left_index_name << ";" << std::endl; prepare_ss << "bool " << fill_null_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); if (cache_right) { @@ -538,11 +538,11 @@ class ConditionedMergeJoinKernel::Impl { codes_ss << right_index_name << " = " << streamed_relation << "->GetItemIndexWithShift(" << streamed_range_id << ");" << std::endl; std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << right_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << right_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); } std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << left_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << left_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); codes_ss << "for (int " << range_id << " = 0; " << range_id << " < 1;" << range_id << "++) {" << std::endl; @@ -631,11 +631,11 @@ class ConditionedMergeJoinKernel::Impl { codes_ss << right_index_name << " = " << streamed_relation << "->GetItemIndexWithShift(" << streamed_range_id << ");" << std::endl; std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << right_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << right_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); } std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << left_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << left_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); codes_ss << "for (int " << range_id << " = 0; " << range_id << " < 1;" << range_id << "++) {" << std::endl; @@ -720,11 +720,11 @@ class ConditionedMergeJoinKernel::Impl { codes_ss << right_index_name << " = " << streamed_relation << "->GetItemIndexWithShift(" << streamed_range_id << ");" << std::endl; std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << right_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << right_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); } std::stringstream prepare_ss; - prepare_ss << "ArrayItemIndexS " << left_index_name << ";" << std::endl; + prepare_ss << "ArrayItemIndex " << left_index_name << ";" << std::endl; (*output)->definition_codes += prepare_ss.str(); codes_ss << "for (int " << range_id << " = 0; " << range_id << " < 1;" << range_id << "++) {" << std::endl; diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/sort_kernel.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/sort_kernel.cc index 46981a761..f7b4c8a88 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/sort_kernel.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/sort_kernel.cc @@ -237,7 +237,7 @@ class SortArraysToIndicesKernel::Impl { "SorterResultIterator received cache with " + std::to_string(cached.size()) + ", which does not match expected num_cols of " + std::to_string(col_num_)); } - indices_begin_ = (ArrayItemIndexS*)indices_in->value_data(); + indices_begin_ = (ArrayItemIndex*)indices_in->value_data(); for (int i = 0; i < col_num_; i++) { auto field = schema->field(i); std::shared_ptr taker; @@ -337,7 +337,7 @@ class SortArraysToIndicesKernel::Impl { arrow::compute::ExecContext* ctx_; uint64_t batch_size_; int col_num_; - ArrayItemIndexS* indices_begin_; + ArrayItemIndex* indices_begin_; std::vector> type_list_; std::vector> taker_list_; std::shared_ptr indices_in_cache_; @@ -1392,7 +1392,7 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { return arrow::Status::OK(); } - void PartitionNulls(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end) { + void PartitionNulls(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end) { int64_t indices_i = 0; int64_t indices_null = 0; @@ -1456,7 +1456,7 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { } } - int64_t PartitionNaNs(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end) { + int64_t PartitionNaNs(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end) { int64_t indices_i = 0; int64_t indices_nan = 0; @@ -1529,7 +1529,7 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { } template - auto Partition(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end, + auto Partition(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end, int64_t& num_nan) -> typename std::enable_if_t::value> { PartitionNulls(indices_begin, indices_end); @@ -1539,14 +1539,14 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { } template - auto Partition(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end, + auto Partition(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end, int64_t& num_nan) -> typename std::enable_if_t::value> { PartitionNulls(indices_begin, indices_end); } template - auto Sort(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end, int64_t num_nan) + auto Sort(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end, int64_t num_nan) -> typename std::enable_if_t::value> { if (asc_) { if (nulls_first_) { @@ -1561,7 +1561,7 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { }); } } else { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) > cached_key_[y.array_id]->GetView(y.id); }; @@ -1576,10 +1576,10 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { } template - auto Sort(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end, int64_t num_nan) + auto Sort(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end, int64_t num_nan) -> typename std::enable_if_t::value> { if (asc_) { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) < cached_key_[y.array_id]->GetView(y.id); }; @@ -1589,7 +1589,7 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { gfx::timsort(indices_begin, indices_begin + items_total_ - nulls_total_, comp); } } else { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) > cached_key_[y.array_id]->GetView(y.id); }; @@ -1602,10 +1602,10 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { } template - auto Sort(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end, int64_t num_nan) + auto Sort(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end, int64_t num_nan) -> typename std::enable_if_t::value> { if (asc_) { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) < cached_key_[y.array_id]->GetView(y.id); }; @@ -1617,7 +1617,7 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { comp); } } else { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) > cached_key_[y.array_id]->GetView(y.id); }; @@ -1634,19 +1634,19 @@ class SortOnekeyKernel : public SortArraysToIndicesKernel::Impl { arrow::Status FinishInternal(std::shared_ptr* out) { // initiate buffer for all arrays std::shared_ptr indices_buf; - int64_t buf_size = items_total_ * sizeof(ArrayItemIndexS); + int64_t buf_size = items_total_ * sizeof(ArrayItemIndex); auto maybe_buffer = arrow::AllocateBuffer(buf_size, ctx_->memory_pool()); indices_buf = *std::move(maybe_buffer); - ArrayItemIndexS* indices_begin = - reinterpret_cast(indices_buf->mutable_data()); - ArrayItemIndexS* indices_end = indices_begin + items_total_; + ArrayItemIndex* indices_begin = + reinterpret_cast(indices_buf->mutable_data()); + ArrayItemIndex* indices_end = indices_begin + items_total_; // do partition and sort here int64_t num_nan = 0; Partition(indices_begin, indices_end, num_nan); Sort(indices_begin, indices_end, num_nan); std::shared_ptr out_type; RETURN_NOT_OK( - MakeFixedSizeBinaryType(sizeof(ArrayItemIndexS) / sizeof(int32_t), &out_type)); + MakeFixedSizeBinaryType(sizeof(ArrayItemIndex) / sizeof(int32_t), &out_type)); RETURN_NOT_OK(MakeFixedSizeBinaryArray(out_type, items_total_, indices_buf, out)); return arrow::Status::OK(); @@ -2021,13 +2021,13 @@ class TypedSorterImpl : public CodeGenBase { R"( // initiate buffer for all arrays std::shared_ptr indices_buf; - int64_t buf_size = items_total_ * sizeof(ArrayItemIndexS); + int64_t buf_size = items_total_ * sizeof(ArrayItemIndex); auto maybe_buffer = arrow::AllocateBuffer(buf_size, ctx_->memory_pool()); indices_buf = *std::move(maybe_buffer); - ArrayItemIndexS* indices_begin = - reinterpret_cast(indices_buf->mutable_data()); - ArrayItemIndexS* indices_end = indices_begin + items_total_; + ArrayItemIndex* indices_begin = + reinterpret_cast(indices_buf->mutable_data()); + ArrayItemIndex* indices_end = indices_begin + items_total_; int64_t indices_i = 0; ARROW_CHECK_LE(num_batches_, 64 * 1024); @@ -2043,7 +2043,7 @@ class TypedSorterImpl : public CodeGenBase { )" + sort_func_str + R"( std::shared_ptr out_type; - RETURN_NOT_OK(MakeFixedSizeBinaryType(sizeof(ArrayItemIndexS) / sizeof(int32_t), &out_type)); + RETURN_NOT_OK(MakeFixedSizeBinaryType(sizeof(ArrayItemIndex) / sizeof(int32_t), &out_type)); RETURN_NOT_OK(MakeFixedSizeBinaryArray(out_type, items_total_, indices_buf, out)); return arrow::Status::OK(); } @@ -2110,13 +2110,13 @@ extern "C" void MakeCodeGen(arrow::compute::ExecContext* ctx, projected = false; } if (has_null) { - ss << "auto comp = [this](const ArrayItemIndexS& x, const " - "ArrayItemIndexS& y) {" + ss << "auto comp = [this](const ArrayItemIndex& x, const " + "ArrayItemIndex& y) {" << GetCompFunction_(0, projected, key_field_list_, projected_types_, sort_directions_, nulls_order_); } else { ss << "auto comp_without_null = " - << "[this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) {" + << "[this](const ArrayItemIndex& x, const ArrayItemIndex& y) {" << GetCompFunction_Without_Null_(0, projected, key_field_list_, projected_types_, sort_directions_); } @@ -2579,15 +2579,15 @@ class SortMultiplekeyKernel : public SortArraysToIndicesKernel::Impl { return arrow::Status::OK(); } - void Sort(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end) { + void Sort(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end) { int keys_num = sort_directions_.size(); - auto comp = [this, &keys_num](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this, &keys_num](const ArrayItemIndex& x, const ArrayItemIndex& y) { return compareRow(x.array_id, x.id, y.array_id, y.id, keys_num); }; gfx::timsort(indices_begin, indices_begin + items_total_, comp); } - void Partition(ArrayItemIndexS* indices_begin, ArrayItemIndexS* indices_end) { + void Partition(ArrayItemIndex* indices_begin, ArrayItemIndex* indices_end) { int64_t indices_i = 0; int64_t indices_null = 0; ARROW_CHECK_LE(num_batches_, 64 * 1024); @@ -2604,12 +2604,12 @@ class SortMultiplekeyKernel : public SortArraysToIndicesKernel::Impl { arrow::Status FinishInternal(std::shared_ptr* out) { // initiate buffer for all arrays std::shared_ptr indices_buf; - int64_t buf_size = items_total_ * sizeof(ArrayItemIndexS); + int64_t buf_size = items_total_ * sizeof(ArrayItemIndex); auto maybe_buffer = arrow::AllocateBuffer(buf_size, ctx_->memory_pool()); indices_buf = *std::move(maybe_buffer); - ArrayItemIndexS* indices_begin = - reinterpret_cast(indices_buf->mutable_data()); - ArrayItemIndexS* indices_end = indices_begin + items_total_; + ArrayItemIndex* indices_begin = + reinterpret_cast(indices_buf->mutable_data()); + ArrayItemIndex* indices_end = indices_begin + items_total_; // do partition and sort here Partition(indices_begin, indices_end); if (key_projector_) { @@ -2627,7 +2627,7 @@ class SortMultiplekeyKernel : public SortArraysToIndicesKernel::Impl { Sort(indices_begin, indices_end); std::shared_ptr out_type; RETURN_NOT_OK( - MakeFixedSizeBinaryType(sizeof(ArrayItemIndexS) / sizeof(int32_t), &out_type)); + MakeFixedSizeBinaryType(sizeof(ArrayItemIndex) / sizeof(int32_t), &out_type)); RETURN_NOT_OK(MakeFixedSizeBinaryArray(out_type, items_total_, indices_buf, out)); return arrow::Status::OK(); } diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/window_sort_kernel.h b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/window_sort_kernel.h index 63b635525..8a97162e4 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/window_sort_kernel.h +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/window_sort_kernel.h @@ -237,14 +237,14 @@ class TypedSorterImpl : public CodeGenBase { // initiate buffer for all arrays std::shared_ptr indices_buf; - int64_t buf_size = items_total * sizeof(ArrayItemIndexS); + int64_t buf_size = items_total * sizeof(ArrayItemIndex); auto maybe_buffer = arrow::AllocateBuffer(buf_size, ctx_->memory_pool()); indices_buf = *std::move(maybe_buffer); // start to partition not_null with null - ArrayItemIndexS* indices_begin = - reinterpret_cast(indices_buf->mutable_data()); - ArrayItemIndexS* indices_end = indices_begin + items_total; + ArrayItemIndex* indices_begin = + reinterpret_cast(indices_buf->mutable_data()); + ArrayItemIndex* indices_end = indices_begin + items_total; int64_t indices_i = 0; @@ -262,7 +262,7 @@ class TypedSorterImpl : public CodeGenBase { )" + sort_func_str + R"( std::shared_ptr out_type; - RETURN_NOT_OK(MakeFixedSizeBinaryType(sizeof(ArrayItemIndexS) / sizeof(int32_t), &out_type)); + RETURN_NOT_OK(MakeFixedSizeBinaryType(sizeof(ArrayItemIndex) / sizeof(int32_t), &out_type)); RETURN_NOT_OK(MakeFixedSizeBinaryArray(out_type, items_total, indices_buf, out)); return arrow::Status::OK(); } @@ -271,7 +271,7 @@ class TypedSorterImpl : public CodeGenBase { std::shared_ptr indices_out; RETURN_NOT_OK(FinishInternal(in, &indices_out)); arrow::UInt64Builder builder; - auto *index = (ArrayItemIndexS *) indices_out->value_data(); + auto *index = (ArrayItemIndex *) indices_out->value_data(); for (int i = 0; i < indices_out->length(); i++) { uint64_t encoded = ((uint64_t) (index->array_id) << 16U) ^ ((uint64_t) (index->id)); RETURN_NOT_OK(builder.Append(encoded)); @@ -295,7 +295,7 @@ class TypedSorterImpl : public CodeGenBase { R"(): ctx_(ctx), total_length_(indices_in->length()), indices_in_cache_(indices_in) { )" + result_iter_define_str + R"( - indices_begin_ = (ArrayItemIndexS*)indices_in->value_data(); + indices_begin_ = (ArrayItemIndex*)indices_in->value_data(); } std::string ToString() override { return "SortArraysToIndicesResultIterator"; } @@ -330,7 +330,7 @@ class TypedSorterImpl : public CodeGenBase { R"( std::shared_ptr indices_in_cache_; uint64_t offset_ = 0; - ArrayItemIndexS* indices_begin_; + ArrayItemIndex* indices_begin_; const uint64_t total_length_; std::shared_ptr result_schema_; arrow::compute::ExecContext* ctx_; @@ -354,7 +354,7 @@ extern "C" void MakeCodeGen(arrow::compute::ExecContext* ctx, } std::string GetCompFunction(std::vector sort_key_index_list) { std::stringstream ss; - ss << "auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& " + ss << "auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& " "y) {" << GetCompFunction_(0, sort_key_index_list) << "};"; return ss.str(); @@ -549,12 +549,12 @@ class WindowSortOnekeyKernel : public WindowSortKernel::Impl { } // initiate buffer for all arrays std::shared_ptr indices_buf; - int64_t buf_size = items_total * sizeof(ArrayItemIndexS); + int64_t buf_size = items_total * sizeof(ArrayItemIndex); auto maybe_buffer = arrow::AllocateBuffer(buf_size, ctx_->memory_pool()); indices_buf = *std::move(maybe_buffer); - ArrayItemIndexS* indices_begin = - reinterpret_cast(indices_buf->mutable_data()); - ArrayItemIndexS* indices_end = indices_begin + items_total; + ArrayItemIndex* indices_begin = + reinterpret_cast(indices_buf->mutable_data()); + ArrayItemIndex* indices_end = indices_begin + items_total; int64_t indices_i = 0; int64_t indices_null = 0; // we should support nulls first and nulls last here @@ -587,7 +587,7 @@ class WindowSortOnekeyKernel : public WindowSortKernel::Impl { } } if (asc_) { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) < cached_key_[y.array_id]->GetView(y.id); }; @@ -597,7 +597,7 @@ class WindowSortOnekeyKernel : public WindowSortKernel::Impl { gfx::timsort(indices_begin, indices_begin + items_total - nulls_total, comp); } } else { - auto comp = [this](const ArrayItemIndexS& x, const ArrayItemIndexS& y) { + auto comp = [this](const ArrayItemIndex& x, const ArrayItemIndex& y) { return cached_key_[x.array_id]->GetView(x.id) > cached_key_[y.array_id]->GetView(y.id); }; @@ -609,7 +609,7 @@ class WindowSortOnekeyKernel : public WindowSortKernel::Impl { } std::shared_ptr out_type; RETURN_NOT_OK( - MakeFixedSizeBinaryType(sizeof(ArrayItemIndexS) / sizeof(int32_t), &out_type)); + MakeFixedSizeBinaryType(sizeof(ArrayItemIndex) / sizeof(int32_t), &out_type)); RETURN_NOT_OK(MakeFixedSizeBinaryArray(out_type, items_total, indices_buf, out)); return arrow::Status::OK(); } @@ -619,7 +619,7 @@ class WindowSortOnekeyKernel : public WindowSortKernel::Impl { std::shared_ptr indices_out; RETURN_NOT_OK(FinishInternal(in, &indices_out)); arrow::UInt64Builder builder; - auto* index = (ArrayItemIndexS*)indices_out->value_data(); + auto* index = (ArrayItemIndex*)indices_out->value_data(); for (int i = 0; i < indices_out->length(); i++) { uint64_t encoded = ((uint64_t)(index->array_id) << 16U) ^ ((uint64_t)(index->id)); RETURN_NOT_OK(builder.Append(encoded)); diff --git a/native-sql-engine/cpp/src/codegen/common/sort_relation.h b/native-sql-engine/cpp/src/codegen/common/sort_relation.h index 33a921f13..78efa9e93 100644 --- a/native-sql-engine/cpp/src/codegen/common/sort_relation.h +++ b/native-sql-engine/cpp/src/codegen/common/sort_relation.h @@ -26,7 +26,7 @@ #include "codegen/common/relation_column.h" #include "precompile/type_traits.h" -using sparkcolumnarplugin::codegen::arrowcompute::extra::ArrayItemIndexS; +using sparkcolumnarplugin::codegen::arrowcompute::extra::ArrayItemIndex; using sparkcolumnarplugin::precompile::enable_if_number; using sparkcolumnarplugin::precompile::enable_if_string_like; using sparkcolumnarplugin::precompile::FixedSizeBinaryArray; @@ -50,10 +50,10 @@ class SortRelation { } if (!is_lazy_input_) { - int64_t buf_size = items_total_ * sizeof(ArrayItemIndexS); + int64_t buf_size = items_total_ * sizeof(ArrayItemIndex); auto maybe_buffer = arrow::AllocateBuffer(buf_size, ctx_->memory_pool()); indices_buf_ = *std::move(maybe_buffer); - indices_begin_ = reinterpret_cast(indices_buf_->mutable_data()); + indices_begin_ = reinterpret_cast(indices_buf_->mutable_data()); uint64_t idx = 0; int array_id = 0; for (auto size : size_array) { @@ -155,7 +155,7 @@ class SortRelation { } } - ArrayItemIndexS GetItemIndexWithShift(int shift) { + ArrayItemIndex GetItemIndexWithShift(int shift) { // std::cout << "DEBUG -> GetItemIndexWithShift: " << shift << std::endl; if (!is_lazy_input_) { return indices_begin_[offset_ + shift]; @@ -167,7 +167,7 @@ class SortRelation { int32_t requested_batches_0; if (shift == last_shifted_) { - ArrayItemIndexS s(shift_cache_aid_, shift_cache_rid_); + ArrayItemIndex s(shift_cache_aid_, shift_cache_rid_); return s; } else if (last_shifted_ >= 0 && shift > last_shifted_) { requested_batches_0 = shift_cache_aid_; @@ -182,7 +182,7 @@ class SortRelation { batch_remaining_0 = (batch_length_0 - 1) - offset_in_current_batch_0; if (shift_0 <= batch_remaining_0) { int64_t rid = offset_in_current_batch_0 + shift_0; - ArrayItemIndexS s(requested_batches_0, rid); + ArrayItemIndex s(requested_batches_0, rid); last_shifted_ = shift; shift_cache_aid_ = requested_batches_0; shift_cache_rid_ = rid; @@ -194,7 +194,7 @@ class SortRelation { int64_t current_batch_length = lazy_in_->GetNumRowsOfBatch(batch_i); if (remaining <= current_batch_length) { int64_t rid = remaining - 1; - ArrayItemIndexS s(batch_i, rid); + ArrayItemIndex s(batch_i, rid); last_shifted_ = shift; shift_cache_aid_ = batch_i; shift_cache_rid_ = rid; @@ -379,6 +379,6 @@ class SortRelation { int64_t rb_shift_cache_rid_ = -1; std::shared_ptr indices_buf_; - ArrayItemIndexS* indices_begin_; + ArrayItemIndex* indices_begin_; const uint64_t items_total_; };