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((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 -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(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 value = + binary_cast>( + *(int32_t*)src); + + char buf[64]; + char* pos = value.to_string(buf); + return std::string(buf, pos - buf - 1); + } + case TYPE_DATETIMEV2: { + vectorized::DateV2Value value = + binary_cast>( + *(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(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 - 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 _runtime_state; std::unique_ptr _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 set_columns;