Skip to content

Commit

Permalink
[Fix] Fix UDF task publish NPE (DataLinkDC#3144)
Browse files Browse the repository at this point in the history
Co-authored-by: gaoyan1998 <[email protected]>
  • Loading branch information
gaoyan1998 and gaoyan1998 authored Feb 5, 2024
1 parent 6ed014f commit 2272802
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/dto/TaskSaveDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,15 @@ public boolean changeTaskLifeRecyle(Integer taskId, JobLifeCycle lifeCycle) thro
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())) {
Expand Down
17 changes: 12 additions & 5 deletions dinky-admin/src/main/java/org/dinky/utils/UDFUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,10 +30,15 @@
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");
}
}
}

0 comments on commit 2272802

Please sign in to comment.