zhangstar333 commented on code in PR #22823: URL: https://github.com/apache/doris/pull/22823#discussion_r1292802175
########## be/src/vec/functions/if.cpp: ########## @@ -396,28 +396,64 @@ class FunctionIf : public IFunction { const ColumnWithTypeAndName& arg_then, const ColumnWithTypeAndName& arg_else, size_t result, size_t input_rows_count) { + 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; + } + 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) { + //this case is a const(nullable column) + auto& const_column = assert_cast<const ColumnConst&>(*arg_then.column); + then_is_nullable = + assert_cast<const ColumnNullable*>(const_column.get_data_column_ptr().get()); + then_column_is_const_nullable = true; + } - if (!then_is_nullable && !else_is_nullable) { - return false; + if (else_type_is_nullable == true && else_is_nullable == nullptr) { + //this case is a const(nullable column) + auto& const_column = assert_cast<const ColumnConst&>(*arg_else.column); + else_is_nullable = + assert_cast<const ColumnNullable*>(const_column.get_data_column_ptr().get()); + else_column_is_const_nullable = true; } /** Calculate null mask of result and nested column separately. */ ColumnPtr result_null_mask; { - Block temporary_block( - {arg_cond, - {then_is_nullable ? then_is_nullable->get_null_map_column_ptr() - : DataTypeUInt8().create_column_const_with_default_value( - input_rows_count), - std::make_shared<DataTypeUInt8>(), ""}, - {else_is_nullable ? else_is_nullable->get_null_map_column_ptr() - : DataTypeUInt8().create_column_const_with_default_value( - input_rows_count), - std::make_shared<DataTypeUInt8>(), ""}, - {nullptr, std::make_shared<DataTypeUInt8>(), ""}}); + // get nullmap from column: + // a. nullable column ----> it's a real nullable column get_null_map_column_ptr() / fake nullable, a const nullable + // b. not nullable ----> not have null map, so create const null map + Block temporary_block; + temporary_block.insert(arg_cond); + auto then_nested_null_map = + then_type_is_nullable + ? (then_column_is_const_nullable + ? DataTypeUInt8().create_column_const_with_default_value( Review Comment: the column only null have been handle by `execute_for_null_then_else` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org