Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug](if) fix if function not handle const nullable value #22823

Merged
merged 5 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions be/src/vec/exprs/vectorized_fn_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ namespace doris::vectorized {

const std::string AGG_STATE_SUFFIX = "_state";

VectorizedFnCall::VectorizedFnCall(const TExprNode& node) : VExpr(node) {
_expr_name = fmt::format("VectorizedFnCall[{}](arguments={},return={})", _fn.name.function_name,
get_child_names(), _data_type->get_name());
}
VectorizedFnCall::VectorizedFnCall(const TExprNode& node) : VExpr(node) {}

Status VectorizedFnCall::prepare(RuntimeState* state, const RowDescriptor& desc,
VExprContext* context) {
Expand All @@ -70,6 +67,9 @@ Status VectorizedFnCall::prepare(RuntimeState* state, const RowDescriptor& desc,
argument_template.emplace_back(nullptr, child->data_type(), child->expr_name());
}

_expr_name = fmt::format("VectorizedFnCall[{}](arguments={},return={})", _fn.name.function_name,
get_child_names(), _data_type->get_name());

if (_fn.binary_type == TFunctionBinaryType::RPC) {
_function = FunctionRPC::create(_fn, argument_template, _data_type);
} else if (_fn.binary_type == TFunctionBinaryType::JAVA_UDF) {
Expand Down
62 changes: 49 additions & 13 deletions be/src/vec/functions/if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
zhangstar333 marked this conversation as resolved.
Show resolved Hide resolved
input_rows_count)
: then_is_nullable->get_null_map_column_ptr())
: DataTypeUInt8().create_column_const_with_default_value(
input_rows_count);
temporary_block.insert({then_nested_null_map, std::make_shared<DataTypeUInt8>(),
"then_column_null_map"});

auto else_nested_null_map =
else_type_is_nullable
? (else_column_is_const_nullable
? DataTypeUInt8().create_column_const_with_default_value(
input_rows_count)
: else_is_nullable->get_null_map_column_ptr())
: DataTypeUInt8().create_column_const_with_default_value(
input_rows_count);
temporary_block.insert({else_nested_null_map, std::make_shared<DataTypeUInt8>(),
"else_column_null_map"});
temporary_block.insert(
{nullptr, std::make_shared<DataTypeUInt8>(), "result_column_null_map"});

execute_impl(context, temporary_block, {0, 1, 2}, 3, temporary_block.rows());

Expand Down