Unverified Commit 2272802a authored by gaoyan's avatar gaoyan Committed by GitHub

[Fix] Fix UDF task publish NPE (#3144)

parent 6ed014f8
......@@ -143,6 +143,9 @@ public class TaskSaveDTO {
@ApiModelProperty(value = "Statement", dataType = "String", notes = "SQL statement for the task")
private String statement;
@ApiModelProperty(value = "Step", dataType = "Integer", example = "1", notes = "Step for the task")
private Integer step;
public Task toTaskEntity() {
Task task = new Task();
BeanUtil.copyProperties(this, task);
......
......@@ -554,9 +554,15 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
if (lifeCycle == JobLifeCycle.PUBLISH) {
Integer taskVersionId = taskVersionService.createTaskVersionSnapshot(task);
task.setVersionId(taskVersionId);
UdfCodePool.addOrUpdate(UDFUtils.taskToUDF(task.buildTask()));
if (Dialect.isUDF(task.getDialect())) {
UdfCodePool.addOrUpdate(UDFUtils.taskToUDF(task.buildTask()));
}
} else {
UdfCodePool.remove(task.getConfigJson().getUdfConfig().getClassName());
if (Dialect.isUDF(task.getDialect())
&& Asserts.isNotNull(task.getConfigJson())
&& Asserts.isNotNull(task.getConfigJson().getUdfConfig())) {
UdfCodePool.remove(task.getConfigJson().getUdfConfig().getClassName());
}
}
boolean saved = saveOrUpdate(task.buildTask());
if (saved && Asserts.isNotNull(task.getJobInstanceId())) {
......
......@@ -19,6 +19,8 @@
package org.dinky.utils;
import org.dinky.assertion.Asserts;
import org.dinky.data.exception.BusException;
import org.dinky.data.model.Task;
import org.dinky.function.data.model.UDF;
import org.dinky.function.util.UDFUtil;
......@@ -28,10 +30,15 @@ import org.apache.flink.table.catalog.FunctionLanguage;
public class UDFUtils extends UDFUtil {
public static UDF taskToUDF(Task task) {
return UDF.builder()
.className(task.getConfigJson().getUdfConfig().getClassName())
.code(task.getStatement())
.functionLanguage(FunctionLanguage.valueOf(task.getDialect().toUpperCase()))
.build();
if (Asserts.isNotNull(task.getConfigJson())
&& Asserts.isNotNull(task.getConfigJson().getUdfConfig())) {
return UDF.builder()
.className(task.getConfigJson().getUdfConfig().getClassName())
.code(task.getStatement())
.functionLanguage(FunctionLanguage.valueOf(task.getDialect().toUpperCase()))
.build();
} else {
throw new BusException("udf `class` config is null,please check your udf task config");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment