diff --git a/core/src/main/scala/com/intel/oap/execution/ColumnarWholeStageCodegenExec.scala b/core/src/main/scala/com/intel/oap/execution/ColumnarWholeStageCodegenExec.scala index adb3df2f6..c515870b1 100644 --- a/core/src/main/scala/com/intel/oap/execution/ColumnarWholeStageCodegenExec.scala +++ b/core/src/main/scala/com/intel/oap/execution/ColumnarWholeStageCodegenExec.scala @@ -157,6 +157,13 @@ case class ColumnarWholeStageCodegenExec(child: SparkPlan)(val codegenStageId: I var idx = metrics.output_length_list.size - 1 var child_process_time: Long = 0 while (idx >= 0 && curChild.isInstanceOf[ColumnarCodegenSupport]) { + if (curChild.isInstanceOf[ColumnarConditionProjectExec]) { + // see if this condition projector did filter, if so, we need to skip metrics + val condProj = curChild.asInstanceOf[ColumnarConditionProjectExec] + if (condProj.condition != null && (condProj.projectList != null && condProj.projectList.size != 0)) { + idx -= 1 + } + } curChild .asInstanceOf[ColumnarCodegenSupport] .updateMetrics( diff --git a/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc b/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc index 07930d152..87d59b29f 100644 --- a/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc +++ b/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc @@ -232,8 +232,11 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node) codes_str_ = "substr_" + std::to_string(cur_func_id); check_str_ = GetValidityName(codes_str_); std::stringstream prepare_ss; - prepare_ss << "auto " << codes_str_ << " = " << ss.str() << ";" << std::endl; - prepare_ss << "bool " << check_str_ << " = true;" << std::endl; + prepare_ss << "std::string " << codes_str_ << ";" << std::endl; + prepare_ss << "bool " << check_str_ << " = " << child_visitor_list[0]->GetPreCheck() + << ";" << std::endl; + 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("upper") == 0) { std::stringstream prepare_ss; @@ -884,15 +887,21 @@ arrow::Status ExpressionCodegenVisitor::Visit( } prepare_ss << "};" << std::endl; - std::stringstream ss; - ss << child_visitor->GetPreCheck() << " && " - << "std::find(in_list_" << cur_func_id << ".begin(), in_list_" << cur_func_id - << ".end(), " << child_visitor->GetResult() << ") != " - << "in_list_" << cur_func_id << ".end()"; - codes_str_ = ss.str(); - prepare_str_ = prepare_ss.str(); + prepare_ss << child_visitor->GetPrepare(); + codes_str_ = "is_in_list_" + std::to_string(cur_func_id); + check_str_ = GetValidityName(codes_str_); + + prepare_ss << "bool " << check_str_ << " = " << child_visitor->GetPreCheck() << ";" + << std::endl; + prepare_ss << "bool " << codes_str_ << " = false;" << std::endl; + prepare_ss << "if (" << check_str_ << ") " << std::endl; + prepare_ss << codes_str_ << " = std::find(in_list_" << cur_func_id + << ".begin(), in_list_" << cur_func_id << ".end(), " + << child_visitor->GetResult() << ") != " + << "in_list_" << cur_func_id << ".end();"; + prepare_str_ += prepare_ss.str(); + field_type_ = child_visitor->GetFieldType(); - prepare_str_ += child_visitor->GetPrepare(); for (auto header : child_visitor->GetHeaders()) { if (std::find(header_list_.begin(), header_list_.end(), header) == header_list_.end()) { @@ -924,15 +933,21 @@ arrow::Status ExpressionCodegenVisitor::Visit( } prepare_ss << "};" << std::endl; - std::stringstream ss; - ss << child_visitor->GetPreCheck() << " && " - << "std::find(in_list_" << cur_func_id << ".begin(), in_list_" << cur_func_id - << ".end(), " << child_visitor->GetResult() << ") != " - << "in_list_" << cur_func_id << ".end()"; - codes_str_ = ss.str(); - prepare_str_ = prepare_ss.str(); + prepare_ss << child_visitor->GetPrepare(); + codes_str_ = "is_in_list_" + std::to_string(cur_func_id); + check_str_ = GetValidityName(codes_str_); + + prepare_ss << "bool " << check_str_ << " = " << child_visitor->GetPreCheck() << ";" + << std::endl; + prepare_ss << "bool " << codes_str_ << " = false;" << std::endl; + prepare_ss << "if (" << check_str_ << ") " << std::endl; + prepare_ss << codes_str_ << " = std::find(in_list_" << cur_func_id + << ".begin(), in_list_" << cur_func_id << ".end(), " + << child_visitor->GetResult() << ") != " + << "in_list_" << cur_func_id << ".end();"; + prepare_str_ += prepare_ss.str(); + field_type_ = child_visitor->GetFieldType(); - prepare_str_ += child_visitor->GetPrepare(); for (auto header : child_visitor->GetHeaders()) { if (std::find(header_list_.begin(), header_list_.end(), header) == header_list_.end()) { @@ -964,15 +979,21 @@ arrow::Status ExpressionCodegenVisitor::Visit( } prepare_ss << "};" << std::endl; - std::stringstream ss; - ss << child_visitor->GetPreCheck() << " && " - << "std::find(in_list_" << cur_func_id << ".begin(), in_list_" << cur_func_id - << ".end(), " << child_visitor->GetResult() << ") != " - << "in_list_" << cur_func_id << ".end()"; - codes_str_ = ss.str(); - prepare_str_ = prepare_ss.str(); + prepare_ss << child_visitor->GetPrepare(); + codes_str_ = "is_in_list_" + std::to_string(cur_func_id); + check_str_ = GetValidityName(codes_str_); + + prepare_ss << "bool " << check_str_ << " = " << child_visitor->GetPreCheck() << ";" + << std::endl; + prepare_ss << "bool " << codes_str_ << " = false;" << std::endl; + prepare_ss << "if (" << check_str_ << ") " << std::endl; + prepare_ss << codes_str_ << " = std::find(in_list_" << cur_func_id + << ".begin(), in_list_" << cur_func_id << ".end(), " + << child_visitor->GetResult() << ") != " + << "in_list_" << cur_func_id << ".end();"; + prepare_str_ += prepare_ss.str(); + field_type_ = child_visitor->GetFieldType(); - prepare_str_ += child_visitor->GetPrepare(); for (auto header : child_visitor->GetHeaders()) { if (std::find(header_list_.begin(), header_list_.end(), header) == header_list_.end()) {