From eb72c546ae2cb9d1967afc2ef0acc75b5d9c63a3 Mon Sep 17 00:00:00 2001 From: Mryange Date: Mon, 8 Dec 2025 15:11:57 +0800 Subject: [PATCH] [chore](exec) BE constant folding no longer needs to construct a temporary block (#58710) Also, this PR fixes a bug: previously BE constant folding did not pass whether casts should be performed in strict mode. ``` W20251205 13:32:09.197405 512888 internal_service.cpp:1608] exec fold constant expr failed, errmsg=[INTERNAL_ERROR]ColumnWithTypeAndName check column type failed, column name: (CAST String(String) TO IPv4), type: IPv4, column: Const(Nullable(IPV4)) , error: [INTERNAL_ERROR]Column type Const(Nullable(IPV4)) is not compatible with data type IPv4 0# doris::Status doris::vectorized::IDataType::check_column_non_nested_type >(doris::vectorized::IColumn const&) const at /root/doris/be/src/common/status.h:0 1# doris::vectorized::DataTypeNumberBase<(doris::PrimitiveType)36>::check_column(doris::vectorized::IColumn const&) const at /root/doris/be/src/vec/data_types/data_type_number_base.cpp:239 2# doris::vectorized::ColumnWithTypeAndName::check_type_and_column_match() const at /root/doris/be/src/vec/core/column_with_type_and_name.cpp:0 3# doris::vectorized::VExprContext::execute(doris::vectorized::Block*, int*) at /root/doris/be/src/vec/exprs/vexpr_context.cpp:0 4# doris::FoldConstantExecutor::fold_constant_vexpr(doris::TFoldConstantParams const&, doris::PConstantExprResult*) at /root/doris/be/src/common/status.h:0 5# std::_Function_handler::_M_invoke(std::_Any_data const&) at /root/doris/be/src/common/status.h:0 ``` --- be/src/runtime/fold_constant_executor.cpp | 12 ++++-------- .../rules/expression/rules/FoldConstantRuleOnBE.java | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/be/src/runtime/fold_constant_executor.cpp b/be/src/runtime/fold_constant_executor.cpp index 2887d39f45b4e9..6ccf1bc9af588d 100644 --- a/be/src/runtime/fold_constant_executor.cpp +++ b/be/src/runtime/fold_constant_executor.cpp @@ -95,21 +95,17 @@ Status FoldConstantExecutor::fold_constant_vexpr(const TFoldConstantParams& para // prepare and open context RETURN_IF_ERROR(_prepare_and_open(ctx.get())); - vectorized::Block tmp_block; - tmp_block.insert({vectorized::ColumnUInt8::create(1), - std::make_shared(), ""}); - int result_column = -1; + vectorized::ColumnWithTypeAndName tmp_data; // calc vexpr - RETURN_IF_ERROR(ctx->execute(&tmp_block, &result_column)); - DCHECK(result_column != -1); + RETURN_IF_ERROR(ctx->execute_const_expr(tmp_data)); // covert to thrift type const auto& res_type = ctx->root()->data_type(); TPrimitiveType::type t_type = doris::to_thrift(res_type->get_primitive_type()); // collect result PExprResult expr_result; std::string result; - const auto& column_ptr = tmp_block.get_by_position(result_column).column; - const auto& column_type = tmp_block.get_by_position(result_column).type; + const auto& column_ptr = tmp_data.column; + const auto& column_type = tmp_data.type; // 4 from fe: Config.be_exec_version maybe need remove after next version, now in 2.1 if (_runtime_state->be_exec_version() >= 4 && params.__isset.is_nereids && params.is_nereids) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java index da4eb88d2a8263..4568e6416462d8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java @@ -83,6 +83,7 @@ import org.apache.doris.proto.Types.PTypeNode; import org.apache.doris.proto.Types.PValues; import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.SessionVariable; import org.apache.doris.rpc.BackendServiceProxy; import org.apache.doris.system.Backend; import org.apache.doris.thrift.TExpr; @@ -319,6 +320,7 @@ private static Map evalOnBE(Map> tQueryOptions.setBeExecVersion(Config.be_exec_version); tQueryOptions.setEnableDecimal256(context.getSessionVariable().isEnableDecimal256()); tQueryOptions.setNewVersionUnixTimestamp(true); + tQueryOptions.setEnableStrictCast(SessionVariable.enableStrictCast()); TFoldConstantParams tParams = new TFoldConstantParams(paramMap, queryGlobals); tParams.setVecExec(true);