You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/06/06 02:33:30 UTC

[dolphinscheduler] branch dev updated: [improve] Using create or replace function in sql task (#10170)

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

zhongjiajie pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new da3c25dc67 [improve] Using create or replace function in sql task (#10170)
da3c25dc67 is described below

commit da3c25dc6792264d003b6f0a10341f04ef970997
Author: He Zhao <32...@users.noreply.github.com>
AuthorDate: Mon Jun 6 10:33:24 2022 +0800

    [improve] Using create or replace function in sql task (#10170)
---
 docs/docs/en/guide/task/sql.md                                       | 2 ++
 docs/docs/zh/guide/task/sql.md                                       | 3 ++-
 .../java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java    | 5 +++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/docs/docs/en/guide/task/sql.md b/docs/docs/en/guide/task/sql.md
index 294b876fed..04c40fe36c 100644
--- a/docs/docs/en/guide/task/sql.md
+++ b/docs/docs/en/guide/task/sql.md
@@ -46,3 +46,5 @@ Log in to the bigdata cluster and use 'hive' command or 'beeline' or 'JDBC' and
 ## Notice
 
 Pay attention to the selection of SQL type. If it is an insert operation, need to change to "Non-Query" type.
+
+To compatible with long session,UDF function are created by the syntax(CREATE OR REPLACE)
\ No newline at end of file
diff --git a/docs/docs/zh/guide/task/sql.md b/docs/docs/zh/guide/task/sql.md
index 5fd1b13875..f5051d3e83 100644
--- a/docs/docs/zh/guide/task/sql.md
+++ b/docs/docs/zh/guide/task/sql.md
@@ -45,4 +45,5 @@ SQL任务类型,用于连接数据库并执行相应SQL。
 
 ## 注意事项
 
-注意SQL类型的选择,如果是INSERT等操作需要选择非查询类型。
\ No newline at end of file
+* 注意SQL类型的选择,如果是INSERT等操作需要选择非查询类型。 
+* 为了兼容长会话情况,UDF函数的创建是通过CREATE OR REPLACE语句
\ No newline at end of file
diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java
index 8f5c51e4f7..2dcb3b090f 100644
--- a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java
+++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java
@@ -82,8 +82,9 @@ public class SqlTask extends AbstractTaskExecutor {
 
     /**
      * create function format
+     * include replace here which can be compatible with more cases, for example a long-running Spark session in Kyuubi will keep its own temp functions instead of destroying them right away
      */
-    private static final String CREATE_FUNCTION_FORMAT = "create temporary function {0} as ''{1}''";
+    private static final String CREATE_OR_REPLACE_FUNCTION_FORMAT = "create or replace temporary function {0} as ''{1}''";
 
     /**
      * default query sql limit
@@ -479,7 +480,7 @@ public class SqlTask extends AbstractTaskExecutor {
      */
     private List<String> buildTempFuncSql(List<UdfFuncParameters> udfFuncParameters) {
         return udfFuncParameters.stream().map(value -> MessageFormat
-                .format(CREATE_FUNCTION_FORMAT, value.getFuncName(), value.getClassName())).collect(Collectors.toList());
+                .format(CREATE_OR_REPLACE_FUNCTION_FORMAT, value.getFuncName(), value.getClassName())).collect(Collectors.toList());
     }
 
     /**