From fe9fa04f43cca6ecb6e9437ddf4cff741fad7976 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 20 Dec 2023 22:11:47 -0800 Subject: [PATCH] Additional fixes. --- metricflow/engine/metricflow_engine.py | 3 ++ .../filter_spec_resolver.py | 46 ++++++++++--------- metricflow/query/query_exceptions.py | 2 +- metricflow/query/query_parser.py | 5 +- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/metricflow/engine/metricflow_engine.py b/metricflow/engine/metricflow_engine.py index 0f13d1cc76..7135f140fd 100644 --- a/metricflow/engine/metricflow_engine.py +++ b/metricflow/engine/metricflow_engine.py @@ -529,6 +529,9 @@ def simple_dimensions_for_metrics( # noqa: D linkable_dimensions_tuple, ) in path_key_to_linkable_dimensions.items(): for linkable_dimension in linkable_dimensions_tuple: + # Simple dimensions shouldn't show date part items. + if linkable_dimension.date_part is not None: + continue semantic_model = self._semantic_manifest_lookup.semantic_model_lookup.get_by_reference( linkable_dimension.semantic_model_origin ) diff --git a/metricflow/query/group_by_item/filter_spec_resolution/filter_spec_resolver.py b/metricflow/query/group_by_item/filter_spec_resolution/filter_spec_resolver.py index e8b24a01d1..7a85fb3c85 100644 --- a/metricflow/query/group_by_item/filter_spec_resolution/filter_spec_resolver.py +++ b/metricflow/query/group_by_item/filter_spec_resolution/filter_spec_resolver.py @@ -1,13 +1,11 @@ from __future__ import annotations +import itertools import logging from typing import List, Sequence from dbt_semantic_interfaces.call_parameter_sets import ( - DimensionCallParameterSet, - EntityCallParameterSet, FilterCallParameterSets, - TimeDimensionCallParameterSet, ) from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilterIntersection from dbt_semantic_interfaces.protocols import WhereFilter, WhereFilterIntersection @@ -97,26 +95,32 @@ def __init__(self, manifest_lookup: SemanticManifestLookup) -> None: # noqa: D def _dedupe_filter_call_parameter_sets( filter_call_parameter_sets_sequence: Sequence[FilterCallParameterSets], ) -> FilterCallParameterSets: - dimension_call_parameter_sets: List[DimensionCallParameterSet] = [] - time_dimension_call_parameter_sets: List[TimeDimensionCallParameterSet] = [] - entity_call_parameter_sets: List[EntityCallParameterSet] = [] - # FilterCallParameterSets needs an update. - for filter_call_parameter_sets in filter_call_parameter_sets_sequence: - for dimension_call_parameter_set in filter_call_parameter_sets.dimension_call_parameter_sets: - if dimension_call_parameter_set not in dimension_call_parameter_sets: - dimension_call_parameter_sets.append(dimension_call_parameter_set) - for time_dimension_call_parameter_set in filter_call_parameter_sets.time_dimension_call_parameter_sets: - if time_dimension_call_parameter_set not in time_dimension_call_parameter_sets: - time_dimension_call_parameter_sets.append(time_dimension_call_parameter_set) - for entity_call_parameter_set in filter_call_parameter_sets.entity_call_parameter_sets: - if entity_call_parameter_set not in entity_call_parameter_sets: - entity_call_parameter_sets.append(entity_call_parameter_set) - return FilterCallParameterSets( - dimension_call_parameter_sets=tuple(dimension_call_parameter_sets), - time_dimension_call_parameter_sets=tuple(time_dimension_call_parameter_sets), - entity_call_parameter_sets=tuple(entity_call_parameter_sets), + dimension_call_parameter_sets=tuple( + dict.fromkeys( + itertools.chain.from_iterable( + filter_call_parameter_sets.dimension_call_parameter_sets + for filter_call_parameter_sets in filter_call_parameter_sets_sequence + ) + ) + ), + time_dimension_call_parameter_sets=tuple( + dict.fromkeys( + itertools.chain.from_iterable( + filter_call_parameter_sets.time_dimension_call_parameter_sets + for filter_call_parameter_sets in filter_call_parameter_sets_sequence + ) + ) + ), + entity_call_parameter_sets=tuple( + dict.fromkeys( + itertools.chain.from_iterable( + filter_call_parameter_sets.entity_call_parameter_sets + for filter_call_parameter_sets in filter_call_parameter_sets_sequence + ) + ) + ), ) @staticmethod diff --git a/metricflow/query/query_exceptions.py b/metricflow/query/query_exceptions.py index 01b5691c8f..fd67e1ad89 100644 --- a/metricflow/query/query_exceptions.py +++ b/metricflow/query/query_exceptions.py @@ -2,6 +2,6 @@ class InvalidQueryException(Exception): - """Exception thrown when there is an error with the parameters to an MQL query.""" + """Exception thrown when there is an error with the parameters to a MF query.""" pass diff --git a/metricflow/query/query_parser.py b/metricflow/query/query_parser.py index b9d8dd1202..8c0de75f06 100644 --- a/metricflow/query/query_parser.py +++ b/metricflow/query/query_parser.py @@ -249,9 +249,10 @@ def _parse_order_by( return tuple(order_by_query_parameter.query_resolver_input for order_by_query_parameter in order_by) @staticmethod - def _error_message( + def generate_error_message( input_to_issue_set: InputToIssueSetMapping, ) -> Optional[str]: + """Create an error message that formats the inputs / issues.""" lines: List[str] = ["Got errors while resolving the query."] issue_counter = 0 @@ -292,7 +293,7 @@ def _raise_exception_if_there_are_errors( if not input_to_issue_set.merged_issue_set.has_errors: return - raise InvalidQueryException(self._error_message(input_to_issue_set=input_to_issue_set)) + raise InvalidQueryException(self.generate_error_message(input_to_issue_set=input_to_issue_set)) def parse_and_validate_query( self,