Skip to content

Commit

Permalink
fixed typing
Browse files Browse the repository at this point in the history
  • Loading branch information
DevonFulcher committed Sep 20, 2023
1 parent 3cc443d commit 3068b69
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions metricflow/specs/query_param_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DimensionQueryParameter:

name: str
grain: Optional[TimeGranularity] = None
descending: bool = False
date_part: Optional[DatePart] = None

def __post_init__(self) -> None: # noqa: D
Expand Down
3 changes: 2 additions & 1 deletion metricflow/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@


@dataclass
class MockQueryParameter:
class MockQueryParameterDimension:
"""This is a mock that is just used to test the query parser."""

name: str
grain: Optional[TimeGranularity] = None
descending: bool = False
date_part: Optional[DatePart] = None
22 changes: 12 additions & 10 deletions metricflow/test/query/test_query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
OrderBySpec,
TimeDimensionSpec,
)
from metricflow.test.conftest import MockQueryParameter
from metricflow.test.conftest import MockQueryParameterDimension
from metricflow.test.fixtures.model_fixtures import query_parser_from_yaml
from metricflow.test.model.example_project_configuration import EXAMPLE_PROJECT_CONFIGURATION_YAML_CONFIG_FILE
from metricflow.test.time.metric_time_dimension import MTD
Expand Down Expand Up @@ -189,11 +189,11 @@ def test_query_parser_with_object_params(bookings_query_parser: MetricFlowQueryP
Metric = namedtuple("Metric", ["name", "descending"])
metric = Metric("bookings", False)
group_by = [
MockQueryParameter("booking__is_instant"),
MockQueryParameter("listing"),
MockQueryParameter(MTD),
MockQueryParameterDimension("booking__is_instant"),
MockQueryParameterDimension("listing"),
MockQueryParameterDimension(MTD),
]
order_by = [MockQueryParameter(MTD), MockQueryParameter("-bookings")]
order_by = [MockQueryParameterDimension(MTD), MockQueryParameterDimension("-bookings")]
query_spec = bookings_query_parser.parse_and_validate_query(metrics=[metric], group_by=group_by, order_by=order_by)
assert query_spec.metric_specs == (MetricSpec(element_name="bookings"),)
assert query_spec.dimension_specs == (
Expand Down Expand Up @@ -414,32 +414,34 @@ def test_date_part_parsing() -> None:
with pytest.raises(RequestTimeGranularityException):
query_parser.parse_and_validate_query(
metric_names=["revenue"],
group_by=[MockQueryParameter(name="metric_time", date_part=DatePart.DOW)],
group_by=[MockQueryParameterDimension(name="metric_time", date_part=DatePart.DOW)],
)

# Can't query date part for cumulative metrics
with pytest.raises(UnableToSatisfyQueryError):
query_parser.parse_and_validate_query(
metric_names=["revenue_cumulative"],
group_by=[MockQueryParameter(name="metric_time", date_part=DatePart.YEAR)],
group_by=[MockQueryParameterDimension(name="metric_time", date_part=DatePart.YEAR)],
)

# Can't query date part for metrics with offset to grain
with pytest.raises(UnableToSatisfyQueryError):
query_parser.parse_and_validate_query(
metric_names=["revenue_since_start_of_year"],
group_by=[MockQueryParameter(name="metric_time", date_part=DatePart.MONTH)],
group_by=[MockQueryParameterDimension(name="metric_time", date_part=DatePart.MONTH)],
)

# Requested granularity doesn't match resolved granularity
with pytest.raises(RequestTimeGranularityException):
query_parser.parse_and_validate_query(
metric_names=["revenue"],
group_by=[MockQueryParameter(name="metric_time", grain=TimeGranularity.YEAR, date_part=DatePart.MONTH)],
group_by=[
MockQueryParameterDimension(name="metric_time", grain=TimeGranularity.YEAR, date_part=DatePart.MONTH)
],
)

# Date part is compatible
query_parser.parse_and_validate_query(
metric_names=["revenue"],
group_by=[MockQueryParameter(name="metric_time", date_part=DatePart.MONTH)],
group_by=[MockQueryParameterDimension(name="metric_time", date_part=DatePart.MONTH)],
)

0 comments on commit 3068b69

Please sign in to comment.