Skip to content
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

Exposures support metrics #6342

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20221130-112913.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Exposures support metrics in lineage
time: 2022-11-30T11:29:13.256034-05:00
custom:
Author: michelleark
Issue: "6057"
PR: "6342"
14 changes: 14 additions & 0 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,14 @@ def __call__(self, *args) -> str:
return ""


class ExposureMetricResolver(BaseResolver):
def __call__(self, *args) -> str:
if len(args) not in (1, 2):
metric_invalid_args(self.model, args)
self.model.metrics.append(list(args))
return ""


def generate_parse_exposure(
exposure: ParsedExposure,
config: RuntimeConfig,
Expand All @@ -1455,6 +1463,12 @@ def generate_parse_exposure(
project,
manifest,
),
"metric": ExposureMetricResolver(
None,
exposure,
project,
manifest,
),
}


Expand Down
1 change: 1 addition & 0 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ class ParsedExposure(UnparsedBaseNode, HasUniqueID, HasFqn):
depends_on: DependsOn = field(default_factory=DependsOn)
refs: List[List[str]] = field(default_factory=list)
sources: List[List[str]] = field(default_factory=list)
metrics: List[List[str]] = field(default_factory=list)
created_at: float = field(default_factory=lambda: time.time())

@property
Expand Down
8 changes: 7 additions & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@ def process_metrics(self, config: RuntimeConfig):
if metric.created_at < self.started_at:
continue
_process_metrics_for_node(self.manifest, current_project, metric)
for exposure in self.manifest.exposures.values():
if exposure.created_at < self.started_at:
continue
_process_metrics_for_node(self.manifest, current_project, exposure)

# nodes: node and column descriptions
# sources: source and table descriptions, column descriptions
Expand Down Expand Up @@ -1180,7 +1184,9 @@ def _process_refs_for_metric(manifest: Manifest, current_project: str, metric: P


def _process_metrics_for_node(
manifest: Manifest, current_project: str, node: Union[ManifestNode, ParsedMetric]
manifest: Manifest,
current_project: str,
node: Union[ManifestNode, ParsedMetric, ParsedExposure],
):
"""Given a manifest and a node in that manifest, process its metrics"""
for metric in node.metrics:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ def parse_exposure(self, unparsed: UnparsedExposure):
)
depends_on_jinja = "\n".join("{{ " + line + "}}" for line in unparsed.depends_on)
get_rendered(depends_on_jinja, ctx, parsed, capture_macros=True)
# parsed now has a populated refs/sources
# parsed now has a populated refs/sources/metrics

if parsed.config.enabled:
self.manifest.add_exposure(self.yaml.file, parsed)
Expand Down
64 changes: 37 additions & 27 deletions schemas/dbt/manifest/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"generated_at": {
"type": "string",
"format": "date-time",
"default": "2022-11-01T18:01:47.759437Z"
"default": "2022-11-30T05:36:16.443035Z"
},
"invocation_id": {
"oneOf": [
Expand All @@ -255,7 +255,7 @@
"type": "null"
}
],
"default": "94cf6dd0-d59b-4139-bf79-70055cb9bb34"
"default": "ff51bdcd-689d-45b3-8dbb-5a8016382eef"
},
"env": {
"type": "object",
Expand Down Expand Up @@ -519,7 +519,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.764821
"default": 1669786576.4447858
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1066,7 +1066,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.767402
"default": 1669786576.445715
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1425,7 +1425,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.768972
"default": 1669786576.4462662
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1672,7 +1672,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.7706041
"default": 1669786576.446837
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -1929,7 +1929,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.772256
"default": 1669786576.447436
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -2176,7 +2176,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.7739131
"default": 1669786576.448
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -2419,7 +2419,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.7757251
"default": 1669786576.448638
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -2714,7 +2714,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.7787
"default": 1669786576.449645
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -3136,7 +3136,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.780513
"default": 1669786576.450196
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -3379,7 +3379,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.782298
"default": 1669786576.450721
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -3583,7 +3583,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.7835789
"default": 1669786576.451207
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -3795,7 +3795,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.784904
"default": 1669786576.451676
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -4017,7 +4017,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.78629
"default": 1669786576.452158
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -4229,7 +4229,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.78762
"default": 1669786576.452618
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -4441,7 +4441,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.789003
"default": 1669786576.453086
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -4649,7 +4649,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.790516
"default": 1669786576.4535701
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -4882,7 +4882,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.792015
"default": 1669786576.454068
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -5081,7 +5081,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.794882
"default": 1669786576.454986
},
"config_call_dict": {
"type": "object",
Expand Down Expand Up @@ -5462,7 +5462,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.797194
"default": 1669786576.455929
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -5577,7 +5577,7 @@
"generated_at": {
"type": "string",
"format": "date-time",
"default": "2022-11-01T18:01:47.754102Z"
"default": "2022-11-30T05:36:16.440838Z"
},
"invocation_id": {
"oneOf": [
Expand All @@ -5588,7 +5588,7 @@
"type": "null"
}
],
"default": "94cf6dd0-d59b-4139-bf79-70055cb9bb34"
"default": "ff51bdcd-689d-45b3-8dbb-5a8016382eef"
},
"env": {
"type": "object",
Expand Down Expand Up @@ -5948,7 +5948,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.798143
"default": 1669786576.45632
},
"supported_languages": {
"oneOf": [
Expand Down Expand Up @@ -6199,13 +6199,23 @@
},
"default": []
},
"metrics": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "string"
}
},
"default": []
},
"created_at": {
"type": "number",
"default": 1667325707.799795
"default": 1669786576.456964
}
},
"additionalProperties": false,
"description": "ParsedExposure(fqn: List[str], unique_id: str, package_name: str, path: str, original_file_path: str, name: str, type: dbt.contracts.graph.unparsed.ExposureType, owner: dbt.contracts.graph.unparsed.ExposureOwner, resource_type: dbt.node_types.NodeType = <NodeType.Exposure: 'exposure'>, description: str = '', label: Optional[str] = None, maturity: Optional[dbt.contracts.graph.unparsed.MaturityType] = None, meta: Dict[str, Any] = <factory>, tags: List[str] = <factory>, config: dbt.contracts.graph.model_config.ExposureConfig = <factory>, unrendered_config: Dict[str, Any] = <factory>, url: Optional[str] = None, depends_on: dbt.contracts.graph.parsed.DependsOn = <factory>, refs: List[List[str]] = <factory>, sources: List[List[str]] = <factory>, created_at: float = <factory>)"
"description": "ParsedExposure(fqn: List[str], unique_id: str, package_name: str, path: str, original_file_path: str, name: str, type: dbt.contracts.graph.unparsed.ExposureType, owner: dbt.contracts.graph.unparsed.ExposureOwner, resource_type: dbt.node_types.NodeType = <NodeType.Exposure: 'exposure'>, description: str = '', label: Optional[str] = None, maturity: Optional[dbt.contracts.graph.unparsed.MaturityType] = None, meta: Dict[str, Any] = <factory>, tags: List[str] = <factory>, config: dbt.contracts.graph.model_config.ExposureConfig = <factory>, unrendered_config: Dict[str, Any] = <factory>, url: Optional[str] = None, depends_on: dbt.contracts.graph.parsed.DependsOn = <factory>, refs: List[List[str]] = <factory>, sources: List[List[str]] = <factory>, metrics: List[List[str]] = <factory>, created_at: float = <factory>)"
},
"ExposureOwner": {
"type": "object",
Expand Down Expand Up @@ -6424,7 +6434,7 @@
},
"created_at": {
"type": "number",
"default": 1667325707.801514
"default": 1669786576.4576042
}
},
"additionalProperties": false,
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@ def basic_parsed_exposure_dict():
},
'refs': [],
'sources': [],
'metrics': [],
'fqn': ['test', 'exposures', 'my_exposure'],
'unique_id': 'exposure.test.my_exposure',
'package_name': 'test',
Expand Down Expand Up @@ -2191,6 +2192,7 @@ def complex_parsed_exposure_dict():
},
'refs': [],
'sources': [],
'metrics': [],
'fqn': ['test', 'exposures', 'my_exposure'],
'unique_id': 'exposure.test.my_exposure',
'package_name': 'test',
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/artifacts/expected_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False):
"fqn": ["test", "notebook_exposure"],
"maturity": "medium",
"meta": {"tool": "my_tool", "languages": ["python"]},
"metrics": [],
"tags": ["my_department"],
"name": "notebook_exposure",
"original_file_path": os.path.join("models", "schema.yml"),
Expand All @@ -770,6 +771,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False):
"enabled": True,
},
"fqn": ["test", "simple_exposure"],
"metrics": [],
"name": "simple_exposure",
"original_file_path": os.path.join("models", "schema.yml"),
"owner": {
Expand Down Expand Up @@ -1185,6 +1187,7 @@ def expected_references_manifest(project):
"fqn": ["test", "notebook_exposure"],
"maturity": "medium",
"meta": {"tool": "my_tool", "languages": ["python"]},
"metrics": [],
"tags": ["my_department"],
"name": "notebook_exposure",
"original_file_path": os.path.join("models", "schema.yml"),
Expand Down
Loading