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

[NSE-1144] Optimize cast wscg performance #1145

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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