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

Commit

Permalink
using from_chars instead of stoi/stod
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Zhou <[email protected]>
  • Loading branch information
zhouyuan committed Oct 24, 2022
1 parent 04fb798 commit f5b9a8f
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,27 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node)

std::string func_str;
if (func_name.compare("castINTOrNull") == 0) {
func_str = " = std::stoi";
// C++17 based from_chars
// std::from_chars(str.data(), str.data() + str.size(), result);
func_str = " = std::from_chars";
prepare_ss << "int result = 0" << std::endl;
} else if (func_name.compare("castBIGINTOrNull") == 0) {
func_str = " = std::stol";
// C++17 based from_chars
// std::from_chars(str.data(), str.data() + str.size(), result);
func_str = " = std::from_chars";
prepare_ss << "long int result = 0" << std::endl;
} else if (func_name.compare("castFLOAT4OrNull") == 0) {
func_str = " = std::stof";
func_str = " = ::arrow_vendored::fast_float::from_chars";
prepare_ss << "float result = 0" << std::endl;
} else {
func_str = " = std::stod";
func_str = " = ::arrow_vendored::fast_float::from_chars";
prepare_ss << "double result = 0" << std::endl;
}
prepare_ss << "try {" << std::endl;
prepare_ss << codes_str_ << func_str << "(" << child_visitor_list[0]->GetResult()
<< ");" << std::endl;
<< ".data(), " << child_visitor_list[0]->GetResult() << ".length(), "
<< "result);" << std::endl;
prepare_ss << codes_str_ << " = result;" << 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;
Expand Down

0 comments on commit f5b9a8f

Please sign in to comment.