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

Commit

Permalink
[NSE-170]improve sort shuffle code (#171)
Browse files Browse the repository at this point in the history
* improve sort shuffle code

Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>

* fix format

Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>

* pass by ref in builder

Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>

* fix string/decimal builder

Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
  • Loading branch information
zhouyuan authored Mar 19, 2021
1 parent b3ab08c commit 698a383
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node)
} else {
auto childNode = node.children().at(0);
auto childType =
std::dynamic_pointer_cast<arrow::Decimal128Type>(childNode->return_type());
fix_ss << "round(" << child_visitor_list[0]->GetResult() << ", "
std::dynamic_pointer_cast<arrow::Decimal128Type>(childNode->return_type());
fix_ss << "round(" << child_visitor_list[0]->GetResult() << ", "
<< childType->precision() << ", " << childType->scale() << ", &overflow";
}
if (child_visitor_list.size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,12 @@ extern "C" void MakeCodeGen(arrow::compute::ExecContext* ctx,
auto length = (total_length_ - offset_) > batch_size_ ? batch_size_
: (total_length_ - offset_);
uint64_t count = 0;
while (count < length) {
auto item = indices_begin_ + offset_ + count++;
for (int i = 0; i < col_num_; i++) {
for (int i = 0; i < col_num_; i++) {
while (count < length) {
auto item = indices_begin_ + offset_ + count++;
RETURN_NOT_OK(appender_list_[i]->Append(item->array_id, item->id));
}
count = 0;
}
offset_ += length;
ArrayList arrays;
Expand Down
8 changes: 4 additions & 4 deletions native-sql-engine/cpp/src/precompile/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace precompile {
}; \
\
TYPENAME::TYPENAME(arrow::MemoryPool* pool) { impl_ = std::make_shared<Impl>(pool); } \
arrow::Status TYPENAME::Append(CTYPE value) { return impl_->Append(value); } \
arrow::Status TYPENAME::Append(const CTYPE& value) { return impl_->Append(value); } \
arrow::Status TYPENAME::AppendNull() { return impl_->AppendNull(); } \
arrow::Status TYPENAME::Reserve(int64_t length) { return impl_->Reserve(length); } \
arrow::Status TYPENAME::AppendNulls(int64_t length) { \
Expand Down Expand Up @@ -69,10 +69,10 @@ class StringBuilder::Impl : public arrow::StringBuilder {
StringBuilder::StringBuilder(arrow::MemoryPool* pool) {
impl_ = std::make_shared<Impl>(pool);
}
arrow::Status StringBuilder::Append(arrow::util::string_view value) {
arrow::Status StringBuilder::Append(const arrow::util::string_view& value) {
return impl_->Append(value);
}
arrow::Status StringBuilder::AppendString(std::string value) {
arrow::Status StringBuilder::AppendString(const std::string& value) {
return impl_->Append(arrow::util::string_view(value));
}
arrow::Status StringBuilder::AppendNull() { return impl_->AppendNull(); }
Expand All @@ -94,7 +94,7 @@ Decimal128Builder::Decimal128Builder(std::shared_ptr<arrow::DataType> type,
arrow::MemoryPool* pool) {
impl_ = std::make_shared<Impl>(type, pool);
}
arrow::Status Decimal128Builder::Append(arrow::Decimal128 value) {
arrow::Status Decimal128Builder::Append(const arrow::Decimal128& value) {
return impl_->Append(value);
}
arrow::Status Decimal128Builder::AppendNull() { return impl_->AppendNull(); }
Expand Down
8 changes: 4 additions & 4 deletions native-sql-engine/cpp/src/precompile/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace precompile {
class TYPENAME { \
public: \
TYPENAME(arrow::MemoryPool* pool); \
arrow::Status Append(TYPE val); \
arrow::Status Append(const TYPE& val); \
arrow::Status AppendNull(); \
arrow::Status Reserve(int64_t); \
arrow::Status AppendNulls(int64_t); \
Expand Down Expand Up @@ -53,8 +53,8 @@ TYPED_BUILDER_DEFINE(Date64Builder, int64_t)
class StringBuilder {
public:
StringBuilder(arrow::MemoryPool* pool);
arrow::Status Append(arrow::util::string_view val);
arrow::Status AppendString(std::string val);
arrow::Status Append(const arrow::util::string_view& val);
arrow::Status AppendString(const std::string& val);
arrow::Status AppendNull();
arrow::Status Finish(std::shared_ptr<arrow::Array>* out);
arrow::Status Reset();
Expand All @@ -67,7 +67,7 @@ class StringBuilder {
class Decimal128Builder {
public:
Decimal128Builder(std::shared_ptr<arrow::DataType> type, arrow::MemoryPool* pool);
arrow::Status Append(arrow::Decimal128 val);
arrow::Status Append(const arrow::Decimal128& val);
arrow::Status AppendNull();
arrow::Status Reserve(int64_t);
arrow::Status AppendNulls(int64_t);
Expand Down
11 changes: 4 additions & 7 deletions native-sql-engine/cpp/src/precompile/gandiva.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,12 @@ bool equal_with_nan(double left, double right) {
return left == right;
}

arrow::Decimal128 round(arrow::Decimal128 in,
int32_t original_precision,
int32_t original_scale,
bool* overflow_,
int32_t res_scale = 2) {
arrow::Decimal128 round(arrow::Decimal128 in, int32_t original_precision,
int32_t original_scale, bool* overflow_, int32_t res_scale = 2) {
bool overflow = false;
gandiva::BasicDecimalScalar128 val(in, original_precision, original_scale);
auto out = gandiva::decimalops::Round(val, original_precision, res_scale,
res_scale, &overflow);
auto out = gandiva::decimalops::Round(val, original_precision, res_scale, res_scale,
&overflow);
if (overflow) {
*overflow_ = true;
}
Expand Down

0 comments on commit 698a383

Please sign in to comment.