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 { ...@@ -143,6 +143,9 @@ public class TaskSaveDTO {
@ApiModelProperty(value = "Statement", dataType = "String", notes = "SQL statement for the task") @ApiModelProperty(value = "Statement", dataType = "String", notes = "SQL statement for the task")
private String statement; private String statement;
@ApiModelProperty(value = "Step", dataType = "Integer", example = "1", notes = "Step for the task")
private Integer step;
public Task toTaskEntity() { public Task toTaskEntity() {
Task task = new Task(); Task task = new Task();
BeanUtil.copyProperties(this, task); BeanUtil.copyProperties(this, task);
......
...@@ -554,10 +554,16 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -554,10 +554,16 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
if (lifeCycle == JobLifeCycle.PUBLISH) { if (lifeCycle == JobLifeCycle.PUBLISH) {
Integer taskVersionId = taskVersionService.createTaskVersionSnapshot(task); Integer taskVersionId = taskVersionService.createTaskVersionSnapshot(task);
task.setVersionId(taskVersionId); task.setVersionId(taskVersionId);
if (Dialect.isUDF(task.getDialect())) {
UdfCodePool.addOrUpdate(UDFUtils.taskToUDF(task.buildTask())); UdfCodePool.addOrUpdate(UDFUtils.taskToUDF(task.buildTask()));
}
} else { } else {
if (Dialect.isUDF(task.getDialect())
&& Asserts.isNotNull(task.getConfigJson())
&& Asserts.isNotNull(task.getConfigJson().getUdfConfig())) {
UdfCodePool.remove(task.getConfigJson().getUdfConfig().getClassName()); UdfCodePool.remove(task.getConfigJson().getUdfConfig().getClassName());
} }
}
boolean saved = saveOrUpdate(task.buildTask()); boolean saved = saveOrUpdate(task.buildTask());
if (saved && Asserts.isNotNull(task.getJobInstanceId())) { if (saved && Asserts.isNotNull(task.getJobInstanceId())) {
JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId()); JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId());
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.dinky.utils; package org.dinky.utils;
import org.dinky.assertion.Asserts;
import org.dinky.data.exception.BusException;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
import org.dinky.function.data.model.UDF; import org.dinky.function.data.model.UDF;
import org.dinky.function.util.UDFUtil; import org.dinky.function.util.UDFUtil;
...@@ -28,10 +30,15 @@ import org.apache.flink.table.catalog.FunctionLanguage; ...@@ -28,10 +30,15 @@ import org.apache.flink.table.catalog.FunctionLanguage;
public class UDFUtils extends UDFUtil { public class UDFUtils extends UDFUtil {
public static UDF taskToUDF(Task task) { public static UDF taskToUDF(Task task) {
if (Asserts.isNotNull(task.getConfigJson())
&& Asserts.isNotNull(task.getConfigJson().getUdfConfig())) {
return UDF.builder() return UDF.builder()
.className(task.getConfigJson().getUdfConfig().getClassName()) .className(task.getConfigJson().getUdfConfig().getClassName())
.code(task.getStatement()) .code(task.getStatement())
.functionLanguage(FunctionLanguage.valueOf(task.getDialect().toUpperCase())) .functionLanguage(FunctionLanguage.valueOf(task.getDialect().toUpperCase()))
.build(); .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