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

[NSE-675] Add instr expression support #676

Merged
merged 2 commits into from
Jan 6, 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 @@ -95,6 +95,22 @@ class ColumnarGetJsonObject(left: Expression, right: Expression, original: GetJs
}
}

class ColumnarStringInstr(left: Expression, right: Expression, original: StringInstr)
extends StringInstr(original.str, original.substr) with ColumnarExpression with Logging {

override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = {
val (left_node, _): (TreeNode, ArrowType) =
left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (right_node, _): (TreeNode, ArrowType) =
right.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val resultType = CodeGeneration.getResultType(dataType)
// Be careful about the argument order.
val funcNode = TreeBuilder.makeFunction("locate",
Lists.newArrayList(right_node, left_node,
TreeBuilder.makeLiteral(1.asInstanceOf[java.lang.Integer])), resultType)
(funcNode, resultType)
}
}

object ColumnarBinaryExpression {

Expand All @@ -116,6 +132,8 @@ object ColumnarBinaryExpression {
new ColumnarDateSub(left, right)
case g: GetJsonObject =>
new ColumnarGetJsonObject(left, right, g)
case instr: StringInstr =>
new ColumnarStringInstr(left, right, instr)
case other =>
throw new UnsupportedOperationException(s"not currently supported: $other.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,31 @@ 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("instr") == 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 << "auto ind = " << child_visitor_list[0]->GetResult() << ".find("
<< child_visitor_list[1]->GetResult() << ");" << std::endl;
prepare_ss << "if (ind == std::string::npos) {" << std::endl;
prepare_ss << codes_str_ << " = 0;" << std::endl;
prepare_ss << "}" << std::endl;
prepare_ss << "else {" << std::endl;
prepare_ss << codes_str_ << " = ind + 1;" << std::endl;
prepare_ss << "}" << 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("btrim") == 0) {
codes_str_ = func_name + "_" + std::to_string(cur_func_id);
auto validity = codes_str_ + "_validity";
Expand Down