|
16 | 16 | import java.util.LinkedList; |
17 | 17 | import java.util.List; |
18 | 18 | import java.util.Optional; |
| 19 | +import java.util.UUID; |
19 | 20 | import java.util.stream.Collectors; |
20 | 21 | import marquez.api.JdbiUtils; |
21 | 22 | import marquez.common.models.DatasetId; |
|
56 | 57 | import org.junit.jupiter.api.BeforeAll; |
57 | 58 | import org.junit.jupiter.api.Test; |
58 | 59 | import org.junit.jupiter.api.extension.ExtendWith; |
| 60 | +import org.testcontainers.shaded.com.google.common.collect.ImmutableMap; |
59 | 61 |
|
60 | 62 | @ExtendWith(MarquezJdbiExternalPostgresExtension.class) |
61 | 63 | public class LineageServiceTest { |
@@ -427,6 +429,77 @@ public void testLineageWithWithCycle() { |
427 | 429 | .matches(n -> n.isJobType() && n.asJobId().getName().getValue().equals("writeJob")); |
428 | 430 | } |
429 | 431 |
|
| 432 | + @Test |
| 433 | + public void testGetLineageJobRunTwice() { |
| 434 | + Dataset input = Dataset.builder().name("input-dataset").namespace(NAMESPACE).build(); |
| 435 | + Dataset output = Dataset.builder().name("output-dataset").namespace(NAMESPACE).build(); |
| 436 | + UUID runId = UUID.randomUUID(); |
| 437 | + |
| 438 | + // (1) Run batch job which outputs input-dataset |
| 439 | + LineageTestUtils.createLineageRow( |
| 440 | + openLineageDao, |
| 441 | + "someJob", |
| 442 | + runId, |
| 443 | + "START", |
| 444 | + jobFacet, |
| 445 | + Arrays.asList(input), |
| 446 | + Collections.emptyList(), |
| 447 | + null, |
| 448 | + ImmutableMap.of()); |
| 449 | + |
| 450 | + LineageTestUtils.createLineageRow( |
| 451 | + openLineageDao, |
| 452 | + "someJob", |
| 453 | + runId, |
| 454 | + "COMPLETE", |
| 455 | + jobFacet, |
| 456 | + Collections.emptyList(), |
| 457 | + Arrays.asList(output), |
| 458 | + null, |
| 459 | + ImmutableMap.of()); |
| 460 | + |
| 461 | + // (2) Rerun it |
| 462 | + LineageTestUtils.createLineageRow( |
| 463 | + openLineageDao, |
| 464 | + "someJob", |
| 465 | + runId, |
| 466 | + "START", |
| 467 | + jobFacet, |
| 468 | + Arrays.asList(input), |
| 469 | + Collections.emptyList(), |
| 470 | + null, |
| 471 | + ImmutableMap.of()); |
| 472 | + |
| 473 | + LineageTestUtils.createLineageRow( |
| 474 | + openLineageDao, |
| 475 | + "someJob", |
| 476 | + runId, |
| 477 | + "COMPLETE", |
| 478 | + jobFacet, |
| 479 | + Collections.emptyList(), |
| 480 | + Arrays.asList(output), |
| 481 | + null, |
| 482 | + ImmutableMap.of()); |
| 483 | + |
| 484 | + // (4) lineage on output dataset shall be same as lineage on input dataset |
| 485 | + Lineage lineageFromInput = |
| 486 | + lineageService.lineage( |
| 487 | + NodeId.of( |
| 488 | + new DatasetId(new NamespaceName(NAMESPACE), new DatasetName("input-dataset"))), |
| 489 | + 5, |
| 490 | + true); |
| 491 | + |
| 492 | + Lineage lineageFromOutput = |
| 493 | + lineageService.lineage( |
| 494 | + NodeId.of( |
| 495 | + new DatasetId(new NamespaceName(NAMESPACE), new DatasetName("output-dataset"))), |
| 496 | + 5, |
| 497 | + true); |
| 498 | + |
| 499 | + assertThat(lineageFromInput.getGraph()).hasSize(3); // 2 datasets + 1 job |
| 500 | + assertThat(lineageFromInput.getGraph()).isEqualTo(lineageFromOutput.getGraph()); |
| 501 | + } |
| 502 | + |
430 | 503 | @Test |
431 | 504 | public void testGetLineageForRunningStreamingJob() { |
432 | 505 | Dataset input = Dataset.builder().name("input-dataset").namespace(NAMESPACE).build(); |
|
0 commit comments