You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/06/14 09:13:38 UTC

[incubator-doris] branch dev-1.0.1 updated: [Bug] return type is not always nullable of function (#10116)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch dev-1.0.1
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/dev-1.0.1 by this push:
     new e80357ed0b [Bug] return type is not always nullable of function (#10116)
e80357ed0b is described below

commit e80357ed0bfe15ebdbf41f80f7eebb3ccffc11cb
Author: HappenLee <ha...@hotmail.com>
AuthorDate: Tue Jun 14 16:32:35 2022 +0800

    [Bug] return type is not always nullable of function (#10116)
    
    Co-authored-by: lihaopeng <li...@baidu.com>
---
 be/src/udf/udf.cpp              |  2 --
 be/src/vec/functions/nullif.cpp | 31 +++++++++++++++----------------
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/be/src/udf/udf.cpp b/be/src/udf/udf.cpp
index 612aabb252..6fb8e53a0e 100644
--- a/be/src/udf/udf.cpp
+++ b/be/src/udf/udf.cpp
@@ -553,10 +553,8 @@ void* FunctionContext::get_function_state(FunctionStateScope scope) const {
     switch (scope) {
     case THREAD_LOCAL:
         return _impl->_thread_local_fn_state;
-        break;
     case FRAGMENT_LOCAL:
         return _impl->_fragment_local_fn_state;
-        break;
     default:
         // TODO: signal error somehow
         return nullptr;
diff --git a/be/src/vec/functions/nullif.cpp b/be/src/vec/functions/nullif.cpp
index 30c5e0cf55..af5ad844ab 100644
--- a/be/src/vec/functions/nullif.cpp
+++ b/be/src/vec/functions/nullif.cpp
@@ -50,7 +50,7 @@ public:
     bool use_default_implementation_for_nulls() const override { return false; }
 
     DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
-        return arguments[0];
+        return make_nullable(arguments[0]);
     }
 
     NullPresence get_null_resense(const ColumnsWithTypeAndName& args) const {
@@ -108,8 +108,11 @@ public:
                  {nullptr, result_type, ""}
         });
 
-        auto equals_func = SimpleFunctionFactory::instance().get_function("eq", eq_columns, result_type);
-        equals_func->execute(context, eq_temporary_block, {0, 1}, 2, input_rows_count);
+        auto equals_func =
+                SimpleFunctionFactory::instance().get_function("eq", eq_columns, result_type);
+        DCHECK(equals_func);
+        RETURN_IF_ERROR(
+                equals_func->execute(context, eq_temporary_block, {0, 1}, 2, input_rows_count));
 
         const ColumnWithTypeAndName new_result_column {
             block.get_by_position(result),
@@ -133,18 +136,14 @@ public:
                                                  input_rows_count),
                       block.get_by_position(result).type, "NULL"},
                  block.get_by_position(arguments[0]),
-                 new_result_column
-                });
-        auto func_if = SimpleFunctionFactory::instance().get_function("if", if_columns, new_result_column.type);
-        func_if->execute(context, temporary_block, {0, 1, 2}, 3, input_rows_count);
-        /// need to handle nullable type and not nullable type differently,
-        /// because `IF` function always return nullable type, but result type is not always
-        if (block.get_by_position(result).type->is_nullable()) {
-            block.get_by_position(result).column = temporary_block.get_by_position(3).column;
-        } else {
-            auto cols = check_and_get_column<ColumnNullable>(temporary_block.get_by_position(3).column.get());
-            block.replace_by_position(result, std::move(cols->get_nested_column_ptr()));
-        }
+                 new_result_column});
+
+        auto func_if = SimpleFunctionFactory::instance().get_function("if", if_columns,
+                                                                      new_result_column.type);
+        DCHECK(func_if);
+        RETURN_IF_ERROR(func_if->execute(context, temporary_block, {0, 1, 2}, 3, input_rows_count));
+        block.get_by_position(result).column = temporary_block.get_by_position(3).column;
+
         return Status::OK();
     }
 };
@@ -152,4 +151,4 @@ public:
 void register_function_nullif(SimpleFunctionFactory& factory) {
     factory.register_function<FunctionNullIf>();
 }
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org