-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to infer primary key of model (#9650)
- Loading branch information
aliceliu
authored
Feb 26, 2024
1 parent
d1ebf9d
commit 2b23a03
Showing
5 changed files
with
345 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Implement primary key inference for model nodes | ||
time: 2024-02-23T11:50:21.257494-08:00 | ||
custom: | ||
Author: aliceliu | ||
Issue: "9652" |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from dbt.contracts.files import FileHash | ||
from dbt.contracts.graph.nodes import ( | ||
DependsOn, | ||
InjectedCTE, | ||
ModelNode, | ||
ModelConfig, | ||
GenericTestNode, | ||
) | ||
from dbt.node_types import NodeType | ||
|
||
from dbt.artifacts.resources import Contract, TestConfig, TestMetadata | ||
|
||
|
||
def model_node(): | ||
return ModelNode( | ||
package_name="test", | ||
path="/root/models/foo.sql", | ||
original_file_path="models/foo.sql", | ||
language="sql", | ||
raw_code='select * from {{ ref("other") }}', | ||
name="foo", | ||
resource_type=NodeType.Model, | ||
unique_id="model.test.foo", | ||
fqn=["test", "models", "foo"], | ||
refs=[], | ||
sources=[], | ||
metrics=[], | ||
depends_on=DependsOn(), | ||
deferred=True, | ||
description="", | ||
database="test_db", | ||
schema="test_schema", | ||
alias="bar", | ||
tags=[], | ||
config=ModelConfig(), | ||
contract=Contract(), | ||
meta={}, | ||
compiled=True, | ||
extra_ctes=[InjectedCTE("whatever", "select * from other")], | ||
extra_ctes_injected=True, | ||
compiled_code="with whatever as (select * from other) select * from whatever", | ||
checksum=FileHash.from_contents(""), | ||
unrendered_config={}, | ||
) | ||
|
||
|
||
def generic_test_node(): | ||
return GenericTestNode( | ||
package_name="test", | ||
path="/root/x/path.sql", | ||
original_file_path="/root/path.sql", | ||
language="sql", | ||
raw_code='select * from {{ ref("other") }}', | ||
name="foo", | ||
resource_type=NodeType.Test, | ||
unique_id="model.test.foo", | ||
fqn=["test", "models", "foo"], | ||
refs=[], | ||
sources=[], | ||
metrics=[], | ||
depends_on=DependsOn(), | ||
deferred=False, | ||
description="", | ||
database="test_db", | ||
schema="dbt_test__audit", | ||
alias="bar", | ||
tags=[], | ||
config=TestConfig(severity="warn"), | ||
contract=Contract(), | ||
meta={}, | ||
compiled=True, | ||
extra_ctes=[InjectedCTE("whatever", "select * from other")], | ||
extra_ctes_injected=True, | ||
compiled_code="with whatever as (select * from other) select * from whatever", | ||
column_name="id", | ||
test_metadata=TestMetadata(namespace=None, name="foo", kwargs={}), | ||
checksum=FileHash.from_contents(""), | ||
unrendered_config={ | ||
"severity": "warn", | ||
}, | ||
) |
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.