This is an automated email from the ASF dual-hosted git repository.
zihaoxiang 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 6472576b70 [Fix-18054] [DependentTask] Cannot dependent single task
due to dao error (#18055)
6472576b70 is described below
commit 6472576b70997da2dcdd48b30b7a7a11a8400d1e
Author: Wenjun Ruan <[email protected]>
AuthorDate: Wed Mar 11 21:34:17 2026 +0800
[Fix-18054] [DependentTask] Cannot dependent single task due to dao error
(#18055)
---
.../dolphinscheduler/dao/entity/TaskInstance.java | 12 +--
.../dao/mapper/TaskInstanceMapper.xml | 2 +-
.../dao/repository/impl/CommandDaoImplTest.java | 2 -
.../repository/impl/TaskInstanceDaoImplTest.java | 102 +++++++++++++++++++++
4 files changed, 109 insertions(+), 9 deletions(-)
diff --git
a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
index e60ffb66f6..f94e88b595 100644
---
a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
+++
b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
@@ -25,7 +25,10 @@ import
org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import java.io.Serializable;
import java.util.Date;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Data;
+import lombok.NoArgsConstructor;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
@@ -33,6 +36,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
@TableName("t_ds_task_instance")
public class TaskInstance implements Serializable {
@@ -132,10 +138,4 @@ public class TaskInstance implements Serializable {
private TaskExecuteType taskExecuteType;
- public void init(String host, Date startTime, String executePath) {
- this.host = host;
- this.startTime = startTime;
- this.executePath = executePath;
- }
-
}
diff --git
a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
index e33b472fec..cc0c10c4b7 100644
---
a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
+++
b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
@@ -241,7 +241,7 @@
</include>
from t_ds_task_instance instance
join (
- select task_code, max(end_time) as max_end_time
+ select task_code, max(end_time) as max_end_time, workflow_instance_id
from t_ds_task_instance
where 1=1
and workflow_instance_id = #{workflowInstanceId}
diff --git
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/CommandDaoImplTest.java
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/CommandDaoImplTest.java
index 6022f89a3b..24886f929f 100644
---
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/CommandDaoImplTest.java
+++
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/CommandDaoImplTest.java
@@ -36,9 +36,7 @@ import java.util.List;
import org.junit.jupiter.api.RepeatedTest;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.annotation.DirtiesContext;
-@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
class CommandDaoImplTest extends BaseDaoTest {
@Autowired
diff --git
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImplTest.java
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImplTest.java
new file mode 100644
index 0000000000..226409b197
--- /dev/null
+++
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImplTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.dao.repository.impl;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.dolphinscheduler.common.enums.Flag;
+import org.apache.dolphinscheduler.dao.BaseDaoTest;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+class TaskInstanceDaoImplTest extends BaseDaoTest {
+
+ private static final int WORKFLOW_INSTANCE_ID = 1;
+ private static final long EXTRACT_TASK = 8001L;
+ private static final long TRANSFORM_TASK = 8002L;
+
+ @Autowired
+ private TaskInstanceDao taskInstanceDao;
+
+ @Test
+ void queryLastTaskInstanceListIntervalInWorkflowInstance() {
+ Date earlier = new Date(System.currentTimeMillis() - 3600_000);
+ Date later = new Date();
+
+ insertTaskInstance(EXTRACT_TASK, TaskExecutionStatus.SUCCESS, earlier);
+ insertTaskInstance(EXTRACT_TASK, TaskExecutionStatus.SUCCESS, later);
+ insertTaskInstance(TRANSFORM_TASK, TaskExecutionStatus.SUCCESS, later);
+
+ Set<Long> taskCodes = new HashSet<>(Arrays.asList(EXTRACT_TASK,
TRANSFORM_TASK));
+ List<TaskInstance> result =
taskInstanceDao.queryLastTaskInstanceListIntervalInWorkflowInstance(
+ WORKFLOW_INSTANCE_ID, taskCodes);
+
+ assertEquals(2, result.size());
+ TaskInstance extractResult = result.stream()
+ .filter(ti -> ti.getTaskCode() == EXTRACT_TASK)
+ .findFirst().orElse(null);
+ assertNotNull(extractResult);
+ assertEquals(later.getTime() / 1000,
extractResult.getEndTime().getTime() / 1000);
+ }
+
+ @Test
+ void queryLastTaskInstanceIntervalInWorkflowInstance() {
+ Date earlier = new Date(System.currentTimeMillis() - 3600_000);
+ Date later = new Date();
+
+ insertTaskInstance(EXTRACT_TASK, TaskExecutionStatus.SUCCESS, earlier);
+ insertTaskInstance(EXTRACT_TASK, TaskExecutionStatus.SUCCESS, later);
+
+ TaskInstance result =
taskInstanceDao.queryLastTaskInstanceIntervalInWorkflowInstance(
+ WORKFLOW_INSTANCE_ID, EXTRACT_TASK);
+ assertNotNull(result);
+ assertEquals(later.getTime() / 1000, result.getEndTime().getTime() /
1000);
+ }
+
+ private void insertTaskInstance(long taskCode, TaskExecutionStatus state,
Date endTime) {
+ TaskInstance ti = TaskInstance.builder()
+ .name("shell-task-" + taskCode)
+ .taskType("SHELL")
+ .workflowInstanceId(WORKFLOW_INSTANCE_ID)
+ .workflowInstanceName("daily-etl-pipeline")
+ .taskCode(taskCode)
+ .taskDefinitionVersion(1)
+ .state(state)
+ .flag(Flag.YES)
+ .submitTime(new Date())
+ .firstSubmitTime(new Date())
+ .startTime(new Date())
+ .endTime(endTime)
+ .host("192.168.1.50:5678")
+ .executePath("/tmp/dolphinscheduler/exec/" +
WORKFLOW_INSTANCE_ID + "/" + taskCode)
+ .logPath("/tmp/dolphinscheduler/logs/" + WORKFLOW_INSTANCE_ID
+ "/" + taskCode + ".log")
+ .build();
+ taskInstanceDao.upsertTaskInstance(ti);
+ }
+}