This is an automated email from the ASF dual-hosted git repository. cambyzju pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new b92aae73ed2 [fix](if) handle result status of if function (#38426) b92aae73ed2 is described below commit b92aae73ed249e077dcbdc9ce054885f3d217a7e Author: camby <camby...@tencent.com> AuthorDate: Mon Jul 29 11:16:19 2024 +0800 [fix](if) handle result status of if function (#38426) --- be/src/vec/exec/join/vjoin_node_base.cpp | 7 +++ be/src/vec/functions/if.cpp | 105 +++++++++++++++++-------------- 2 files changed, 64 insertions(+), 48 deletions(-) diff --git a/be/src/vec/exec/join/vjoin_node_base.cpp b/be/src/vec/exec/join/vjoin_node_base.cpp index 912f7826fe2..bd4143e3a73 100644 --- a/be/src/vec/exec/join/vjoin_node_base.cpp +++ b/be/src/vec/exec/join/vjoin_node_base.cpp @@ -193,6 +193,13 @@ Status VJoinNodeBase::_build_output_block(Block* origin_block, Block* output_blo auto result_column_id = -1; RETURN_IF_ERROR(_output_expr_ctxs[i]->execute(origin_block, &result_column_id)); auto& origin_column = origin_block->get_by_position(result_column_id).column; + if (!origin_column) { + LOG(WARNING) + << "BUG!!! VExprContext::execute successfully, but return null column. " + << origin_block->get_by_position(result_column_id).dump_structure(); + return Status::InternalError( + "VExprContext::execute inside VJoinNodeBase return null column"); + } /// `convert_to_full_column_if_const` will create a pointer to the origin column if /// the origin column is not ColumnConst/ColumnArray, this make the column be not diff --git a/be/src/vec/functions/if.cpp b/be/src/vec/functions/if.cpp index 77f1c0ae53b..5c360d670bf 100644 --- a/be/src/vec/functions/if.cpp +++ b/be/src/vec/functions/if.cpp @@ -287,23 +287,24 @@ public: else_col.type->get_type_id(), call); } - bool execute_for_null_then_else(FunctionContext* context, Block& block, - const ColumnWithTypeAndName& arg_cond, - const ColumnWithTypeAndName& arg_then, - const ColumnWithTypeAndName& arg_else, size_t result, - size_t input_rows_count, Status& status) { + Status execute_for_null_then_else(FunctionContext* context, Block& block, + const ColumnWithTypeAndName& arg_cond, + const ColumnWithTypeAndName& arg_then, + const ColumnWithTypeAndName& arg_else, size_t result, + size_t input_rows_count, bool& handled) { bool then_is_null = arg_then.column->only_null(); bool else_is_null = arg_else.column->only_null(); if (!then_is_null && !else_is_null) { - return false; + return Status::OK(); } if (then_is_null && else_is_null) { block.get_by_position(result).column = block.get_by_position(result).type->create_column_const_with_default_value( input_rows_count); - return true; + handled = true; + return Status::OK(); } const ColumnUInt8* cond_col = typeid_cast<const ColumnUInt8*>(arg_cond.column.get()); @@ -335,16 +336,12 @@ public: make_nullable_column_if_not(arg_else.column); } } else { - status = Status::InternalError( + return Status::InternalError( "Illegal column {} of first argument of function {}. Must be ColumnUInt8 " "or ColumnConstUInt8.", arg_cond.column->get_name(), get_name()); } - return true; - } - - /// If else is NULL, we create Nullable column with null mask OR-ed with negated condition. - if (else_is_null) { + } else { /// If else is NULL, we create Nullable column with null mask OR-ed with negated condition. if (cond_col) { size_t size = input_rows_count; auto& null_map_data = cond_col->get_data(); @@ -380,33 +377,32 @@ public: input_rows_count); } } else { - status = Status::InternalError( + return Status::InternalError( "Illegal column {} of first argument of function {}. Must be ColumnUInt8 " "or ColumnConstUInt8.", arg_cond.column->get_name(), get_name()); } - return true; } - - return false; + handled = true; + return Status::OK(); } - bool execute_for_nullable_then_else(FunctionContext* context, Block& block, - const ColumnWithTypeAndName& arg_cond, - const ColumnWithTypeAndName& arg_then, - const ColumnWithTypeAndName& arg_else, size_t result, - size_t input_rows_count) { + Status execute_for_nullable_then_else(FunctionContext* context, Block& block, + const ColumnWithTypeAndName& arg_cond, + const ColumnWithTypeAndName& arg_then, + const ColumnWithTypeAndName& arg_else, size_t result, + size_t input_rows_count, bool& handled) { auto then_type_is_nullable = arg_then.type->is_nullable(); auto else_type_is_nullable = arg_else.type->is_nullable(); if (!then_type_is_nullable && !else_type_is_nullable) { - return false; + return Status::OK(); } auto* then_is_nullable = check_and_get_column<ColumnNullable>(*arg_then.column); auto* else_is_nullable = check_and_get_column<ColumnNullable>(*arg_else.column); bool then_column_is_const_nullable = false; bool else_column_is_const_nullable = false; - if (then_type_is_nullable == true && then_is_nullable == nullptr) { + if (then_type_is_nullable && then_is_nullable == nullptr) { //this case is a const(nullable column) auto& const_column = assert_cast<const ColumnConst&>(*arg_then.column); then_is_nullable = @@ -414,7 +410,7 @@ public: then_column_is_const_nullable = true; } - if (else_type_is_nullable == true && else_is_nullable == nullptr) { + if (else_type_is_nullable && else_is_nullable == nullptr) { //this case is a const(nullable column) auto& const_column = assert_cast<const ColumnConst&>(*arg_else.column); else_is_nullable = @@ -426,13 +422,13 @@ public: */ ColumnPtr result_null_mask; { - // get nullmap from column: + // get null map from column: // a. get_null_map_column_ptr() : it's a real nullable column, so could get it from nullable column // b. create a const_nullmap_column: it's a not nullable column or a const nullable column, contain a const value Block temporary_block; temporary_block.insert(arg_cond); auto then_nested_null_map = - (then_type_is_nullable == true && then_column_is_const_nullable == false) + (then_type_is_nullable && !then_column_is_const_nullable) ? then_is_nullable->get_null_map_column_ptr() : DataTypeUInt8().create_column_const_with_default_value( input_rows_count); @@ -440,7 +436,7 @@ public: "then_column_null_map"}); auto else_nested_null_map = - (else_type_is_nullable == true && else_column_is_const_nullable == false) + (else_type_is_nullable && !else_column_is_const_nullable) ? else_is_nullable->get_null_map_column_ptr() : DataTypeUInt8().create_column_const_with_default_value( input_rows_count); @@ -449,7 +445,8 @@ public: temporary_block.insert( {nullptr, std::make_shared<DataTypeUInt8>(), "result_column_null_map"}); - execute_impl(context, temporary_block, {0, 1, 2}, 3, temporary_block.rows()); + RETURN_IF_ERROR( + execute_impl(context, temporary_block, {0, 1, 2}, 3, temporary_block.rows())); result_null_mask = temporary_block.get_by_position(3).column; } @@ -463,7 +460,8 @@ public: {get_nested_column(arg_else.column), remove_nullable(arg_else.type), ""}, {nullptr, remove_nullable(block.get_by_position(result).type), ""}}); - execute_impl(context, temporary_block, {0, 1, 2}, 3, temporary_block.rows()); + RETURN_IF_ERROR( + execute_impl(context, temporary_block, {0, 1, 2}, 3, temporary_block.rows())); result_nested_column = temporary_block.get_by_position(3).column; } @@ -471,26 +469,29 @@ public: auto column = ColumnNullable::create(materialize_column_if_const(result_nested_column), materialize_column_if_const(result_null_mask)); block.replace_by_position(result, std::move(column)); - return true; + handled = true; + return Status::OK(); } - bool execute_for_null_condition(FunctionContext* context, Block& block, - const ColumnNumbers& arguments, - const ColumnWithTypeAndName& arg_cond, - const ColumnWithTypeAndName& arg_then, - const ColumnWithTypeAndName& arg_else, size_t result) { + Status execute_for_null_condition(FunctionContext* context, Block& block, + const ColumnNumbers& arguments, + const ColumnWithTypeAndName& arg_cond, + const ColumnWithTypeAndName& arg_then, + const ColumnWithTypeAndName& arg_else, size_t result, + bool& handled) { bool cond_is_null = arg_cond.column->only_null(); if (cond_is_null) { block.replace_by_position(result, arg_else.column->clone_resized(arg_cond.column->size())); - return true; + handled = true; + return Status::OK(); } if (auto* nullable = check_and_get_column<ColumnNullable>(*arg_cond.column)) { DCHECK(remove_nullable(arg_cond.type)->get_type_id() == TypeIndex::UInt8); - // update neseted column by nullmap + // update nested column by null map auto* __restrict null_map = nullable->get_null_map_data().data(); auto* __restrict nested_bool_data = ((ColumnVector<UInt8>&)(nullable->get_nested_column())).get_data().data(); @@ -502,10 +503,11 @@ public: block.insert({nullable->get_nested_column_ptr(), remove_nullable(arg_cond.type), arg_cond.name}); - execute_impl(context, block, {column_size, arguments[1], arguments[2]}, result, rows); - return true; + handled = true; + return execute_impl(context, block, {column_size, arguments[1], arguments[2]}, result, + rows); } - return false; + return Status::OK(); } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, @@ -525,13 +527,20 @@ public: const ColumnWithTypeAndName& arg_cond = block.get_by_position(arguments[0]); Status ret = Status::OK(); - if (execute_for_null_condition(context, block, arguments, arg_cond, arg_then, arg_else, - result) || - execute_for_null_then_else(context, block, arg_cond, arg_then, arg_else, result, - input_rows_count, ret) || - execute_for_nullable_then_else(context, block, arg_cond, arg_then, arg_else, result, - input_rows_count)) { - return ret; + bool handled = false; + RETURN_IF_ERROR(execute_for_null_condition(context, block, arguments, arg_cond, arg_then, + arg_else, result, handled)); + if (!handled) { + RETURN_IF_ERROR(execute_for_null_then_else(context, block, arg_cond, arg_then, arg_else, + result, input_rows_count, handled)); + } + if (!handled) { + RETURN_IF_ERROR(execute_for_nullable_then_else(context, block, arg_cond, arg_then, + arg_else, result, input_rows_count, + handled)); + } + if (handled) { + return Status::OK(); } const ColumnUInt8* cond_col = typeid_cast<const ColumnUInt8*>(arg_cond.column.get()); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org