Skip to content

Commit

Permalink
Additional fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Dec 21, 2023
1 parent 1ef6777 commit fe9fa04
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
3 changes: 3 additions & 0 deletions metricflow/engine/metricflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion metricflow/query/query_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions metricflow/query/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fe9fa04

Please sign in to comment.