-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add Defaults for SemanticModel #79
Conversation
5d73a82
to
fa21754
Compare
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.
Love it, this looks a lot cleaner!
@@ -18,7 +18,7 @@ | |||
|
|||
|
|||
class SetMeasureAggregationTimeDimensionRule(ProtocolHint[SemanticManifestTransformRule[PydanticSemanticManifest]]): | |||
"""Sets the aggregation time dimension for measures to the primary time dimension if not defined.""" | |||
"""Sets the aggregation time dimension for measures to the done specified as default.""" |
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.
nit: done
-> one
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.
Updated.
primary_time_dimensions = [] | ||
|
||
for dim in semantic_model.dimensions: | ||
if dim.type == DimensionType.TIME and dim.type_params is not None and dim.type_params.is_primary: | ||
primary_time_dimensions.append(dim) | ||
|
||
# A semantic model must have a primary time dimension if it has | ||
# any measures that don't have an `agg_time_dimension` set | ||
if ( | ||
len(primary_time_dimensions) == 0 | ||
and len(semantic_model.measures) > 0 | ||
and any(measure.agg_time_dimension is None for measure in semantic_model.measures) | ||
): | ||
issues.append( | ||
ValidationError( | ||
context=SemanticModelContext( | ||
file_context=FileContext.from_metadata(metadata=semantic_model.metadata), | ||
semantic_model=SemanticModelReference(semantic_model_name=semantic_model.name), | ||
), | ||
message=f"No primary time dimension in semantic model with name ({semantic_model.name}). " | ||
"Please add one", | ||
) | ||
) | ||
|
||
if len(primary_time_dimensions) > 1: | ||
for primary_time_dimension in primary_time_dimensions: |
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.
Oh this is so much better without all of this stuff....
@@ -124,60 +111,3 @@ def test_incompatible_dimension_is_partition() -> None: # noqa:D | |||
], | |||
) | |||
) | |||
|
|||
|
|||
def test_multiple_primary_time_dimensions() -> None: # noqa:D |
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.
YES!
if ( | ||
dimension.type_params is not None | ||
and not dimension.type_params.is_primary |
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.
Oh huh. This is vestigial from the time before metric_time
, right?
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.
That is correct.
fa21754
to
d4c32e2
Compare
resolves # 50
Description
This PR adds a
defaults
section in theSemanticModel
definition that can be used to specify default values for objects listed in the model. e.g.In addition, this removes
Dimension.is_primary
since it's no longer needed with the introduction ofmetric_time
anddefaults.agg_time_dimensions
.Checklist
changie new
to create a changelog entry