This is an automated email from the ASF dual-hosted git repository.
SbloodyS 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 d46079f716 [Fix-18346] countTaskInstanceStateByProjectCodes uses
submit_time filtering (#18347)
d46079f716 is described below
commit d46079f7166b410ede518323a7a4054dec57b895
Author: eye-gu <[email protected]>
AuthorDate: Mon Jun 15 10:07:44 2026 +0800
[Fix-18346] countTaskInstanceStateByProjectCodes uses submit_time filtering
(#18347)
---
.../dao/mapper/TaskInstanceMapper.xml | 4 +-
.../dao/mapper/TaskInstanceMapperTest.java | 44 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
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 cc0c10c4b7..674450ccbb 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
@@ -56,10 +56,10 @@
</foreach>
</if>
<if test="startTime != null">
- and start_time <![CDATA[ > ]]> #{startTime}
+ and submit_time <![CDATA[ > ]]> #{startTime}
</if>
<if test="endTime != null">
- and start_time <![CDATA[ <= ]]> #{endTime}
+ and submit_time <![CDATA[ <= ]]> #{endTime}
</if>
group by state
</select>
diff --git
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
index c9c7aa1901..f51220451e 100644
---
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
+++
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
@@ -86,6 +86,7 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
taskInstance.setFlag(Flag.YES);
taskInstance.setName("us task");
taskInstance.setState(TaskExecutionStatus.RUNNING_EXECUTION);
+ taskInstance.setSubmitTime(new Date());
taskInstance.setStartTime(new Date());
taskInstance.setEndTime(new Date());
taskInstance.setWorkflowInstanceId(processInstanceId);
@@ -233,6 +234,49 @@ public class TaskInstanceMapperTest extends BaseDaoTest {
taskInstanceMapper.deleteById(task.getId());
}
+ /**
+ * test that task instances with null start_time but valid submit_time are
included in time range filter
+ */
+ @Test
+ public void
testCountTaskInstanceStateByProjectCodes_withSubmitTimeFilter() {
+ // insert a task instance with submit_time set but start_time null
(e.g. task not yet started)
+ TaskInstance task = new TaskInstance();
+ task.setFlag(Flag.YES);
+ task.setName("submitted task");
+ task.setState(TaskExecutionStatus.SUBMITTED_SUCCESS);
+ task.setStartTime(null);
+ task.setSubmitTime(new Date());
+ task.setWorkflowInstanceId(1);
+ task.setProjectCode(1L);
+ task.setTaskType("SHELL");
+ taskInstanceMapper.insert(task);
+
+ Date filterStart = new Date(System.currentTimeMillis() - 3600_000);
+ Date filterEnd = new Date(System.currentTimeMillis() + 3600_000);
+
+ // should find the task via submit_time filter
+ List<TaskInstanceStatusCountDto> results =
+ taskInstanceMapper.countTaskInstanceStateByProjectCodes(
+ filterStart,
+ filterEnd,
+ Lists.newArrayList(task.getProjectCode()));
+
+ Assertions.assertEquals(1, results.size());
+ Assertions.assertEquals(TaskExecutionStatus.SUBMITTED_SUCCESS,
results.get(0).getState());
+
+ // time range before submit_time should return empty
+ Date beforeSubmit = new Date(System.currentTimeMillis() - 7200_000);
+ List<TaskInstanceStatusCountDto> emptyResults =
+ taskInstanceMapper.countTaskInstanceStateByProjectCodes(
+ beforeSubmit,
+ filterStart,
+ Lists.newArrayList(task.getProjectCode()));
+
+ Assertions.assertTrue(emptyResults.isEmpty());
+
+ taskInstanceMapper.deleteById(task.getId());
+ }
+
/**
* test page
*/