This is an automated email from the ASF dual-hosted git repository. zhangstar333 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 942a119881 [bug](java-udf) fix java-udf not return const column when all args are const values (#23188) 942a119881 is described below commit 942a11988157de641d9189fd8c3f54cb8d6fa405 Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com> AuthorDate: Wed Aug 30 10:46:47 2023 +0800 [bug](java-udf) fix java-udf not return const column when all args are const values (#23188) eg: udf('asd'), this need return a const column, otherwise will be failed use the return column as other function params. mysql> select concat('a', 'b', cuuid9('a'), ':c'); ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.6)[CANCELLED][INTERNAL_ERROR]const check failed, expr=VectorizedFn[VectorizedFnCallconcat]{ VLiteral (name = String, type = String, value = (a)), VLiteral (name = String, type = String, value = (b)), VectorizedFn[VectorizedFnCallcuuid9] { VLiteral (name = String, type = String, value = (a))}, VLiteral (name = String, type = String, value = (:c))} --- be/src/vec/functions/function_java_udf.cpp | 6 ++--- be/src/vec/functions/function_java_udf.h | 38 ++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/be/src/vec/functions/function_java_udf.cpp b/be/src/vec/functions/function_java_udf.cpp index 7c50e74117..fa9c8517c8 100644 --- a/be/src/vec/functions/function_java_udf.cpp +++ b/be/src/vec/functions/function_java_udf.cpp @@ -121,9 +121,9 @@ Status JavaFunctionCall::open(FunctionContext* context, FunctionContext::Functio return Status::OK(); } -Status JavaFunctionCall::execute(FunctionContext* context, Block& block, - const ColumnNumbers& arguments, size_t result, size_t num_rows, - bool dry_run) { +Status JavaFunctionCall::execute_impl(FunctionContext* context, Block& block, + const ColumnNumbers& arguments, size_t result, + size_t num_rows) const { JNIEnv* env = nullptr; RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env)); JniContext* jni_ctx = reinterpret_cast<JniContext*>( diff --git a/be/src/vec/functions/function_java_udf.h b/be/src/vec/functions/function_java_udf.h index ddbe300e89..875e3426df 100644 --- a/be/src/vec/functions/function_java_udf.h +++ b/be/src/vec/functions/function_java_udf.h @@ -22,6 +22,7 @@ #include <stddef.h> #include <stdint.h> +#include <functional> #include <memory> #include <mutex> #include <ostream> @@ -37,10 +38,35 @@ #include "vec/core/types.h" #include "vec/data_types/data_type.h" #include "vec/functions/function.h" - namespace doris { namespace vectorized { + +class JavaUdfPreparedFunction : public PreparedFunctionImpl { +public: + using execute_call_back = std::function<Status(FunctionContext* context, Block& block, + const ColumnNumbers& arguments, size_t result, + size_t input_rows_count)>; + + explicit JavaUdfPreparedFunction(const execute_call_back& func, const std::string& name) + : callback_function(func), name(name) {} + + String get_name() const override { return name; } + +protected: + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + return callback_function(context, block, arguments, result, input_rows_count); + } + + bool use_default_implementation_for_nulls() const override { return false; } + bool use_default_implementation_for_low_cardinality_columns() const override { return false; } + +private: + execute_call_back callback_function; + std::string name; +}; + class JavaFunctionCall : public IFunctionBase { public: JavaFunctionCall(const TFunction& fn, const DataTypes& argument_types, @@ -63,13 +89,17 @@ public: PreparedFunctionPtr prepare(FunctionContext* context, const Block& sample_block, const ColumnNumbers& arguments, size_t result) const override { - return nullptr; + return std::make_shared<JavaUdfPreparedFunction>( + std::bind<Status>(&JavaFunctionCall::execute_impl, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, + std::placeholders::_4, std::placeholders::_5), + fn_.name.function_name); } Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override; - Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, - size_t result, size_t input_rows_count, bool dry_run = false) override; + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) const; Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org