You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2023/02/26 04:30:11 UTC

[doris] branch master updated: [vectorized](bug) fix open fold constant cause be core dump (#17055)

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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 94927b3b1c [vectorized](bug) fix open fold constant cause be core dump (#17055)
94927b3b1c is described below

commit 94927b3b1c67efbde8a0556e8f6bc0e1e0cf74c9
Author: zhangstar333 <87...@users.noreply.github.com>
AuthorDate: Sun Feb 26 12:30:03 2023 +0800

    [vectorized](bug) fix open fold constant cause be core dump (#17055)
    
    add a defer in fold constant to close.
    add more type when call _get_result function in fold constant.3.
    fix in can't handle null. eg:select 1 in (2, NULL, 1);
    in java udf jni_ctx will be nullptr, so call close will be core dump.
    Describe your changes.
---
 be/src/runtime/fold_constant_executor.cpp  | 48 +++++++++++++++++++++++++-----
 be/src/runtime/fold_constant_executor.h    |  5 +++-
 be/src/vec/functions/function_java_udf.cpp |  4 ++-
 be/src/vec/functions/in.h                  |  7 ++++-
 4 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/be/src/runtime/fold_constant_executor.cpp b/be/src/runtime/fold_constant_executor.cpp
index dbfbacf0b2..bd28c35de9 100644
--- a/be/src/runtime/fold_constant_executor.cpp
+++ b/be/src/runtime/fold_constant_executor.cpp
@@ -23,6 +23,7 @@
 #include "common/status.h"
 #include "gen_cpp/PaloInternalService_types.h"
 #include "gen_cpp/internal_service.pb.h"
+#include "runtime/define_primitive_type.h"
 #include "runtime/exec_env.h"
 #include "runtime/large_int_value.h"
 #include "runtime/memory/mem_tracker.h"
@@ -57,6 +58,9 @@ Status FoldConstantExecutor::fold_constant_vexpr(const TFoldConstantParams& para
             const TExpr& texpr = n.second;
             // create expr tree from TExpr
             RETURN_IF_ERROR(vectorized::VExpr::create_expr_tree(&_pool, texpr, &ctx));
+
+            // close context expr
+            Defer defer {[&]() { ctx->close(_runtime_state.get()); }};
             // prepare and open context
             RETURN_IF_ERROR(_prepare_and_open(ctx));
 
@@ -75,21 +79,19 @@ Status FoldConstantExecutor::fold_constant_vexpr(const TFoldConstantParams& para
             PExprResult expr_result;
             string result;
             const auto& column_ptr = tmp_block.get_by_position(result_column).column;
+            const auto& column_type = tmp_block.get_by_position(result_column).type;
             if (column_ptr->is_null_at(0)) {
                 expr_result.set_success(false);
             } else {
                 expr_result.set_success(true);
                 auto string_ref = column_ptr->get_data_at(0);
                 result = _get_result<true>((void*)string_ref.data, string_ref.size,
-                                           ctx->root()->type().type);
+                                           ctx->root()->type(), column_ptr, column_type);
             }
 
             expr_result.set_content(std::move(result));
             expr_result.mutable_type()->set_type(t_type);
             pexpr_result_map.mutable_map()->insert({n.first, expr_result});
-
-            // close context expr
-            ctx->close(_runtime_state.get());
         }
         expr_result_map->insert({m.first, pexpr_result_map});
     }
@@ -136,8 +138,10 @@ Status FoldConstantExecutor::_prepare_and_open(Context* ctx) {
 }
 
 template <bool is_vec>
-string FoldConstantExecutor::_get_result(void* src, size_t size, PrimitiveType slot_type) {
-    switch (slot_type) {
+string FoldConstantExecutor::_get_result(void* src, size_t size, const TypeDescriptor& type,
+                                         const vectorized::ColumnPtr column_ptr,
+                                         const vectorized::DataTypePtr column_type) {
+    switch (type.type) {
     case TYPE_BOOLEAN: {
         bool val = *reinterpret_cast<const bool*>(src);
         return val ? "true" : "false";
@@ -194,11 +198,41 @@ string FoldConstantExecutor::_get_result(void* src, size_t size, PrimitiveType s
             return str;
         }
     }
+    case TYPE_DATEV2: {
+        vectorized::DateV2Value<vectorized::DateV2ValueType> value =
+                binary_cast<uint32_t, doris::vectorized::DateV2Value<vectorized::DateV2ValueType>>(
+                        *(int32_t*)src);
+
+        char buf[64];
+        char* pos = value.to_string(buf);
+        return std::string(buf, pos - buf - 1);
+    }
+    case TYPE_DATETIMEV2: {
+        vectorized::DateV2Value<vectorized::DateTimeV2ValueType> value =
+                binary_cast<uint64_t,
+                            doris::vectorized::DateV2Value<vectorized::DateTimeV2ValueType>>(
+                        *(int64_t*)src);
+
+        char buf[64];
+        char* pos = value.to_string(buf, type.scale);
+        return std::string(buf, pos - buf - 1);
+    }
     case TYPE_DECIMALV2: {
         return reinterpret_cast<DecimalV2Value*>(src)->to_string();
     }
+    case TYPE_DECIMAL32:
+    case TYPE_DECIMAL64:
+    case TYPE_DECIMAL128I: {
+        return column_type->to_string(*column_ptr, 0);
+    }
+    case TYPE_ARRAY:
+    case TYPE_JSONB:
+    case TYPE_MAP:
+    case TYPE_STRUCT: {
+        return column_type->to_string(*column_ptr, 0);
+    }
     default:
-        DCHECK(false) << "Type not implemented: " << slot_type;
+        DCHECK(false) << "Type not implemented: " << type.debug_string();
         return "";
     }
 }
diff --git a/be/src/runtime/fold_constant_executor.h b/be/src/runtime/fold_constant_executor.h
index 90ace19a32..43628b6068 100644
--- a/be/src/runtime/fold_constant_executor.h
+++ b/be/src/runtime/fold_constant_executor.h
@@ -25,6 +25,7 @@
 #include "runtime/exec_env.h"
 #include "runtime/runtime_state.h"
 #include "util/runtime_profile.h"
+#include "vec/data_types/data_type.h"
 
 namespace doris {
 
@@ -46,7 +47,9 @@ private:
     Status _prepare_and_open(Context* ctx);
 
     template <bool is_vec = false>
-    std::string _get_result(void* src, size_t size, PrimitiveType slot_type);
+    std::string _get_result(void* src, size_t size, const TypeDescriptor& type,
+                            const vectorized::ColumnPtr column_ptr,
+                            const vectorized::DataTypePtr column_type);
 
     std::unique_ptr<RuntimeState> _runtime_state;
     std::unique_ptr<MemTracker> _mem_tracker;
diff --git a/be/src/vec/functions/function_java_udf.cpp b/be/src/vec/functions/function_java_udf.cpp
index 0a031e186f..9da2f38dd5 100644
--- a/be/src/vec/functions/function_java_udf.cpp
+++ b/be/src/vec/functions/function_java_udf.cpp
@@ -311,7 +311,9 @@ Status JavaFunctionCall::close(FunctionContext* context,
             context->get_function_state(FunctionContext::THREAD_LOCAL));
     // JNIContext own some resource and its release method depend on JavaFunctionCall
     // has to release the resource before JavaFunctionCall is deconstructed.
-    jni_ctx->close();
+    if (jni_ctx) {
+        jni_ctx->close();
+    }
     return Status::OK();
 }
 } // namespace doris::vectorized
diff --git a/be/src/vec/functions/in.h b/be/src/vec/functions/in.h
index 97e299bdef..eb1c01c343 100644
--- a/be/src/vec/functions/in.h
+++ b/be/src/vec/functions/in.h
@@ -156,7 +156,6 @@ public:
                 }
 
             } else { // non-nullable
-                DCHECK(!in_state->null_in_set);
 
                 auto search_hash_set = [&](auto* col_ptr) {
                     for (size_t i = 0; i < input_rows_count; ++i) {
@@ -177,6 +176,12 @@ public:
                 } else {
                     search_hash_set(materialized_column.get());
                 }
+
+                if (in_state->null_in_set) {
+                    for (size_t i = 0; i < input_rows_count; ++i) {
+                        vec_null_map_to[i] = negative == vec_res[i];
+                    }
+                }
             }
         } else {
             std::vector<ColumnPtr> set_columns;


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