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

[NSE-661] Add trim expression support in WSCG #664

Merged
merged 3 commits into from
Dec 30, 2021
Merged
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 @@ -289,6 +289,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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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