Repository navigation
feat(cli): emit lineage for assertions and property graphs #2368
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 @@ | ||
| import { dataform } from "df/protos/ts"; | ||
|
|
||
| /** | ||
| * Lineage action-type rule shared with the Dataform Backend (DD §4.3): | ||
| * every action that runs a BigQuery job emits lineage events. Declarations | ||
| * and other action types that don't run a BigQuery job are excluded. | ||
| * | ||
| * Maps the CLI's execution action type to the value sent in | ||
| * `gcp_bq_pipelines_job.actionType`. Values mirror the Backend's | ||
| * `WorkflowExecutionActionInfo.DataformActionType` enum names so both | ||
| * runtimes report the same action type to Knowledge Catalog Lineage. | ||
| */ | ||
| const LINEAGE_ACTION_TYPES: { readonly [executionType: string]: string } = { | ||
| table: "TABLE", | ||
| operation: "OPERATIONS", | ||
|
rafal-hawrylak marked this conversation as resolved.
Resolved
|
||
| assertion: "ASSERTION", | ||
| propertyGraph: "PROPERTY_GRAPH", | ||
|
rafal-hawrylak marked this conversation as resolved.
Resolved
|
||
| }; | ||
|
|
||
| /** Returns true if lineage events are emitted for the given action. */ | ||
| export function isLineageEligibleAction(action: dataform.IExecutionAction): boolean { | ||
|
rafal-hawrylak marked this conversation as resolved.
Resolved
|
||
| return Object.prototype.hasOwnProperty.call(LINEAGE_ACTION_TYPES, action.type || ""); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the `gcp_bq_pipelines_job.actionType` value for the given action, | ||
| * or undefined if the action type is not lineage-eligible. | ||
| */ | ||
| export function toLineageActionType(action: dataform.IExecutionAction): string | undefined { | ||
| return isLineageEligibleAction(action) ? LINEAGE_ACTION_TYPES[action.type] : undefined; | ||
|
rafal-hawrylak marked this conversation as resolved.
Resolved
|
||
| } | ||
This file contains hidden or 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,35 @@ | ||
| import { expect } from "chai"; | ||
|
|
||
| import { isLineageEligibleAction, toLineageActionType } from "df/cli/api/lineage/action_type"; | ||
| import { dataform } from "df/protos/ts"; | ||
| import { suite, test } from "df/testing"; | ||
|
|
||
| function actionOfType(type: string): dataform.IExecutionAction { | ||
| return dataform.ExecutionAction.create({ | ||
| target: { database: "proj", schema: "schema", name: "name" }, | ||
| type, | ||
| }); | ||
| } | ||
|
|
||
| suite("lineage action_type", () => { | ||
| test("actions that run a BigQuery job are eligible and map to Backend enum names", () => { | ||
| const mapped = ["table", "operation", "assertion", "propertyGraph"].map((type) => ({ | ||
| type, | ||
| eligible: isLineageEligibleAction(actionOfType(type)), | ||
| actionType: toLineageActionType(actionOfType(type)), | ||
| })); | ||
| expect(mapped).to.deep.equal([ | ||
| { type: "table", eligible: true, actionType: "TABLE" }, | ||
| { type: "operation", eligible: true, actionType: "OPERATIONS" }, | ||
| { type: "assertion", eligible: true, actionType: "ASSERTION" }, | ||
| { type: "propertyGraph", eligible: true, actionType: "PROPERTY_GRAPH" }, | ||
| ]); | ||
| }); | ||
|
|
||
| test("declarations, unknown and missing types are not eligible", () => { | ||
| for (const type of ["declaration", "notebook", "unknown", "", "toString"]) { | ||
| expect(isLineageEligibleAction(actionOfType(type)), type).to.equal(false); | ||
| expect(toLineageActionType(actionOfType(type)), type).to.equal(undefined); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.