-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide simple implementation of one-level lineage optimized for parent jobs #2657
Open
julienledem
wants to merge
10
commits into
main
Choose a base branch
from
simple_lineage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
41c2439
provide simple implementation of one-level lineage optimized for pare…
julienledem 023985e
spotless apply
julienledem 72c96f7
cleanup test
julienledem 47cc1d5
cleanup test
julienledem a38028b
rename to direct lineage; use jobs_view in sql; replace simple_name w…
julienledem c14c836
add LineageService test
julienledem 95d43e4
add LineageService test
julienledem 53ff595
fixing integration tests
julienledem efa46fe
Merge branch 'main' into simple_lineage
julienledem e7af696
add javadoc to mapper
julienledem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import marquez.common.models.DatasetId; | ||
import marquez.common.models.JobId; | ||
import marquez.db.mappers.DatasetDataMapper; | ||
import marquez.db.mappers.DirectLineageEdgeMapper; | ||
import marquez.db.mappers.JobDataMapper; | ||
import marquez.db.mappers.JobRowMapper; | ||
import marquez.db.mappers.RunMapper; | ||
|
@@ -25,8 +28,19 @@ | |
@RegisterRowMapper(JobDataMapper.class) | ||
@RegisterRowMapper(RunMapper.class) | ||
@RegisterRowMapper(JobRowMapper.class) | ||
@RegisterRowMapper(DirectLineageEdgeMapper.class) | ||
public interface LineageDao { | ||
|
||
public record DirectLineage(Collection<DirectLineageEdge> edges) {} | ||
|
||
public record DirectLineageEdge( | ||
JobId job1, | ||
String direction, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using existing |
||
DatasetId dataset, | ||
String direction2, | ||
JobId job2, | ||
JobId job2parent) {} | ||
|
||
/** | ||
* Fetch all of the jobs that consume or produce the datasets that are consumed or produced by the | ||
* input jobIds. This returns a single layer from the BFS using datasets as edges. Jobs that have | ||
|
@@ -79,6 +93,34 @@ SELECT DISTINCT ON (j.uuid) j.*, inputs AS input_uuids, outputs AS output_uuids | |
""") | ||
Set<JobData> getLineage(@BindList Set<UUID> jobIds, int depth); | ||
|
||
/** | ||
* 1 level of lineage for all the children jobs of the given parent | ||
* | ||
* @param parentJobNamespace the namespace of the parent | ||
* @param parentJobName the name of the parent | ||
* @return edges form job to dataset to job | ||
*/ | ||
@SqlQuery( | ||
""" | ||
SELECT | ||
jobs.namespace_name AS job_namespace, jobs."name" AS job_name, | ||
jvim.io_type AS io1, | ||
d.namespace_name AS ds_namespace, d."name" AS ds_name, | ||
jvim2.io_type AS io2, | ||
jv2.namespace_name AS job2_namespace, jv2.job_name AS job2_name, | ||
jv2.namespace_name AS job2_parent_namespace, j2.parent_job_name AS job2_parent_name | ||
FROM jobs_view jobs | ||
INNER JOIN job_versions jv ON jv.uuid = jobs.current_version_uuid | ||
LEFT JOIN job_versions_io_mapping jvim ON jvim.job_version_uuid = jobs.current_version_uuid | ||
LEFT JOIN datasets d ON d.uuid = jvim.dataset_uuid | ||
LEFT JOIN job_versions_io_mapping jvim2 ON jvim2.dataset_uuid = d.uuid AND jvim2.job_version_uuid <> jvim.job_version_uuid AND jvim2.io_type <> jvim.io_type | ||
LEFT JOIN job_versions jv2 ON jv2.uuid = jvim2.job_version_uuid | ||
LEFT JOIN jobs_view j2 ON jv2.job_uuid = j2.uuid | ||
WHERE jobs.namespace_name = :parentJobNamespace AND jobs.parent_job_name = :parentJobName ; | ||
""") | ||
Collection<DirectLineageEdge> getDirectLineageFromParent( | ||
String parentJobNamespace, String parentJobName); | ||
|
||
@SqlQuery( | ||
""" | ||
SELECT ds.*, dv.fields, dv.lifecycle_state | ||
|
54 changes: 54 additions & 0 deletions
54
api/src/main/java/marquez/db/mappers/DirectLineageEdgeMapper.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,54 @@ | ||
/* | ||
* Copyright 2023 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package marquez.db.mappers; | ||
|
||
import static marquez.db.Columns.stringOrNull; | ||
import static marquez.db.Columns.stringOrThrow; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import lombok.NonNull; | ||
import marquez.common.models.DatasetId; | ||
import marquez.common.models.DatasetName; | ||
import marquez.common.models.JobId; | ||
import marquez.common.models.JobName; | ||
import marquez.common.models.NamespaceName; | ||
import marquez.db.LineageDao.DirectLineageEdge; | ||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
|
||
/** Maps the result set of direct lineage to a DirectLineageEdge */ | ||
public final class DirectLineageEdgeMapper implements RowMapper<DirectLineageEdge> { | ||
@Override | ||
public DirectLineageEdge map(@NonNull ResultSet results, @NonNull StatementContext context) | ||
throws SQLException { | ||
JobId job1 = | ||
JobId.of( | ||
NamespaceName.of(stringOrThrow(results, "job_namespace")), | ||
JobName.of(stringOrThrow(results, "job_name"))); | ||
String io1 = stringOrNull(results, "io1"); | ||
String ds_namespace = stringOrNull(results, "ds_namespace"); | ||
DatasetId ds = | ||
ds_namespace == null | ||
? null | ||
: new DatasetId( | ||
NamespaceName.of(ds_namespace), DatasetName.of(stringOrNull(results, "ds_name"))); | ||
String io2 = stringOrNull(results, "io2"); | ||
String job2_namespace = stringOrNull(results, "job2_namespace"); | ||
JobId job2 = | ||
job2_namespace == null | ||
? null | ||
: JobId.of( | ||
NamespaceName.of(job2_namespace), JobName.of(stringOrThrow(results, "job2_name"))); | ||
String job2parent_namespace = stringOrNull(results, "job2_parent_namespace"); | ||
JobId job2parent = | ||
job2parent_namespace == null | ||
? null | ||
: JobId.of( | ||
NamespaceName.of(job2parent_namespace), | ||
JobName.of(stringOrThrow(results, "job2_parent_name"))); | ||
return new DirectLineageEdge(job1, io1, ds, io2, job2, job2parent); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mind updating
openapi.yaml
andchangeling