Skip to content

Commit baa7528

Browse files
fm100wslulciuc
andauthored
Fill run state of the parent run when it is created by child run (#2296)
Signed-off-by: Minkyu Park <minkyu.park.200@gmail.com> Signed-off-by: Minkyu Park <minkyu.park.200@gmail.com> Co-authored-by: Willy Lulciuc <willy@datakin.com>
1 parent c868872 commit baa7528

2 files changed

Lines changed: 42 additions & 19 deletions

File tree

api/src/main/java/marquez/db/OpenLineageDao.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -498,25 +498,40 @@ private JobRow createParentJobRunRecord(
498498
RunArgsRow argsRow =
499499
createRunArgsDao()
500500
.upsertRunArgs(UUID.randomUUID(), now, "{}", Utils.checksumFor(ImmutableMap.of()));
501+
502+
Optional<RunState> runState = Optional.ofNullable(event.getEventType()).map(this::getRunState);
503+
RunDao runDao = createRunDao();
501504
RunRow newRow =
502-
createRunDao()
503-
.upsert(
504-
uuid,
505-
null,
506-
facet.getRun().getRunId(),
507-
now,
508-
newParentJobRow.getUuid(),
509-
null,
510-
argsRow.getUuid(),
511-
nominalStartTime,
512-
nominalEndTime,
513-
Optional.ofNullable(event.getEventType()).map(this::getRunState).orElse(null),
514-
now,
515-
namespace.getName(),
516-
newParentJobRow.getName(),
517-
newParentJobRow.getLocation(),
518-
newParentJobRow.getJobContextUuid().orElse(null));
505+
runDao.upsert(
506+
uuid,
507+
null,
508+
facet.getRun().getRunId(),
509+
now,
510+
newParentJobRow.getUuid(),
511+
null,
512+
argsRow.getUuid(),
513+
nominalStartTime,
514+
nominalEndTime,
515+
runState.orElse(null),
516+
now,
517+
namespace.getName(),
518+
newParentJobRow.getName(),
519+
newParentJobRow.getLocation(),
520+
newParentJobRow.getJobContextUuid().orElse(null));
519521
log.info("Created new parent run record {}", newRow);
522+
523+
runState
524+
.map(rs -> createRunStateDao().upsert(UUID.randomUUID(), now, uuid, rs))
525+
.ifPresent(
526+
runStateRow -> {
527+
UUID runStateUuid = runStateRow.getUuid();
528+
if (RunState.valueOf(runStateRow.getState()).isDone()) {
529+
runDao.updateEndState(uuid, now, runStateUuid);
530+
} else {
531+
runDao.updateStartState(uuid, now, runStateUuid);
532+
}
533+
});
534+
520535
return newParentJobRow;
521536
}
522537

api/src/test/java/marquez/OpenLineageIntegrationTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static marquez.db.LineageTestUtils.PRODUCER_URL;
99
import static marquez.db.LineageTestUtils.SCHEMA_URL;
10+
import static org.assertj.core.api.Assertions.as;
1011
import static org.assertj.core.api.Assertions.assertThat;
1112
import static org.junit.jupiter.api.Assertions.assertEquals;
1213

@@ -52,6 +53,7 @@
5253
import marquez.client.models.Run;
5354
import marquez.common.Utils;
5455
import marquez.db.LineageTestUtils;
56+
import org.assertj.core.api.InstanceOfAssertFactories;
5557
import org.jdbi.v3.core.Jdbi;
5658
import org.jetbrains.annotations.NotNull;
5759
import org.junit.jupiter.api.AfterEach;
@@ -170,7 +172,7 @@ public void testSendOpenLineageEventFailsJsonProcessing() throws IOException {
170172
}
171173

172174
@Test
173-
public void testGetLineageForNonExistantDataset() {
175+
public void testGetLineageForNonExistentDataset() {
174176
CompletableFuture<Integer> response =
175177
this.fetchLineage("dataset:Imadethisup:andthistoo")
176178
.thenApply(HttpResponse::statusCode)
@@ -419,7 +421,13 @@ public void testOpenLineageJobHierarchyAirflowIntegrationWithParentOnStartEventO
419421
.hasFieldOrPropertyWithValue("id", new JobId(NAMESPACE_NAME, dagName))
420422
.hasFieldOrPropertyWithValue("parentJobName", null);
421423
List<Run> runsList = client.listRuns(NAMESPACE_NAME, dagName);
422-
assertThat(runsList).isNotEmpty().hasSize(1);
424+
assertThat(runsList)
425+
.isNotEmpty()
426+
.hasSize(1)
427+
.first()
428+
.extracting("startedAt", as(InstanceOfAssertFactories.OPTIONAL))
429+
.get()
430+
.isNotNull();
423431
}
424432

425433
@Test

0 commit comments

Comments
 (0)