Skip to content

Commit

Permalink
/* PR_START p--query-resolution-perf 12 */ Add a test for serializing…
Browse files Browse the repository at this point in the history
… a `WhereFilterSpec`.
  • Loading branch information
plypaul committed Jul 17, 2024
1 parent c65a1ea commit 76525dc
Showing 1 changed file with 88 additions and 0 deletions.
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

0 comments on commit 76525dc

Please sign in to comment.