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

Commit

Permalink
support normalize function in WSCG
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Apr 19, 2021
1 parent 442a321 commit 8d0df5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,27 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node)
}
prepare_str_ += prepare_ss.str();
check_str_ = validity;
} else if (func_name.compare("normalize") == 0) {
codes_str_ = "normalize_" + std::to_string(cur_func_id);
auto validity = codes_str_ + "_validity";
std::stringstream fix_ss;
fix_ss << "normalize_nan_zero(" << child_visitor_list[0]->GetResult() << ")";
std::stringstream prepare_ss;
prepare_ss << GetCTypeString(node.return_type()) << " " << codes_str_ << ";"
<< std::endl;
prepare_ss << "bool " << validity << " = " << child_visitor_list[0]->GetPreCheck()
<< ";" << std::endl;
prepare_ss << "if (" << validity << ") {" << std::endl;
prepare_ss << codes_str_ << " = (" << GetCTypeString(node.return_type()) << ")"
<< fix_ss.str() << ";" << std::endl;
prepare_ss << "}" << std::endl;

for (int i = 0; i < 1; i++) {
prepare_str_ += child_visitor_list[i]->GetPrepare();
}
prepare_str_ += prepare_ss.str();
check_str_ = validity;
header_list_.push_back(R"(#include "precompile/gandiva.h")");
} else {
return arrow::Status::NotImplemented(func_name, " is currently not supported.");
}
Expand Down
10 changes: 10 additions & 0 deletions native-sql-engine/cpp/src/precompile/gandiva.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ bool equal_with_nan(double left, double right) {
return left == right;
}

double normalize_nan_zero(double in) {
if (std::isnan(in)) {
return 0.0 / 0.0;
} else if (in < 0 && std::abs(in) < 0.0000001) {
return 0.0;
} else {
return in;
}
}

arrow::Decimal128 round(arrow::Decimal128 in, int32_t original_precision,
int32_t original_scale, bool* overflow_, int32_t res_scale = 2) {
bool overflow = false;
Expand Down

0 comments on commit 8d0df5f

Please sign in to comment.