-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Update SemanticModel node to match DSI 0.1.0dev3 protocols #7848
Merged
QMalcolm
merged 10 commits into
main
from
ct-2677--ensure-semantic-nodes-match-dsi-protocols
Jun 13, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f2eec1
Add tests to ensure our semantic layer nodes satisfy the DSI protocols
QMalcolm 612a01b
Update the `Dimension` object of `SemanticModel` node to match DSI pr…
QMalcolm cd7099d
Make `UnparsedDimension` more strict and update schema readers accord…
QMalcolm 185e3fc
Update the `Entity` object of `SemanticModel` node to match DSI protocol
QMalcolm 5007e2c
Make `UnparsedEntity` more strict and update schema readers accordingly
QMalcolm 467d993
Update the `Measure` object of `SemanticModel` node to match DSI prot…
QMalcolm 28b6dab
Make `UnparsedMeasure` more strict and update schema readers accordingly
QMalcolm d6809a9
Update the `SemanticModel` node to match DSI protocol
QMalcolm 69ce4a6
Make `UnparsedSemanticModel` more strict and update schema readers ac…
QMalcolm f9ac0e1
Changie entry for updating SemanticModel node
QMalcolm 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Fixes | ||
body: Update SemanticModel node to properly impelment the DSI 0.1.0dev3 SemanticModel | ||
protocol spec | ||
time: 2023-06-12T17:58:54.289704-07:00 | ||
custom: | ||
Author: QMalcolm | ||
Issue: 7833 7827 |
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,152 @@ | ||
from dataclasses import dataclass | ||
from dbt.dataclass_schema import dbtClassMixin | ||
from dbt_semantic_interfaces.references import ( | ||
DimensionReference, | ||
EntityReference, | ||
MeasureReference, | ||
TimeDimensionReference, | ||
) | ||
from dbt_semantic_interfaces.type_enums.aggregation_type import AggregationType | ||
from dbt_semantic_interfaces.type_enums.dimension_type import DimensionType | ||
from dbt_semantic_interfaces.type_enums.entity_type import EntityType | ||
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity | ||
from typing import List, Optional | ||
|
||
|
||
@dataclass | ||
class FileSlice(dbtClassMixin): | ||
"""Provides file slice level context about what something was created from. | ||
|
||
Implementation of the dbt-semantic-interfaces `FileSlice` protocol | ||
""" | ||
|
||
filename: str | ||
content: str | ||
start_line_number: int | ||
end_line_number: int | ||
|
||
|
||
@dataclass | ||
class SourceFileMetadata(dbtClassMixin): | ||
"""Provides file context about what something was created from. | ||
|
||
Implementation of the dbt-semantic-interfaces `Metadata` protocol | ||
""" | ||
|
||
repo_file_path: str | ||
file_slice: FileSlice | ||
|
||
|
||
@dataclass | ||
class Defaults(dbtClassMixin): | ||
agg_time_dimension: Optional[str] = None | ||
|
||
|
||
# ==================================== | ||
# Dimension objects | ||
# ==================================== | ||
|
||
|
||
@dataclass | ||
class DimensionValidityParams(dbtClassMixin): | ||
is_start: bool = False | ||
is_end: bool = False | ||
|
||
|
||
@dataclass | ||
class DimensionTypeParams(dbtClassMixin): | ||
time_granularity: TimeGranularity | ||
validity_params: Optional[DimensionValidityParams] = None | ||
|
||
|
||
@dataclass | ||
class Dimension(dbtClassMixin): | ||
name: str | ||
type: DimensionType | ||
description: Optional[str] = None | ||
is_partition: bool = False | ||
type_params: Optional[DimensionTypeParams] = None | ||
expr: Optional[str] = None | ||
metadata: Optional[SourceFileMetadata] = None | ||
|
||
@property | ||
def reference(self) -> DimensionReference: | ||
return DimensionReference(element_name=self.name) | ||
|
||
@property | ||
def time_dimension_reference(self) -> Optional[TimeDimensionReference]: | ||
if self.type == DimensionType.TIME: | ||
return TimeDimensionReference(element_name=self.name) | ||
else: | ||
return None | ||
|
||
@property | ||
def validity_params(self) -> Optional[DimensionValidityParams]: | ||
if self.type_params: | ||
return self.type_params.validity_params | ||
else: | ||
return None | ||
|
||
|
||
# ==================================== | ||
# Entity objects | ||
# ==================================== | ||
|
||
|
||
@dataclass | ||
class Entity(dbtClassMixin): | ||
name: str | ||
type: EntityType | ||
description: Optional[str] = None | ||
role: Optional[str] = None | ||
expr: Optional[str] = None | ||
|
||
@property | ||
def reference(self) -> EntityReference: | ||
return EntityReference(element_name=self.name) | ||
|
||
@property | ||
def is_linkable_entity_type(self) -> bool: | ||
return self.type in (EntityType.PRIMARY, EntityType.UNIQUE, EntityType.NATURAL) | ||
|
||
|
||
# ==================================== | ||
# Measure objects | ||
# ==================================== | ||
|
||
|
||
@dataclass | ||
class MeasureAggregationParameters(dbtClassMixin): | ||
percentile: Optional[float] = None | ||
use_discrete_percentile: Optional[bool] = None | ||
use_approximate_percentile: Optional[bool] = None | ||
|
||
|
||
@dataclass | ||
class NonAdditiveDimension(dbtClassMixin): | ||
name: str | ||
window_choice: AggregationType | ||
window_grouples: List[str] | ||
|
||
|
||
@dataclass | ||
class Measure(dbtClassMixin): | ||
name: str | ||
agg: AggregationType | ||
description: Optional[str] = None | ||
create_metric: bool = False | ||
expr: Optional[str] = None | ||
agg_params: Optional[MeasureAggregationParameters] = None | ||
non_additive_dimension: Optional[NonAdditiveDimension] = None | ||
agg_time_dimension: Optional[str] = None | ||
|
||
@property | ||
def checked_agg_time_dimension(self) -> TimeDimensionReference: | ||
if self.agg_time_dimension is not None: | ||
return TimeDimensionReference(element_name=self.agg_time_dimension) | ||
else: | ||
raise Exception("Measure is missing agg_time_dimension!") | ||
|
||
@property | ||
def reference(self) -> MeasureReference: | ||
return MeasureReference(element_name=self.name) |
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.
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.
I am very happy about moving the following classes out of nodes.py, but I wonder if we should move them out of the graph subdirectory? I could see arguments either way. We don't need to decide now.
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.
Good point! I mostly moved them to where they are because they were cluttering
nodes.py
and there was some precedent given the spearategraph/metrics.py
file. I'm not sure if there is a right "other" place for them though 🤔 mostly because they are direct dependencies of specific graph nodes and not much else