diff --git a/dbt_semantic_interfaces/call_parameter_sets.py b/dbt_semantic_interfaces/call_parameter_sets.py index e9cae4f6..9d827194 100644 --- a/dbt_semantic_interfaces/call_parameter_sets.py +++ b/dbt_semantic_interfaces/call_parameter_sets.py @@ -1,7 +1,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Tuple +from typing import Optional, Tuple from dbt_semantic_interfaces.references import ( DimensionReference, @@ -25,7 +25,7 @@ class TimeDimensionCallParameterSet: entity_path: Tuple[EntityReference, ...] time_dimension_reference: TimeDimensionReference - time_granularity: TimeGranularity + time_granularity: Optional[TimeGranularity] = None @dataclass(frozen=True) diff --git a/dbt_semantic_interfaces/parsing/where_filter/parameter_set_factory.py b/dbt_semantic_interfaces/parsing/where_filter/parameter_set_factory.py index 78561ba0..12a2216f 100644 --- a/dbt_semantic_interfaces/parsing/where_filter/parameter_set_factory.py +++ b/dbt_semantic_interfaces/parsing/where_filter/parameter_set_factory.py @@ -1,4 +1,4 @@ -from typing import Sequence +from typing import Optional, Sequence from dbt_semantic_interfaces.call_parameter_sets import ( DimensionCallParameterSet, @@ -31,7 +31,7 @@ def _exception_message_for_incorrect_format(element_name: str) -> str: @staticmethod def create_time_dimension( - time_dimension_name: str, time_granularity_name: str, entity_path: Sequence[str] = () + time_dimension_name: str, time_granularity_name: Optional[str] = None, entity_path: Sequence[str] = () ) -> TimeDimensionCallParameterSet: """Gets called by Jinja when rendering {{ TimeDimension(...) }}.""" group_by_item_name = DunderedNameFormatter.parse_name(time_dimension_name) @@ -56,7 +56,7 @@ def create_time_dimension( entity_path=( tuple(EntityReference(element_name=arg) for arg in entity_path) + group_by_item_name.entity_links ), - time_granularity=TimeGranularity(time_granularity_name), + time_granularity=TimeGranularity(time_granularity_name) if time_granularity_name is not None else None, ) @staticmethod diff --git a/dbt_semantic_interfaces/parsing/where_filter/where_filter_time_dimension.py b/dbt_semantic_interfaces/parsing/where_filter/where_filter_time_dimension.py index f8022f45..420e286a 100644 --- a/dbt_semantic_interfaces/parsing/where_filter/where_filter_time_dimension.py +++ b/dbt_semantic_interfaces/parsing/where_filter/where_filter_time_dimension.py @@ -41,7 +41,7 @@ def __init__(self) -> None: # noqa def create( self, time_dimension_name: str, - time_granularity_name: str, + time_granularity_name: Optional[str] = None, entity_path: Sequence[str] = (), descending: Optional[bool] = None, date_part_name: Optional[str] = None, diff --git a/tests/implementations/where_filter/test_parse_calls.py b/tests/implementations/where_filter/test_parse_calls.py index f3e069b8..03ba267e 100644 --- a/tests/implementations/where_filter/test_parse_calls.py +++ b/tests/implementations/where_filter/test_parse_calls.py @@ -99,7 +99,7 @@ def test_extract_time_dimension_call_parameter_sets() -> None: # noqa: D def test_extract_metric_time_dimension_call_parameter_sets() -> None: # noqa: D parse_result = PydanticWhereFilter( - where_sql_template=("""{{ TimeDimension('metric_time', 'month') }} = '2020-01-01'""") + where_sql_template="""{{ TimeDimension('metric_time', 'month') }} = '2020-01-01'""" ).call_parameter_sets assert parse_result == FilterCallParameterSets( @@ -215,3 +215,21 @@ def test_where_filter_intersection_error_collection() -> None: ParameterSetFactory._exception_message_for_incorrect_format("customer__has_delivery_address") not in error_string ) + + +def test_time_dimension_without_granularity() -> None: # noqa: D + parse_result = PydanticWhereFilter( + where_sql_template="{{ TimeDimension('booking__created_at') }} > 2023-09-18" + ).call_parameter_sets + + assert parse_result == FilterCallParameterSets( + dimension_call_parameter_sets=(), + time_dimension_call_parameter_sets=( + TimeDimensionCallParameterSet( + entity_path=(EntityReference("booking"),), + time_dimension_reference=TimeDimensionReference(element_name="created_at"), + time_granularity=None, + ), + ), + entity_call_parameter_sets=(), + )