Skip to content

Commit

Permalink
BREAKING: Update PydanticWhereFilter.call_parameter_sets and Pydantic…
Browse files Browse the repository at this point in the history
…WhereFilterIntersection.filter_expression_parameter_sets from property to a method that takes in the valid custom grain names
  • Loading branch information
WilliamDee committed Nov 5, 2024
1 parent 56a8fae commit 3aa70b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 14 additions & 7 deletions dbt_semantic_interfaces/implementations/filters/where_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import textwrap
import traceback
from typing import Callable, Generator, List, Tuple
from typing import Callable, Generator, List, Sequence, Tuple

from typing_extensions import Self

Expand Down Expand Up @@ -49,9 +49,10 @@ def _from_yaml_value(
else:
raise ValueError(f"Expected input to be of type string, but got type {type(input)} with value: {input}")

@property
def call_parameter_sets(self) -> FilterCallParameterSets: # noqa: D
return WhereFilterParser.parse_call_parameter_sets(self.where_sql_template)
def call_parameter_sets(self, custom_granularity_names: Sequence[str]) -> FilterCallParameterSets: # noqa: D
return WhereFilterParser.parse_call_parameter_sets(
where_sql_template=self.where_sql_template, custom_granularity_names=custom_granularity_names
)


class PydanticWhereFilterIntersection(HashableBaseModel):
Expand Down Expand Up @@ -115,14 +116,20 @@ def _convert_legacy_and_yaml_input(cls, input: PydanticParseableValueType) -> Se
f"or dict but got {type(input)} with value {input}"
)

@property
def filter_expression_parameter_sets(self) -> List[Tuple[str, FilterCallParameterSets]]:
def filter_expression_parameter_sets(
self, custom_granularity_names: Sequence[str]
) -> List[Tuple[str, FilterCallParameterSets]]:
"""Gets the call parameter sets for each filter expression."""
filter_parameter_sets: List[Tuple[str, FilterCallParameterSets]] = []
invalid_filter_expressions: List[Tuple[str, Exception]] = []
for where_filter in self.where_filters:
try:
filter_parameter_sets.append((where_filter.where_sql_template, where_filter.call_parameter_sets))
filter_parameter_sets.append(
(
where_filter.where_sql_template,
where_filter.call_parameter_sets(custom_granularity_names=custom_granularity_names),
)
)
except Exception as e:
invalid_filter_expressions.append((where_filter.where_sql_template, e))

Expand Down
6 changes: 2 additions & 4 deletions dbt_semantic_interfaces/protocols/where_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ def where_sql_template(self) -> str:
"""A template that describes how to render the SQL for a WHERE clause."""
pass

@property
@abstractmethod
def call_parameter_sets(self) -> FilterCallParameterSets:
def call_parameter_sets(self, custom_granularity_names: Sequence[str]) -> FilterCallParameterSets:
"""Describe calls like 'dimension(...)' in the SQL template."""
pass

Expand All @@ -35,9 +34,8 @@ class WhereFilterIntersection(Protocol):
logic and partly because it is more descriptive as to the relationship between the filter elements in the set.
"""

@property
@abstractmethod
def where_filters(self) -> Sequence[WhereFilter]:
def where_filters(self, custom_granularity_names: Sequence[str]) -> Sequence[WhereFilter]:
"""The collection of WhereFilters to be applied to the input data set."""
pass

Expand Down

0 comments on commit 3aa70b5

Please sign in to comment.