-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
- Loading branch information
1 parent
9316120
commit c4e8f0c
Showing
22 changed files
with
705 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
api/src/test/java/marquez/ColumnLineageIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez; | ||
|
||
import static marquez.db.ColumnLineageTestUtils.getDatasetA; | ||
import static marquez.db.ColumnLineageTestUtils.getDatasetB; | ||
import static marquez.db.ColumnLineageTestUtils.getDatasetC; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import marquez.api.JdbiUtils; | ||
import marquez.client.MarquezClient; | ||
import marquez.client.models.Node; | ||
import marquez.db.LineageTestUtils; | ||
import marquez.db.OpenLineageDao; | ||
import marquez.jdbi.MarquezJdbiExternalPostgresExtension; | ||
import marquez.service.models.LineageEvent; | ||
import org.jdbi.v3.core.Jdbi; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@org.junit.jupiter.api.Tag("IntegrationTests") | ||
@ExtendWith(MarquezJdbiExternalPostgresExtension.class) | ||
public class ColumnLineageIntegrationTest extends BaseIntegrationTest { | ||
|
||
@BeforeEach | ||
public void setup(Jdbi jdbi) { | ||
OpenLineageDao openLineageDao = jdbi.onDemand(OpenLineageDao.class); | ||
|
||
LineageEvent.JobFacet jobFacet = | ||
new LineageEvent.JobFacet(null, null, null, LineageTestUtils.EMPTY_MAP); | ||
|
||
LineageEvent.Dataset dataset_A = getDatasetA(); | ||
LineageEvent.Dataset dataset_B = getDatasetB(); | ||
LineageEvent.Dataset dataset_C = getDatasetC(); | ||
|
||
LineageTestUtils.createLineageRow( | ||
openLineageDao, | ||
"job1", | ||
"COMPLETE", | ||
jobFacet, | ||
Arrays.asList(dataset_A), | ||
Arrays.asList(dataset_B)); | ||
|
||
LineageTestUtils.createLineageRow( | ||
openLineageDao, | ||
"job2", | ||
"COMPLETE", | ||
jobFacet, | ||
Arrays.asList(dataset_B), | ||
Arrays.asList(dataset_C)); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown(Jdbi jdbi) { | ||
JdbiUtils.cleanDatabase(jdbi); | ||
} | ||
|
||
@Test | ||
public void testColumnLineageEndpointByDataset() { | ||
MarquezClient.Lineage lineage = client.getColumnLineage("namespace", "dataset_b"); | ||
|
||
assertThat(lineage.getGraph()).hasSize(3); | ||
assertThat(getNodeByFieldName(lineage, "col_a")).isPresent(); | ||
assertThat(getNodeByFieldName(lineage, "col_b")).isPresent(); | ||
assertThat(getNodeByFieldName(lineage, "col_c")).isPresent(); | ||
} | ||
|
||
@Test | ||
public void testColumnLineageEndpointByDatasetField() { | ||
MarquezClient.Lineage lineage = client.getColumnLineage("namespace", "dataset_b", "col_c"); | ||
|
||
assertThat(lineage.getGraph()).hasSize(3); | ||
assertThat(getNodeByFieldName(lineage, "col_a")).isPresent(); | ||
assertThat(getNodeByFieldName(lineage, "col_b")).isPresent(); | ||
assertThat(getNodeByFieldName(lineage, "col_c")).isPresent(); | ||
} | ||
|
||
@Test | ||
public void testColumnLineageEndpointWithDepthLimit() { | ||
MarquezClient.Lineage lineage = | ||
client.getColumnLineage("namespace", "dataset_c", "col_d", 1, false); | ||
|
||
assertThat(lineage.getGraph()).hasSize(2); | ||
assertThat(getNodeByFieldName(lineage, "col_c")).isPresent(); | ||
assertThat(getNodeByFieldName(lineage, "col_d")).isPresent(); | ||
} | ||
|
||
@Test | ||
public void testColumnLineageEndpointWithDownstream() { | ||
MarquezClient.Lineage lineage = | ||
client.getColumnLineage("namespace", "dataset_b", "col_c", 10, true); | ||
|
||
assertThat(lineage.getGraph()).hasSize(4); | ||
assertThat(getNodeByFieldName(lineage, "col_d")).isPresent(); | ||
} | ||
|
||
private Optional<Node> getNodeByFieldName(MarquezClient.Lineage lineage, String field) { | ||
return lineage.getGraph().stream() | ||
.filter(n -> n.getId().asDatasetFieldId().getField().equals(field)) | ||
.findAny(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
clients/java/src/main/java/marquez/client/models/ColumnLineageNodeData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.client.models; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import marquez.client.Utils; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
public class ColumnLineageNodeData implements NodeData { | ||
@NonNull String namespace; | ||
@NonNull String dataset; | ||
@NonNull String field; | ||
@NonNull String fieldType; | ||
@NonNull String transformationDescription; | ||
@NonNull String transformationType; | ||
@NonNull List<DatasetFieldId> inputFields; | ||
|
||
public static ColumnLineageNodeData fromJson(@NonNull final String json) { | ||
return Utils.fromJson(json, new TypeReference<ColumnLineageNodeData>() {}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
clients/java/src/main/java/marquez/client/models/DatasetFieldId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.client.models; | ||
|
||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
@Value | ||
public class DatasetFieldId { | ||
@NonNull String namespace; | ||
@NonNull String dataset; | ||
@NonNull String field; | ||
} |
27 changes: 27 additions & 0 deletions
27
clients/java/src/main/java/marquez/client/models/Edge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.client.models; | ||
|
||
import java.util.Comparator; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
@Value | ||
public class Edge implements Comparable<Edge> { | ||
@NonNull NodeId origin; | ||
@NonNull NodeId destination; | ||
|
||
public static Edge of(@NonNull final NodeId origin, @NonNull final NodeId destination) { | ||
return new Edge(origin, destination); | ||
} | ||
|
||
@Override | ||
public int compareTo(Edge o) { | ||
return Comparator.comparing(Edge::getOrigin) | ||
.thenComparing(Edge::getDestination) | ||
.compare(this, o); | ||
} | ||
} |
Oops, something went wrong.