diff --git a/dbt_semantic_interfaces/parsing/text_input/description_renderer.py b/dbt_semantic_interfaces/parsing/text_input/description_renderer.py index 404404a9..3cbe7ac4 100644 --- a/dbt_semantic_interfaces/parsing/text_input/description_renderer.py +++ b/dbt_semantic_interfaces/parsing/text_input/description_renderer.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from dbt_semantic_interfaces.parsing.text_input.ti_description import ( - QueryItemDescription, + ObjectBuilderItemDescription, ) @@ -22,6 +22,6 @@ class QueryItemDescriptionRenderer(ABC): """ @abstractmethod - def render_description(self, item_description: QueryItemDescription) -> str: + def render_description(self, item_description: ObjectBuilderItemDescription) -> str: """Return the string that will be substituted for the query item in the Jinja template.""" raise NotImplementedError diff --git a/dbt_semantic_interfaces/parsing/text_input/rendering_helper.py b/dbt_semantic_interfaces/parsing/text_input/rendering_helper.py index d4e5aa8f..ce2e3e01 100644 --- a/dbt_semantic_interfaces/parsing/text_input/rendering_helper.py +++ b/dbt_semantic_interfaces/parsing/text_input/rendering_helper.py @@ -6,8 +6,8 @@ from typing_extensions import override from dbt_semantic_interfaces.parsing.text_input.ti_description import ( + ObjectBuilderItemDescription, ObjectBuilderMethod, - QueryItemDescription, QueryItemType, ) from dbt_semantic_interfaces.parsing.text_input.ti_exceptions import ( @@ -56,7 +56,7 @@ def _create(name: str, entity_path: Sequence[str] = ()) -> _RenderingClassForJin return _RenderingClassForJinjaTemplate( description_processor=description_processor, allowed_methods=allowed_methods, - initial_item_description=QueryItemDescription( + initial_item_description=ObjectBuilderItemDescription( item_type=item_type, item_name=name, entity_path=tuple(entity_path), @@ -85,7 +85,7 @@ def _create( return _RenderingClassForJinjaTemplate( description_processor=description_processor, allowed_methods=allowed_methods, - initial_item_description=QueryItemDescription( + initial_item_description=ObjectBuilderItemDescription( item_type=item_type, item_name=time_dimension_name, entity_path=tuple(entity_path), @@ -108,7 +108,7 @@ def _create(entity_name: str, entity_path: Sequence[str] = ()) -> _RenderingClas return _RenderingClassForJinjaTemplate( description_processor=description_processor, allowed_methods=allowed_methods, - initial_item_description=QueryItemDescription( + initial_item_description=ObjectBuilderItemDescription( item_type=item_type, item_name=entity_name, entity_path=tuple(entity_path), @@ -131,7 +131,7 @@ def _create(metric_name: str, group_by: Sequence[str] = ()) -> _RenderingClassFo return _RenderingClassForJinjaTemplate( description_processor=description_processor, allowed_methods=allowed_methods, - initial_item_description=QueryItemDescription( + initial_item_description=ObjectBuilderItemDescription( item_type=item_type, item_name=metric_name, entity_path=(), @@ -161,7 +161,7 @@ def __init__( self, description_processor: QueryItemDescriptionProcessor, allowed_methods: FrozenSet[ObjectBuilderMethod], - initial_item_description: QueryItemDescription, + initial_item_description: ObjectBuilderItemDescription, ) -> None: """Initializer. @@ -178,7 +178,7 @@ def __init__( def _update_current_description( self, builder_method: ObjectBuilderMethod, - new_description: QueryItemDescription, + new_description: ObjectBuilderItemDescription, ) -> None: if builder_method not in self._allowed_builder_methods: raise InvalidBuilderMethodException( diff --git a/dbt_semantic_interfaces/parsing/text_input/ti_description.py b/dbt_semantic_interfaces/parsing/text_input/ti_description.py index 1a9795ff..6477b4f1 100644 --- a/dbt_semantic_interfaces/parsing/text_input/ti_description.py +++ b/dbt_semantic_interfaces/parsing/text_input/ti_description.py @@ -12,7 +12,7 @@ @dataclass(frozen=True) -class QueryItemDescription: +class ObjectBuilderItemDescription: """Describes a query item specified by the user. For example, the following specified in an order-by of a saved query: @@ -21,7 +21,7 @@ class QueryItemDescription: -> - QueryItemDescription( + ObjectBuilderItemDescription( item_type=GroupByItemType.DIMENSION, item_name="user__created_at", entity_path=['listing'], @@ -101,9 +101,9 @@ def create_modified( time_granularity_name: Optional[str] = None, date_part_name: Optional[str] = None, descending: Optional[bool] = None, - ) -> QueryItemDescription: + ) -> ObjectBuilderItemDescription: """Create one with the same fields as self except the ones provided.""" - return QueryItemDescription( + return ObjectBuilderItemDescription( item_type=self.item_type, item_name=self.item_name, entity_path=self.entity_path, @@ -113,9 +113,9 @@ def create_modified( descending=descending or self.descending, ) - def with_descending_unset(self) -> QueryItemDescription: + def with_descending_unset(self) -> ObjectBuilderItemDescription: """Return this with the `descending` field set to None.""" - return QueryItemDescription( + return ObjectBuilderItemDescription( item_type=self.item_type, item_name=self.item_name, entity_path=self.entity_path, diff --git a/dbt_semantic_interfaces/parsing/text_input/ti_processor.py b/dbt_semantic_interfaces/parsing/text_input/ti_processor.py index f0ad2e8d..74e6bcb9 100644 --- a/dbt_semantic_interfaces/parsing/text_input/ti_processor.py +++ b/dbt_semantic_interfaces/parsing/text_input/ti_processor.py @@ -17,7 +17,7 @@ ObjectBuilderJinjaRenderHelper, ) from dbt_semantic_interfaces.parsing.text_input.ti_description import ( - QueryItemDescription, + ObjectBuilderItemDescription, ) from dbt_semantic_interfaces.parsing.text_input.ti_exceptions import ( QueryItemJinjaException, @@ -25,16 +25,21 @@ from dbt_semantic_interfaces.parsing.text_input.valid_method import ValidMethodMapping -class QueryItemTextProcessor: +class ObjectBuilderTextProcessor: """Performs processing actions for text containing query items specified in the object-builder syntax. This currently supports: - * Collecting `QueryItemDescription`s from a Jinja template. + * Collecting `ObjectBuilderItemDescription`s from a Jinja template. * Rendering a Jinja template using a specified renderer. """ - def get_description(self, query_item_input: str, valid_method_mapping: ValidMethodMapping) -> QueryItemDescription: - """Get the `QueryItemDescription` for a single item e.g. `Dimension('listing__country').descending(True)`.""" + def get_description( + self, query_item_input: str, valid_method_mapping: ValidMethodMapping + ) -> ObjectBuilderItemDescription: + """Get the `ObjectBuilderItemDescription` for a single item. + + e.g. `Dimension('listing__country').descending(True)`. + """ descriptions = self.collect_descriptions_from_template( jinja_template="{{ " + query_item_input + " }}", valid_method_mapping=valid_method_mapping, @@ -49,8 +54,8 @@ def collect_descriptions_from_template( self, jinja_template: str, valid_method_mapping: ValidMethodMapping, - ) -> Sequence[QueryItemDescription]: - """Returns the `QueryItemDescription`s that are found in a Jinja template. + ) -> Sequence[ObjectBuilderItemDescription]: + """Returns the `ObjectBuilderItemDescription`s that are found in a Jinja template. Args: jinja_template: A Jinja-template string like `{{ Dimension('listing__country') }} = 'US'`. @@ -135,7 +140,7 @@ class QueryItemDescriptionProcessor(ABC): """General processor that does something to a query-item description seen in a Jinja template.""" @abstractmethod - def process_description(self, item_description: QueryItemDescription) -> str: + def process_description(self, item_description: ObjectBuilderItemDescription) -> str: """Process the given description, and return a string that would be substituted into the Jinja template.""" raise NotImplementedError @@ -144,14 +149,14 @@ class _CollectDescriptionProcessor(QueryItemDescriptionProcessor): """Processor that collects all descriptions that were processed.""" def __init__(self) -> None: # noqa: D107 - self._items: List[QueryItemDescription] = [] + self._items: List[ObjectBuilderItemDescription] = [] - def collected_descriptions(self) -> Sequence[QueryItemDescription]: + def collected_descriptions(self) -> Sequence[ObjectBuilderItemDescription]: """Return all descriptions that were processed so far.""" return self._items @override - def process_description(self, item_description: QueryItemDescription) -> str: + def process_description(self, item_description: ObjectBuilderItemDescription) -> str: if item_description not in self._items: self._items.append(item_description) @@ -169,5 +174,5 @@ def __init__(self, renderer: QueryItemDescriptionRenderer) -> None: # noqa: D10 self._renderer = renderer @override - def process_description(self, item_description: QueryItemDescription) -> str: + def process_description(self, item_description: ObjectBuilderItemDescription) -> str: return self._renderer.render_description(item_description) diff --git a/dbt_semantic_interfaces/parsing/where_filter/where_filter_parser.py b/dbt_semantic_interfaces/parsing/where_filter/where_filter_parser.py index 761d07e2..7d070b84 100644 --- a/dbt_semantic_interfaces/parsing/where_filter/where_filter_parser.py +++ b/dbt_semantic_interfaces/parsing/where_filter/where_filter_parser.py @@ -8,11 +8,11 @@ ) from dbt_semantic_interfaces.enum_extension import assert_values_exhausted from dbt_semantic_interfaces.parsing.text_input.ti_description import ( - QueryItemDescription, + ObjectBuilderItemDescription, QueryItemType, ) from dbt_semantic_interfaces.parsing.text_input.ti_processor import ( - QueryItemTextProcessor, + ObjectBuilderTextProcessor, ) from dbt_semantic_interfaces.parsing.text_input.valid_method import ( ConfiguredValidMethodMapping, @@ -26,9 +26,9 @@ class WhereFilterParser: """Parses the template in the WhereFilter into FilterCallParameterSets.""" @staticmethod - def parse_item_descriptions(where_sql_template: str) -> Sequence[QueryItemDescription]: + def parse_item_descriptions(where_sql_template: str) -> Sequence[ObjectBuilderItemDescription]: """Parses the filter and returns the item descriptions.""" - text_processor = QueryItemTextProcessor() + text_processor = ObjectBuilderTextProcessor() try: return text_processor.collect_descriptions_from_template( diff --git a/dbt_semantic_interfaces/validations/saved_query.py b/dbt_semantic_interfaces/validations/saved_query.py index bc978341..7d3716bb 100644 --- a/dbt_semantic_interfaces/validations/saved_query.py +++ b/dbt_semantic_interfaces/validations/saved_query.py @@ -8,11 +8,11 @@ from dbt_semantic_interfaces.call_parameter_sets import FilterCallParameterSets from dbt_semantic_interfaces.naming.keywords import METRIC_TIME_ELEMENT_NAME from dbt_semantic_interfaces.parsing.text_input.ti_description import ( - QueryItemDescription, + ObjectBuilderItemDescription, QueryItemType, ) from dbt_semantic_interfaces.parsing.text_input.ti_processor import ( - QueryItemTextProcessor, + ObjectBuilderTextProcessor, ) from dbt_semantic_interfaces.parsing.text_input.valid_method import ( ConfiguredValidMethodMapping, @@ -142,7 +142,7 @@ def _check_where(saved_query: SavedQuery) -> Sequence[ValidationIssue]: @staticmethod def _parse_query_item( saved_query: SavedQuery, - text_processor: QueryItemTextProcessor, + text_processor: ObjectBuilderTextProcessor, query_item_input: str, element_type: SavedQueryElementType, valid_method_mapping: ValidMethodMapping, @@ -184,7 +184,7 @@ def _check_order_by(saved_query: SavedQuery) -> Sequence[ValidationIssue]: return validation_issues valid_query_item_descriptions = set() - text_processor = QueryItemTextProcessor() + text_processor = ObjectBuilderTextProcessor() for metric in saved_query.query_params.metrics: # In an order-by, a metric is specified as "Metric('bookings')" while in the metrics section, it's only the # metric name. @@ -299,7 +299,7 @@ def validate_manifest(semantic_manifest: SemanticManifestT) -> Sequence[Validati class _ParseQueryItemResult: """Result of parsing a string like `Dimension('listing__country')`.""" - item_description: Optional[QueryItemDescription] + item_description: Optional[ObjectBuilderItemDescription] validation_issue: Optional[ValidationIssue] def __post_init__(self) -> None: