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

Commit

Permalink
[NSE-661] Add trim expression support in WSCG (#664)
Browse files Browse the repository at this point in the history
* Add trim expression support in WSCG

* Fix a bug

* Format the code
  • Loading branch information
PHILO-HE authored Dec 30, 2021
1 parent 240cc52 commit 946a1db
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node)
prepare_ss << "if (" << check_str_ << ")" << std::endl;
prepare_ss << codes_str_ << " = " << ss.str() << ";" << std::endl;
prepare_str_ += prepare_ss.str();
} else if (func_name.compare("btrim") == 0) {
codes_str_ = func_name + "_" + std::to_string(cur_func_id);
auto validity = codes_str_ + "_validity";
real_codes_str_ = codes_str_;
real_validity_str_ = validity;
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 << "std::string arg = " << child_visitor_list[0]->GetResult() << ";"
<< std::endl;
prepare_ss << "int start_index = 0, end_index = arg.length() - 1;" << std::endl;
prepare_ss << "while (start_index <= end_index && arg[start_index] == ' ') {"
<< std::endl;
prepare_ss << "start_index++;" << std::endl;
prepare_ss << "}" << std::endl;
prepare_ss << "while (end_index >= start_index && arg[end_index] == ' ') {"
<< std::endl;
prepare_ss << "end_index--;" << std::endl;
prepare_ss << "}" << std::endl;
prepare_ss << codes_str_ << " = arg.substr(start_index, end_index - start_index + 1);"
<< 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;

} else if (func_name.compare("upper") == 0) {
std::stringstream prepare_ss;
auto child_name = child_visitor_list[0]->GetResult();
Expand Down

0 comments on commit 946a1db

Please sign in to comment.