From 3068b69f4825995ebd18c51fe8a8c46a9c37182a Mon Sep 17 00:00:00 2001 From: Devon Fulcher Date: Wed, 20 Sep 2023 11:42:48 -0500 Subject: [PATCH] fixed typing --- .../specs/query_param_implementations.py | 1 + metricflow/test/conftest.py | 3 ++- metricflow/test/query/test_query_parser.py | 22 ++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/metricflow/specs/query_param_implementations.py b/metricflow/specs/query_param_implementations.py index 62c42d6937..b791c46189 100644 --- a/metricflow/specs/query_param_implementations.py +++ b/metricflow/specs/query_param_implementations.py @@ -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 diff --git a/metricflow/test/conftest.py b/metricflow/test/conftest.py index 13318c9f16..d2a60d713c 100644 --- a/metricflow/test/conftest.py +++ b/metricflow/test/conftest.py @@ -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 diff --git a/metricflow/test/query/test_query_parser.py b/metricflow/test/query/test_query_parser.py index f8469d645c..e861369302 100644 --- a/metricflow/test/query/test_query_parser.py +++ b/metricflow/test/query/test_query_parser.py @@ -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 @@ -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 == ( @@ -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)], )