diff --git a/metricflow-semantics/metricflow_semantics/query/query_parser.py b/metricflow-semantics/metricflow_semantics/query/query_parser.py index 59994594c1..72b6f654da 100644 --- a/metricflow-semantics/metricflow_semantics/query/query_parser.py +++ b/metricflow-semantics/metricflow_semantics/query/query_parser.py @@ -321,7 +321,7 @@ def parse_and_validate_query( order_by_names: Optional[Sequence[str]] = None, order_by: Optional[Sequence[OrderByQueryParameter]] = None, min_max_only: bool = False, - ) -> MetricFlowQuerySpec: + ) -> ParseQueryResult: """Parse the query into spec objects, validating them in the process. e.g. make sure that the given metric is a valid metric name. @@ -341,7 +341,7 @@ def parse_and_validate_query( order_by_names=order_by_names, order_by=order_by, min_max_only=min_max_only, - ).query_spec + ) @log_runtime() def _parse_and_validate_query( @@ -533,7 +533,7 @@ def build_query_spec_for_group_by_metric_source_node( return self.parse_and_validate_query( metrics=(MetricParameter(group_by_metric_spec.reference.element_name),), group_by=(DimensionOrEntityParameter(group_by_metric_spec.metric_subquery_entity_spec.qualified_name),), - ) + ).query_spec @dataclass(frozen=True) diff --git a/metricflow-semantics/tests_metricflow_semantics/query/test_ambiguous_entity_path.py b/metricflow-semantics/tests_metricflow_semantics/query/test_ambiguous_entity_path.py index d27786ce27..db892c4d99 100644 --- a/metricflow-semantics/tests_metricflow_semantics/query/test_ambiguous_entity_path.py +++ b/metricflow-semantics/tests_metricflow_semantics/query/test_ambiguous_entity_path.py @@ -28,7 +28,7 @@ def test_resolvable_ambiguous_entity_path( # noqa: D103 query_spec = multi_hop_query_parser.parse_and_validate_query( metric_names=["entity_1_metric"], group_by_names=["entity_0__country"], - ) + ).query_spec assert_object_snapshot_equal( request=request, @@ -47,7 +47,7 @@ def test_ambiguous_entity_path_resolves_to_shortest_entity_path_item( query_spec = multi_hop_query_parser.parse_and_validate_query( metric_names=["all_entity_metric"], group_by_names=["entity_1__country"], - ) + ).query_spec assert_object_snapshot_equal( request=request, @@ -70,7 +70,7 @@ def test_non_resolvable_ambiguous_entity_path_due_to_multiple_matches( multi_hop_query_parser.parse_and_validate_query( metric_names=["entity_1_and_entity_2_metric"], group_by_names=["entity_0__country"], - ) + ).query_spec assert_str_snapshot_equal( request=request, @@ -93,7 +93,7 @@ def test_non_resolvable_ambiguous_entity_path_due_to_mismatch( multi_hop_query_parser.parse_and_validate_query( metric_names=["entity_0_metric", "entity_1_metric"], group_by_names=["entity_0__country"], - ) + ).query_spec assert_str_snapshot_equal( request=request, diff --git a/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py b/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py index d5f82d4927..9e563aff17 100644 --- a/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py +++ b/metricflow-semantics/tests_metricflow_semantics/query/test_query_parser.py @@ -200,7 +200,7 @@ def test_query_parser(bookings_query_parser: MetricFlowQueryParser) -> None: # metric_names=["bookings"], group_by_names=["booking__is_instant", "listing", MTD], order_by_names=[MTD, "-bookings"], - ) + ).query_spec assert query_spec.metric_specs == (MetricSpec(element_name="bookings"),) assert query_spec.dimension_specs == ( @@ -228,7 +228,7 @@ def test_query_parser_case_insensitivity(bookings_query_parser: MetricFlowQueryP metric_names=["BOOKINGS"], group_by_names=["BOOKING__IS_INSTANT", "LISTING", MTD.upper()], order_by_names=[MTD.upper(), "-BOOKINGS"], - ) + ).query_spec assert query_spec.metric_specs == (MetricSpec(element_name="bookings"),) assert query_spec.dimension_specs == ( @@ -260,7 +260,9 @@ def test_query_parser_case_insensitivity(bookings_query_parser: MetricFlowQueryP OrderByParameter(order_by=TimeDimensionParameter(MTD.upper())), OrderByParameter(order_by=MetricParameter("BOOKINGS"), descending=True), ) - query_spec = bookings_query_parser.parse_and_validate_query(metrics=[metric], group_by=group_by, order_by=order_by) + query_spec = bookings_query_parser.parse_and_validate_query( + metrics=[metric], group_by=group_by, order_by=order_by + ).query_spec assert query_spec.metric_specs == (MetricSpec(element_name="bookings"),) assert query_spec.dimension_specs == ( DimensionSpec(element_name="is_instant", entity_links=(EntityReference("booking"),)), @@ -283,7 +285,7 @@ def test_query_parser_case_insensitivity(bookings_query_parser: MetricFlowQueryP def test_query_parser_invalid_group_by(bookings_query_parser: MetricFlowQueryParser) -> None: # noqa: D103 with pytest.raises(InvalidQueryException): - bookings_query_parser.parse_and_validate_query(group_by_names=["random_stuff"]) + bookings_query_parser.parse_and_validate_query(group_by_names=["random_stuff"]).query_spec def test_query_parser_with_object_params(bookings_query_parser: MetricFlowQueryParser) -> None: # noqa: D103 @@ -297,7 +299,9 @@ def test_query_parser_with_object_params(bookings_query_parser: MetricFlowQueryP OrderByParameter(order_by=TimeDimensionParameter(MTD)), OrderByParameter(order_by=MetricParameter("bookings"), descending=True), ) - query_spec = bookings_query_parser.parse_and_validate_query(metrics=[metric], group_by=group_by, order_by=order_by) + query_spec = bookings_query_parser.parse_and_validate_query( + metrics=[metric], group_by=group_by, order_by=order_by + ).query_spec assert query_spec.metric_specs == (MetricSpec(element_name="bookings"),) assert query_spec.dimension_specs == ( DimensionSpec(element_name="is_instant", entity_links=(EntityReference("booking"),)), @@ -333,7 +337,7 @@ def test_order_by_granularity_conversion() -> None: ) query_spec = query_parser.parse_and_validate_query( metric_names=["bookings", "revenue"], group_by_names=[MTD], order_by_names=[f"-{MTD}"] - ) + ).query_spec # The lowest common granularity is MONTH, so we expect the PTD in the order by to have that granularity. assert ( @@ -347,7 +351,7 @@ def test_order_by_granularity_conversion() -> None: def test_order_by_granularity_no_conversion(bookings_query_parser: MetricFlowQueryParser) -> None: # noqa: D103 query_spec = bookings_query_parser.parse_and_validate_query( metric_names=["bookings"], group_by_names=[MTD], order_by_names=[MTD] - ) + ).query_spec # The only granularity is DAY, so we expect the PTD in the order by to have that granularity. assert ( @@ -373,7 +377,7 @@ def test_time_range_constraint_conversion() -> None: group_by_names=[MTD], time_constraint_start=as_datetime("2020-01-15"), time_constraint_end=as_datetime("2020-02-15"), - ) + ).query_spec assert ( TimeRangeConstraint(start_time=as_datetime("2020-01-01"), end_time=as_datetime("2020-02-29")) @@ -390,7 +394,7 @@ def test_parse_and_validate_where_constraint_dims(bookings_query_parser: MetricF time_constraint_start=as_datetime("2020-01-15"), time_constraint_end=as_datetime("2020-02-15"), where_constraint_str="{{ Dimension('booking__invalid_dim') }} = '1'", - ) + ).query_spec with pytest.raises(InvalidQueryException, match="Error parsing where filter"): bookings_query_parser.parse_and_validate_query( @@ -399,7 +403,7 @@ def test_parse_and_validate_where_constraint_dims(bookings_query_parser: MetricF time_constraint_start=as_datetime("2020-01-15"), time_constraint_end=as_datetime("2020-02-15"), where_constraint_str="{{ Dimension('invalid_format') }} = '1'", - ) + ).query_spec query_spec = bookings_query_parser.parse_and_validate_query( metric_names=["bookings"], @@ -407,7 +411,7 @@ def test_parse_and_validate_where_constraint_dims(bookings_query_parser: MetricF time_constraint_start=as_datetime("2020-01-15"), time_constraint_end=as_datetime("2020-02-15"), where_constraint_str="{{ Dimension('booking__is_instant') }} = '1'", - ) + ).query_spec assert ( DimensionSpec(element_name="is_instant", entity_links=(EntityReference("booking"),)) not in query_spec.dimension_specs @@ -424,7 +428,7 @@ def test_parse_and_validate_where_constraint_metric_time() -> None: metric_names=["revenue"], group_by_names=[MTD], where_constraint_str="{{ TimeDimension('metric_time', 'day') }} > '2020-01-15'", - ) + ).query_spec def test_parse_and_validate_metric_constraint_dims() -> None: @@ -442,7 +446,7 @@ def test_parse_and_validate_metric_constraint_dims() -> None: group_by_names=[MTD], time_constraint_start=as_datetime("2020-01-15"), time_constraint_end=as_datetime("2020-02-15"), - ) + ).query_spec def test_cumulative_metric_no_time_dimension_validation() -> None: @@ -461,7 +465,7 @@ def test_cumulative_metric_no_time_dimension_validation() -> None: with pytest.raises(InvalidQueryException, match="do not include 'metric_time'"): query_parser.parse_and_validate_query( metric_names=["revenue_cumulative"], - ) + ).query_spec def test_cumulative_metric_wrong_time_dimension_validation() -> None: @@ -486,7 +490,7 @@ def test_cumulative_metric_wrong_time_dimension_validation() -> None: query_parser.parse_and_validate_query( metric_names=["revenue_cumulative"], group_by_names=["revenue_instance__loaded_at"], - ) + ).query_spec def test_cumulative_metric_agg_time_dimension_name_validation() -> None: @@ -498,7 +502,9 @@ def test_cumulative_metric_agg_time_dimension_name_validation() -> None: [EXAMPLE_PROJECT_CONFIGURATION_YAML_CONFIG_FILE, bookings_yaml_file, revenue_yaml_file, metrics_yaml_file] ) - query_parser.parse_and_validate_query(metric_names=["revenue_cumulative"], group_by_names=["revenue_instance__ds"]) + query_parser.parse_and_validate_query( + metric_names=["revenue_cumulative"], group_by_names=["revenue_instance__ds"] + ).query_spec def test_derived_metric_query_parsing() -> None: @@ -514,20 +520,20 @@ def test_derived_metric_query_parsing() -> None: query_parser.parse_and_validate_query( metric_names=["revenue_sub_10"], group_by_names=[], - ) + ).query_spec # Attempt to query with non-time dimension with pytest.raises(InvalidQueryException, match="does not match any of the available"): query_parser.parse_and_validate_query( metric_names=["revenue_sub_10"], group_by_names=["country"], - ) + ).query_spec # Query with time dimension query_parser.parse_and_validate_query( metric_names=["revenue_sub_10"], group_by_names=[MTD], - ) + ).query_spec def test_derived_metric_with_offset_parsing() -> None: @@ -542,20 +548,20 @@ def test_derived_metric_with_offset_parsing() -> None: query_parser.parse_and_validate_query( metric_names=["revenue_growth_2_weeks"], group_by_names=[], - ) + ).query_spec # Attempt to query with non-time dimension with pytest.raises(InvalidQueryException, match="do not include 'metric_time'"): query_parser.parse_and_validate_query( metric_names=["revenue_growth_2_weeks"], group_by_names=["revenue_instance__country"], - ) + ).query_spec # Query with time dimension query_parser.parse_and_validate_query( metric_names=["revenue_growth_2_weeks"], group_by_names=[MTD], - ) + ).query_spec def test_date_part_parsing() -> None: @@ -571,21 +577,21 @@ def test_date_part_parsing() -> None: query_parser.parse_and_validate_query( metric_names=["revenue"], group_by=(TimeDimensionParameter(name="metric_time", date_part=DatePart.DOW),), - ) + ).query_spec # Can't query date part for cumulative metrics with pytest.raises(InvalidQueryException, match="does not match any of the available"): query_parser.parse_and_validate_query( metric_names=["revenue_cumulative"], group_by=(TimeDimensionParameter(name="metric_time", date_part=DatePart.YEAR),), - ) + ).query_spec # Can't query date part for metrics with offset to grain with pytest.raises(InvalidQueryException, match="does not allow group-by-items with a date part in the query"): query_parser.parse_and_validate_query( metric_names=["revenue_since_start_of_year"], group_by=(TimeDimensionParameter(name="metric_time", date_part=DatePart.MONTH),), - ) + ).query_spec # Requested granularity doesn't match resolved granularity with pytest.raises(InvalidQueryException, match="does not match any of the available"): @@ -594,13 +600,13 @@ def test_date_part_parsing() -> None: group_by=( TimeDimensionParameter(name="metric_time", grain=TimeGranularity.YEAR, date_part=DatePart.MONTH), ), - ) + ).query_spec # Date part is compatible query_parser.parse_and_validate_query( metric_names=["revenue"], group_by=(TimeDimensionParameter(name="metric_time", date_part=DatePart.MONTH),), - ) + ).query_spec def test_duplicate_metric_query(bookings_query_parser: MetricFlowQueryParser) -> None: # noqa: D103 @@ -608,12 +614,12 @@ def test_duplicate_metric_query(bookings_query_parser: MetricFlowQueryParser) -> bookings_query_parser.parse_and_validate_query( metric_names=["bookings", "bookings"], group_by_names=[MTD], - ) + ).query_spec def test_no_metrics_or_group_by(bookings_query_parser: MetricFlowQueryParser) -> None: # noqa: D103 with pytest.raises(InvalidQueryException, match="no metrics or group by items"): - bookings_query_parser.parse_and_validate_query() + bookings_query_parser.parse_and_validate_query().query_spec def test_offset_metric_with_diff_agg_time_dims_error() -> None: # noqa: D103 @@ -626,7 +632,7 @@ def test_offset_metric_with_diff_agg_time_dims_error() -> None: # noqa: D103 query_parser.parse_and_validate_query( metric_names=["monthly_revenue_last_7_days"], group_by_names=["revenue___ds"], - ) + ).query_spec def query_parser_from_yaml(yaml_contents: List[YamlConfigFile]) -> MetricFlowQueryParser: diff --git a/metricflow-semantics/tests_metricflow_semantics/query/test_suggestions.py b/metricflow-semantics/tests_metricflow_semantics/query/test_suggestions.py index 8ab94aa9c5..f3251383f3 100644 --- a/metricflow-semantics/tests_metricflow_semantics/query/test_suggestions.py +++ b/metricflow-semantics/tests_metricflow_semantics/query/test_suggestions.py @@ -32,7 +32,9 @@ def test_suggestions_for_group_by_item( # noqa: D103 request: FixtureRequest, mf_test_configuration: MetricFlowTestConfiguration, query_parser: MetricFlowQueryParser ) -> None: with pytest.raises(InvalidQueryException) as e: - query_parser.parse_and_validate_query(metric_names=("bookings",), group_by_names=("booking__instant",)) + query_parser.parse_and_validate_query( + metric_names=("bookings",), group_by_names=("booking__instant",) + ).query_spec assert_str_snapshot_equal( request=request, @@ -46,7 +48,9 @@ def test_suggestions_for_metric( # noqa: D103 request: FixtureRequest, mf_test_configuration: MetricFlowTestConfiguration, query_parser: MetricFlowQueryParser ) -> None: with pytest.raises(InvalidQueryException) as e: - query_parser.parse_and_validate_query(metric_names=("booking",), group_by_names=(METRIC_TIME_ELEMENT_NAME,)) + query_parser.parse_and_validate_query( + metric_names=("booking",), group_by_names=(METRIC_TIME_ELEMENT_NAME,) + ).query_spec assert_str_snapshot_equal( request=request, @@ -60,7 +64,9 @@ def test_suggestions_for_multiple_metrics( # noqa: D103 request: FixtureRequest, mf_test_configuration: MetricFlowTestConfiguration, query_parser: MetricFlowQueryParser ) -> None: with pytest.raises(InvalidQueryException) as e: - query_parser.parse_and_validate_query(metric_names=("bookings", "listings"), group_by_names=("booking__ds",)) + query_parser.parse_and_validate_query( + metric_names=("bookings", "listings"), group_by_names=("booking__ds",) + ).query_spec assert_str_snapshot_equal( request=request, @@ -93,7 +99,9 @@ def test_suggestions_for_defined_where_filter( # noqa: D103 semantic_manifest_lookup=semantic_manifest_lookup, ) with pytest.raises(InvalidQueryException) as e: - query_parser.parse_and_validate_query(metric_names=("listings",), group_by_names=(METRIC_TIME_ELEMENT_NAME,)) + query_parser.parse_and_validate_query( + metric_names=("listings",), group_by_names=(METRIC_TIME_ELEMENT_NAME,) + ).query_spec assert_str_snapshot_equal( request=request, @@ -145,7 +153,7 @@ def test_suggestions_for_defined_filters_in_multi_metric_query( "listings", ), group_by_names=(METRIC_TIME_ELEMENT_NAME,), - ) + ).query_spec assert_str_snapshot_equal( request=request, diff --git a/metricflow/engine/metricflow_engine.py b/metricflow/engine/metricflow_engine.py index 07441eb64b..79a6aea9cd 100644 --- a/metricflow/engine/metricflow_engine.py +++ b/metricflow/engine/metricflow_engine.py @@ -485,7 +485,7 @@ def _create_execution_plan(self, mf_query_request: MetricFlowQueryRequest) -> Me order_by_names=mf_query_request.order_by_names, order_by=mf_query_request.order_by, min_max_only=mf_query_request.min_max_only, - ) + ).query_spec logger.info(f"Query spec is:\n{mf_pformat(query_spec)}") output_selection_specs: Optional[InstanceSpecSet] = None diff --git a/scripts/ci_tests/metricflow_semantics_package_test.py b/scripts/ci_tests/metricflow_semantics_package_test.py index f2499bfb95..8cb603952f 100644 --- a/scripts/ci_tests/metricflow_semantics_package_test.py +++ b/scripts/ci_tests/metricflow_semantics_package_test.py @@ -80,7 +80,7 @@ def log_query_spec() -> None: # noqa: D103 query_parser = MetricFlowQueryParser(SemanticManifestLookup(semantic_manifest)) query_spec = query_parser.parse_and_validate_query( metric_names=["bookings"], group_by_names=["booking__is_instant"] - ) + ).query_spec logger.info(f"{query_spec.__class__.__name__}:\n{mf_pformat(query_spec)}") diff --git a/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py b/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py index d0c03da8be..fd179912e6 100644 --- a/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py +++ b/tests_metricflow/dataflow/builder/test_dataflow_plan_builder.py @@ -361,7 +361,7 @@ def test_where_constrained_plan( metric_names=("bookings",), group_by_names=("booking__is_instant",), where_constraint_str="{{ Dimension('listing__country_latest') }} = 'us'", - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -390,7 +390,7 @@ def test_where_constrained_plan_time_dimension( metric_names=("bookings",), group_by_names=("booking__is_instant",), where_constraint_str="{{ TimeDimension('metric_time', 'day') }} >= '2020-01-01'", - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -420,7 +420,7 @@ def test_where_constrained_with_common_linkable_plan( metric_names=("bookings",), group_by_names=("listing__country_latest",), where_constraint_str="{{ Dimension('listing__country_latest') }} = 'us'", - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -559,7 +559,7 @@ def test_distinct_values_plan( where_constraint_str="{{ Dimension('listing__country_latest') }} = 'us'", order_by_names=("-listing__country_latest",), limit=100, - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values(query_spec) assert_plan_snapshot_text_equal( @@ -589,7 +589,7 @@ def test_distinct_values_plan_with_join( where_constraint_str="{{ Dimension('listing__country_latest') }} = 'us'", order_by_names=("-listing__is_lux_latest",), limit=100, - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values(query_spec) assert_plan_snapshot_text_equal( @@ -617,7 +617,7 @@ def test_measure_constraint_plan( query_spec = query_parser.parse_and_validate_query( metric_names=("lux_booking_value_rate_expr",), group_by_names=(METRIC_TIME_ELEMENT_NAME,), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -645,7 +645,7 @@ def test_measure_constraint_with_reused_measure_plan( query_spec = query_parser.parse_and_validate_query( metric_names=("instant_booking_value_ratio",), group_by_names=(METRIC_TIME_ELEMENT_NAME,), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -1197,7 +1197,7 @@ def test_join_to_time_spine_with_filters( ), time_constraint_start=datetime.datetime(2020, 1, 3), time_constraint_end=datetime.datetime(2020, 1, 5), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -1228,7 +1228,7 @@ def test_offset_window_metric_filter_and_query_have_different_granularities( where_constraint=PydanticWhereFilter( where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -1259,7 +1259,7 @@ def test_offset_to_grain_metric_filter_and_query_have_different_granularities( where_constraint=PydanticWhereFilter( where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -1286,7 +1286,7 @@ def test_metric_in_query_where_filter( """Test querying a metric that has a metric in its where filter.""" query_spec = query_parser.parse_and_validate_query( metric_names=("listings",), where_constraint_str="{{ Metric('bookings', ['listing'])}} > 2" - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -1313,7 +1313,7 @@ def test_metric_in_metric_where_filter( """Test querying a metric that has a metric in its where filter.""" query_spec = query_parser.parse_and_validate_query( metric_names=("active_listings",), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) assert_plan_snapshot_text_equal( @@ -1348,5 +1348,5 @@ def test_all_available_metric_filters( metric_name=linkable_metric.element_name, entity_name=entity_spec.qualified_name ), ), - ) + ).query_spec dataflow_plan_builder.build_plan(query_spec) diff --git a/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py b/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py index 0a6789cb41..859cb4fd64 100644 --- a/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py +++ b/tests_metricflow/dataflow/optimizer/source_scan/test_source_scan_optimizer.py @@ -242,7 +242,7 @@ def test_constrained_metric_not_combined( query_spec = query_parser.parse_and_validate_query( metric_names=("booking_value", "instant_booking_value"), group_by_names=(METRIC_TIME_ELEMENT_NAME,), - ) + ).query_spec check_optimization( request=request, mf_test_configuration=mf_test_configuration, diff --git a/tests_metricflow/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py b/tests_metricflow/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py index f0fcf7b7ea..1da3d464aa 100644 --- a/tests_metricflow/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py +++ b/tests_metricflow/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py @@ -58,7 +58,7 @@ def test_dimension_values_with_a_join_and_a_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Dimension('user__home_state_latest') }} = 'us'", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values(query_spec) convert_and_check( diff --git a/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py b/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py index 63fe16d27d..e0c75aa5bd 100644 --- a/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py +++ b/tests_metricflow/plan_conversion/test_dataflow_to_sql_plan.py @@ -1205,7 +1205,7 @@ def test_dimension_with_joined_where_constraint( query_spec = query_parser.parse_and_validate_query( group_by_names=("user__home_state_latest",), where_constraint_str="{{ Dimension('listing__country_latest') }} = 'us'", - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values(query_spec) convert_and_check( diff --git a/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py b/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py index f13355485d..e44a0f878d 100644 --- a/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py +++ b/tests_metricflow/query_rendering/test_cumulative_metric_rendering.py @@ -125,7 +125,7 @@ def test_cumulative_metric_with_non_adjustable_time_filter( "or {{ TimeDimension('metric_time', 'day') }} = '2020-01-07'" ) ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( diff --git a/tests_metricflow/query_rendering/test_derived_metric_rendering.py b/tests_metricflow/query_rendering/test_derived_metric_rendering.py index 284e39f999..65939fa56f 100644 --- a/tests_metricflow/query_rendering/test_derived_metric_rendering.py +++ b/tests_metricflow/query_rendering/test_derived_metric_rendering.py @@ -122,7 +122,7 @@ def test_derived_metric_with_offset_window_and_time_filter( # noqa: D103 "or {{ TimeDimension('metric_time', 'day') }} = '2020-01-14'" ) ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -396,7 +396,7 @@ def test_nested_offsets_with_where_constraint( # noqa: D103 "or {{ TimeDimension('metric_time', 'day') }} = '2020-01-13'" ) ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -474,7 +474,7 @@ def test_nested_filters( create_source_tables: bool, ) -> None: """Tests derived metric rendering for a nested derived metric with filters on the outer metric spec.""" - query_spec = query_parser.parse_and_validate_query(metric_names=("instant_lux_booking_value_rate",)) + query_spec = query_parser.parse_and_validate_query(metric_names=("instant_lux_booking_value_rate",)).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec=query_spec) convert_and_check( @@ -532,7 +532,7 @@ def test_nested_derived_metric_offset_with_joined_where_constraint_not_selected( metric_names=("bookings_offset_twice",), group_by_names=(group_by_name,), where_constraint_str="{{ Dimension('booking__is_instant') }}", - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -558,7 +558,7 @@ def test_offset_window_with_agg_time_dim( # noqa: D103 query_spec = query_parser.parse_and_validate_query( metric_names=("bookings_growth_2_weeks",), group_by_names=("booking__ds__day",), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -584,7 +584,7 @@ def test_offset_to_grain_with_agg_time_dim( # noqa: D103 query_spec = query_parser.parse_and_validate_query( metric_names=("bookings_growth_since_start_of_month",), group_by_names=("booking__ds__day",), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -610,7 +610,7 @@ def test_derived_offset_metric_with_agg_time_dim( # noqa: D103 query_spec = query_parser.parse_and_validate_query( metric_names=("booking_fees_last_week_per_booker_this_week",), group_by_names=("booking__ds__day",), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -717,7 +717,7 @@ def test_offset_window_metric_multiple_granularities( query_spec = query_parser.parse_and_validate_query( metric_names=("booking_fees_last_week_per_booker_this_week",), group_by_names=("metric_time__day", "metric_time__month", "metric_time__year"), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -743,7 +743,7 @@ def test_offset_to_grain_metric_multiple_granularities( query_spec = query_parser.parse_and_validate_query( metric_names=("bookings_at_start_of_month",), group_by_names=("metric_time__day", "metric_time__month", "metric_time__year"), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -772,7 +772,7 @@ def test_offset_window_metric_filter_and_query_have_different_granularities( where_constraint=PydanticWhereFilter( where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -801,7 +801,7 @@ def test_offset_to_grain_metric_filter_and_query_have_different_granularities( where_constraint=PydanticWhereFilter( where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( diff --git a/tests_metricflow/query_rendering/test_fill_nulls_with_rendering.py b/tests_metricflow/query_rendering/test_fill_nulls_with_rendering.py index f820b8bbe4..5490338441 100644 --- a/tests_metricflow/query_rendering/test_fill_nulls_with_rendering.py +++ b/tests_metricflow/query_rendering/test_fill_nulls_with_rendering.py @@ -214,7 +214,7 @@ def test_join_to_time_spine_with_filters( # noqa: D103 ), time_constraint_start=datetime.datetime(2020, 1, 3), time_constraint_end=datetime.datetime(2020, 1, 5), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( diff --git a/tests_metricflow/query_rendering/test_metric_filter_rendering.py b/tests_metricflow/query_rendering/test_metric_filter_rendering.py index 3cbc9909e1..b4e3940d24 100644 --- a/tests_metricflow/query_rendering/test_metric_filter_rendering.py +++ b/tests_metricflow/query_rendering/test_metric_filter_rendering.py @@ -27,7 +27,7 @@ def test_query_with_simple_metric_in_where_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('bookings', ['listing']) }} > 2", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -52,7 +52,7 @@ def test_metric_with_metric_in_where_filter( query_spec = query_parser.parse_and_validate_query( metric_names=("active_listings",), group_by_names=("metric_time__day",), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -79,7 +79,7 @@ def test_query_with_derived_metric_in_where_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('views_times_booking_value', ['listing']) }} > 1", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -106,7 +106,7 @@ def test_query_with_ratio_metric_in_where_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('bookings_per_booker', ['listing']) }} > 1", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -136,7 +136,7 @@ def test_query_with_cumulative_metric_in_where_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('revenue_all_time', ['user']) }} > 1", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -163,7 +163,7 @@ def test_query_with_multiple_metrics_in_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('bookings', ['listing']) }} > 2 AND {{ Metric('bookers', ['listing']) }} > 1", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -190,7 +190,7 @@ def test_filter_by_metric_in_same_semantic_model_as_queried_metric( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('booking_value', ['guest']) }} > 1.00", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -217,7 +217,7 @@ def test_distinct_values_query_with_metric_filter( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('bookings', ['listing']) }} > 2", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values(query_spec) convert_and_check( @@ -244,7 +244,7 @@ def test_metric_filtered_by_itself( where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('bookers', ['guest']) }} > 1.00", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -270,7 +270,7 @@ def test_group_by_has_local_entity_prefix( # noqa: D103 where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('average_booking_value', ['listing__user']) }} > 1", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -296,7 +296,7 @@ def test_filter_with_conversion_metric( # noqa: D103 where_constraint=PydanticWhereFilter( where_sql_template="{{ Metric('visit_buy_conversion_rate', ['user']) }} > 2", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( diff --git a/tests_metricflow/query_rendering/test_query_rendering.py b/tests_metricflow/query_rendering/test_query_rendering.py index b07e349dd9..927ad92e07 100644 --- a/tests_metricflow/query_rendering/test_query_rendering.py +++ b/tests_metricflow/query_rendering/test_query_rendering.py @@ -83,7 +83,7 @@ def test_filter_with_where_constraint_on_join_dim( where_constraint=PydanticWhereFilter( where_sql_template="{{ Dimension('listing__country_latest') }} = 'us'", ), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -174,7 +174,7 @@ def test_distinct_values( where_sql_template="{{ Dimension('listing__country_latest') }} = 'us'", ), limit=100, - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values(query_spec) convert_and_check( @@ -227,7 +227,7 @@ def test_measure_constraint( # noqa: D103 query_spec = query_parser.parse_and_validate_query( metric_names=("lux_booking_value_rate_expr",), group_by_names=(MTD_SPEC_DAY.qualified_name,), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -251,7 +251,7 @@ def test_measure_constraint_with_reused_measure( # noqa: D103 query_spec = query_parser.parse_and_validate_query( metric_names=("instant_booking_value_ratio",), group_by_names=(MTD_SPEC_DAY.qualified_name,), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) convert_and_check( @@ -275,7 +275,7 @@ def test_measure_constraint_with_single_expr_and_alias( # noqa: D103 query_spec = query_parser.parse_and_validate_query( metric_names=("double_counted_delayed_bookings",), group_by_names=(MTD_SPEC_DAY.qualified_name,), - ) + ).query_spec dataflow_plan = dataflow_plan_builder.build_plan(query_spec) @@ -305,7 +305,7 @@ def test_join_to_scd_dimension( where_constraint=PydanticWhereFilter( where_sql_template="{{ Dimension('listing__capacity') }} > 2", ), - ) + ).query_spec dataflow_plan = scd_dataflow_plan_builder.build_plan(query_spec) convert_and_check(