Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions be/src/vec/functions/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ ColumnPtr wrap_in_nullable(const ColumnPtr& src, const Block& block, const Colum
return ColumnNullable::create(src_not_nullable, result_null_map_column);
}

bool get_null_presence(const Block& block, const ColumnNumbers& args) {
bool have_null_column(const Block& block, const ColumnNumbers& args) {
return std::ranges::any_of(args, [&block](const auto& elem) {
return block.get_by_position(elem).type->is_nullable();
});
}

bool get_null_presence(const ColumnsWithTypeAndName& args) {
bool have_null_column(const ColumnsWithTypeAndName& args) {
return std::ranges::any_of(args, [](const auto& elem) { return elem.type->is_nullable(); });
}

Expand Down Expand Up @@ -202,20 +202,21 @@ Status PreparedFunctionImpl::default_implementation_for_nulls(
return Status::OK();
}

if (get_null_presence(block, args)) {
if (have_null_column(block, args)) {
bool need_to_default = need_replace_null_data_to_default();
if (context) {
need_to_default &= context->check_overflow_for_decimal();
}
// extract nested column from nulls
ColumnNumbers new_args;
for (auto arg : args) {
new_args.push_back(block.columns());
block.insert(block.get_by_position(arg).get_nested(need_to_default));
DCHECK(!block.get_by_position(new_args.back()).column->is_nullable());
}

RETURN_IF_ERROR(execute_without_low_cardinality_columns(context, block, new_args, result,
block.rows(), dry_run));
// after run with nested, wrap them in null.
block.get_by_position(result).column = wrap_in_nullable(
block.get_by_position(result).column, block, args, result, input_rows_count);

Expand Down Expand Up @@ -267,7 +268,7 @@ DataTypePtr FunctionBuilderImpl::get_return_type_without_low_cardinality(
check_number_of_arguments(arguments.size());

if (!arguments.empty() && use_default_implementation_for_nulls()) {
if (get_null_presence(arguments)) {
if (have_null_column(arguments)) {
ColumnNumbers numbers(arguments.size());
std::iota(numbers.begin(), numbers.end(), 0);
auto [nested_block, _] =
Expand Down
16 changes: 10 additions & 6 deletions be/src/vec/functions/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ concept HasGetVariadicArgumentTypesImpl = requires(T t) {
{ t.get_variadic_argument_types_impl() } -> std::same_as<DataTypes>;
};

bool get_null_presence(const Block& block, const ColumnNumbers& args);
bool get_null_presence(const ColumnsWithTypeAndName& args);
bool have_null_column(const Block& block, const ColumnNumbers& args);
bool have_null_column(const ColumnsWithTypeAndName& args);

/// The simplest executable object.
/// Motivation:
Expand Down Expand Up @@ -288,9 +288,11 @@ class FunctionBuilderImpl : public IFunctionBuilder {

bool is_variadic() const override { return false; }

/// Default implementation. Will check only in non-variadic case.
// Default implementation. Will check only in non-variadic case.
void check_number_of_arguments(size_t number_of_arguments) const override;

// the return type should be same with what FE plans.
// it returns: `get_return_type_impl` if `use_default_implementation_for_nulls` = false
// `get_return_type_impl` warpped in NULL if `use_default_implementation_for_nulls` = true and input has NULL
DataTypePtr get_return_type(const ColumnsWithTypeAndName& arguments) const;

DataTypes get_variadic_argument_types() const override {
Expand All @@ -300,7 +302,9 @@ class FunctionBuilderImpl : public IFunctionBuilder {
ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; }

protected:
/// Get the result type by argument type. If the function does not apply to these arguments, throw an exception.
// Get the result type by argument type. If the function does not apply to these arguments, throw an exception.
// the get_return_type_impl and its overrides should only return the nested type if `use_default_implementation_for_nulls` is true.
// whether to wrap in nullable type will be automatically decided.
virtual DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const {
DataTypes data_types(arguments.size());
for (size_t i = 0; i < arguments.size(); ++i) data_types[i] = arguments[i].type;
Expand All @@ -317,7 +321,7 @@ class FunctionBuilderImpl : public IFunctionBuilder {
* if some of arguments are Nullable(Nothing) then don't call get_return_type(), call build_impl() with return_type = Nullable(Nothing),
* if some of arguments are Nullable, then:
* - Nullable types are substituted with nested types for get_return_type() function
* - wrap get_return_type() result in Nullable type and pass to build_impl
* - WRAP get_return_type() RESULT IN NULLABLE type and pass to build_impl
*
* Otherwise build returns build_impl(arguments, get_return_type(arguments));
*/
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/function_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ Status execute_bitmap_op_count_null_to_zero(
size_t input_rows_count,
const std::function<Status(FunctionContext*, Block&, const ColumnNumbers&, size_t, size_t)>&
exec_impl_func) {
if (get_null_presence(block, arguments)) {
if (have_null_column(block, arguments)) {
auto [temporary_block, new_args, new_result] =
create_block_with_nested_columns(block, arguments, result);
RETURN_IF_ERROR(exec_impl_func(context, temporary_block, new_args, new_result,
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/functions/nullif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FunctionNullIf : public IFunction {
}

if (!arguments.empty()) {
if (get_null_presence(arguments)) {
if (have_null_column(arguments)) {
return make_nullable(std::make_shared<doris::vectorized::DataTypeUInt8>());
}
}
Expand Down
Loading