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

Commit

Permalink
[NSE-1144] Optimize cast wscg performance (#1145)
Browse files Browse the repository at this point in the history
* optimize cast wscg performance

* add missing headers
  • Loading branch information
jackylee-ch authored Oct 25, 2022
1 parent d8fe25b commit c947bd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -669,22 +669,11 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node)
<< ";" << std::endl;
prepare_ss << "if (" << validity << ") {" << std::endl;

std::string func_str;
if (func_name.compare("castINTOrNull") == 0) {
func_str = " = std::stoi";
} else if (func_name.compare("castBIGINTOrNull") == 0) {
func_str = " = std::stol";
} else if (func_name.compare("castFLOAT4OrNull") == 0) {
func_str = " = std::stof";
} else {
func_str = " = std::stod";
}
prepare_ss << "try {" << std::endl;
prepare_ss << codes_str_ << func_str << "(" << child_visitor_list[0]->GetResult()
<< ");" << std::endl;
prepare_ss << "} catch (std::invalid_argument) {" << std::endl;
prepare_ss << validity << " = false;" << std::endl;
prepare_ss << "} catch (std::out_of_range) {" << std::endl;
prepare_ss << "if (!arrow::internal::ParseValue<arrow::"
<< GetTypeString(node.return_type(), "Type") << ">("
<< child_visitor_list[0]->GetResult() << ".data(), "
<< child_visitor_list[0]->GetResult() << ".length(), "
<< "&" << codes_str_ << ")) {" << std::endl;
prepare_ss << validity << " = false;" << std::endl;
prepare_ss << "}" << std::endl;
prepare_ss << "}" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions native-sql-engine/cpp/src/precompile/wscgapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <arrow/buffer.h>
#include <arrow/compute/api.h>
#include <arrow/record_batch.h>
#include <arrow/util/value_parsing.h>

#include <algorithm>
#include <cmath>
Expand Down

0 comments on commit c947bd1

Please sign in to comment.