-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/* PR_START p--query-resolution-perf 12 */ Add a test for serializing…
… a `WhereFilterSpec`.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
metricflow-semantics/tests_metricflow_semantics/specs/test_spec_serialization.py
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,88 @@ | ||
from __future__ import annotations | ||
|
||
from dbt_semantic_interfaces.dataclass_serialization import DataClassDeserializer, DataclassSerializer | ||
from dbt_semantic_interfaces.references import EntityReference, SemanticModelReference | ||
from dbt_semantic_interfaces.type_enums import DatePart, DimensionType, TimeGranularity | ||
from metricflow_semantics.model.linkable_element_property import LinkableElementProperty | ||
from metricflow_semantics.model.semantics.linkable_element import ( | ||
LinkableDimension, | ||
LinkableElementUnion, | ||
SemanticModelJoinPath, | ||
SemanticModelJoinPathElement, | ||
) | ||
from metricflow_semantics.specs.dimension_spec import DimensionSpec | ||
from metricflow_semantics.specs.entity_spec import EntitySpec | ||
from metricflow_semantics.specs.group_by_metric_spec import GroupByMetricSpec | ||
from metricflow_semantics.specs.linkable_spec_set import LinkableSpecSet | ||
from metricflow_semantics.specs.time_dimension_spec import TimeDimensionSpec | ||
from metricflow_semantics.specs.where_filter.where_filter_spec import WhereFilterSpec | ||
from metricflow_semantics.sql.sql_bind_parameters import SqlBindParameter, SqlBindParameters, SqlBindParameterValue | ||
|
||
|
||
def test_where_filter_spec_serialization() -> None: # noqa: D103 | ||
where_filter_spec = WhereFilterSpec( | ||
where_sql="where_sql", | ||
bind_parameters=SqlBindParameters( | ||
param_items=(SqlBindParameter(key="key", value=SqlBindParameterValue(str_value="str_value")),) | ||
), | ||
linkable_element_unions=( | ||
LinkableElementUnion( | ||
linkable_dimension=LinkableDimension( | ||
properties=(LinkableElementProperty.JOINED,), | ||
defined_in_semantic_model=SemanticModelReference(semantic_model_name="semantic_model_name"), | ||
element_name="element_name", | ||
dimension_type=DimensionType.CATEGORICAL, | ||
entity_links=(EntityReference(element_name="element_name"),), | ||
join_path=SemanticModelJoinPath( | ||
left_semantic_model_reference=SemanticModelReference(semantic_model_name="semantic_model_name"), | ||
path_elements=( | ||
SemanticModelJoinPathElement( | ||
semantic_model_reference=SemanticModelReference( | ||
semantic_model_name="semantic_model_name" | ||
), | ||
join_on_entity=EntityReference(element_name="element_name"), | ||
), | ||
), | ||
), | ||
date_part=DatePart.DAY, | ||
time_granularity=TimeGranularity.DAY, | ||
), | ||
), | ||
), | ||
linkable_spec_set=LinkableSpecSet( | ||
dimension_specs=( | ||
DimensionSpec( | ||
element_name="element_name", | ||
entity_links=(EntityReference(element_name="element_name"),), | ||
), | ||
), | ||
time_dimension_specs=( | ||
TimeDimensionSpec( | ||
element_name="element_name", | ||
entity_links=(EntityReference(element_name="element_name"),), | ||
time_granularity=TimeGranularity.YEAR, | ||
), | ||
), | ||
entity_specs=( | ||
EntitySpec( | ||
element_name="element_name", | ||
entity_links=(EntityReference(element_name="element_name"),), | ||
), | ||
), | ||
group_by_metric_specs=( | ||
GroupByMetricSpec( | ||
element_name="element_name", | ||
entity_links=(EntityReference(element_name="element_name"),), | ||
metric_subquery_entity_links=(EntityReference(element_name="element_name"),), | ||
), | ||
), | ||
), | ||
) | ||
|
||
serializer = DataclassSerializer() | ||
deserializer = DataClassDeserializer() | ||
|
||
serialized_spec = serializer.pydantic_serialize(where_filter_spec) | ||
deserialized_spec = deserializer.pydantic_deserialize(WhereFilterSpec, serialized_spec) | ||
|
||
assert where_filter_spec == deserialized_spec |