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

Add Defaults for SemanticModel #79

Merged
merged 3 commits into from
May 31, 2023
Merged

Conversation

plypaul
Copy link
Contributor

@plypaul plypaul commented May 30, 2023

resolves # 50

Description

This PR adds a defaults section in the SemanticModel definition that can be used to specify default values for objects listed in the model. e.g.

semantic_model:
  name: accounts_source
  description: accounts_source

  defaults:
    agg_time_dimension: ds

In addition, this removes Dimension.is_primary since it's no longer needed with the introduction of metric_time and defaults.agg_time_dimensions.

Checklist

@cla-bot cla-bot bot added the cla:yes label May 30, 2023
@plypaul plypaul force-pushed the plypaul--10.7--add-model-defaults branch from 5d73a82 to fa21754 Compare May 30, 2023 17:00
@plypaul plypaul marked this pull request as ready for review May 30, 2023 22:59
Copy link
Collaborator

@tlento tlento left a 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."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: done -> one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines -42 to -67
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:
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct.

Base automatically changed from plypaul--10.6--metric-type-simple to main May 31, 2023 00:21
@plypaul plypaul force-pushed the plypaul--10.7--add-model-defaults branch from fa21754 to d4c32e2 Compare May 31, 2023 00:22
@plypaul plypaul merged commit 02a30bb into main May 31, 2023
5 checks passed
@plypaul plypaul deleted the plypaul--10.7--add-model-defaults branch May 31, 2023 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants