diff --git a/metricflow/model/semantics/linkable_spec_resolver.py b/metricflow/model/semantics/linkable_spec_resolver.py index f3fedf0f81..26f36af5a0 100644 --- a/metricflow/model/semantics/linkable_spec_resolver.py +++ b/metricflow/model/semantics/linkable_spec_resolver.py @@ -139,7 +139,7 @@ def metric_to_entity_join_path(self) -> Optional[SemanticModelJoinPath]: @property def metric_subquery_entity_links(self) -> Tuple[EntityReference, ...]: """Entity links used to join the metric to the entity it's grouped by in the metric subquery.""" - return self.metric_to_entity_join_path.entity_links if self.metric_to_entity_join_path else () + return self.join_path.metric_subquery_join_path_element.entity_links @dataclass(frozen=True) @@ -410,6 +410,11 @@ class MetricSubqueryJoinPathElement: join_on_entity: EntityReference metric_to_entity_join_path: Optional[SemanticModelJoinPath] = None + @property + def entity_links(self) -> Tuple[EntityReference, ...]: # noqa: D102 + join_links = self.metric_to_entity_join_path.entity_links if self.metric_to_entity_join_path else () + return join_links + (self.join_on_entity,) + @dataclass(frozen=True) class SemanticModelToMetricSubqueryJoinPath: diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 05895e7a81..e2160630cb 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -736,8 +736,8 @@ def visit_compute_metrics_node(self, node: ComputeMetricsNode) -> SqlDataSet: defined_from=metric_instance.defined_from, spec=GroupByMetricSpec( element_name=metric_spec.element_name, - entity_links=(), # check this - metric_subquery_entity_links=entity_instance.spec.entity_links, + entity_links=(), + metric_subquery_entity_links=entity_instance.spec.entity_links + (entity_instance.spec.reference,), ), ) transform_func = AddGroupByMetric(group_by_metric_instance) diff --git a/metricflow/specs/specs.py b/metricflow/specs/specs.py index 8e86a247be..e51b525da2 100644 --- a/metricflow/specs/specs.py +++ b/metricflow/specs/specs.py @@ -249,12 +249,18 @@ class GroupByMetricSpec(LinkableInstanceSpec, SerializableDataclass): entity_links: Sequence of entities joined to join the metric subquery to the outer query. Last entity is the one joining the subquery to the outer query. metric_subquery_entity_links: Sequence of entities used in the metric subquery to join the metric to the entity. - Does not include the top-level entity (to avoid duplicating the last element of `entity_links`). - """ metric_subquery_entity_links: Tuple[EntityReference, ...] + def __post_init__(self) -> None: + """The inner query and outer query entity paths must end with the same entity (that's what they join on). + + If no entity links, it's because we're already in the final joined node (no links left). + """ + if self.entity_links: + assert self.metric_subquery_entity_links[-1] == self.entity_links[-1] + @property def without_first_entity_link(self) -> GroupByMetricSpec: # noqa: D102 assert len(self.entity_links) > 0, f"Spec does not have any entity links: {self}" @@ -277,21 +283,15 @@ def last_entity_link(self) -> EntityReference: # noqa: D102 assert len(self.entity_links) > 0, f"Spec does not have any entity links: {self}" return self.entity_links[-1] - @staticmethod - def from_name(name: str) -> GroupByMetricSpec: # noqa: D102 - structured_name = StructuredLinkableSpecName.from_name(name) - return GroupByMetricSpec( - entity_links=tuple(EntityReference(idl) for idl in structured_name.entity_link_names), - element_name=structured_name.element_name, - metric_subquery_entity_links=(), - ) - @property def metric_subquery_entity_spec(self) -> EntitySpec: """Spec for the entity that the metric will be grouped by it the metric subquery.""" + assert ( + len(self.metric_subquery_entity_links) > 0 + ), "GroupByMetricSpec must have at least one metric_subquery_entity_link." return EntitySpec( - element_name=self.last_entity_link.element_name, - entity_links=self.metric_subquery_entity_links, + element_name=self.metric_subquery_entity_links[-1].element_name, + entity_links=self.metric_subquery_entity_links[:-1], ) def __eq__(self, other: Any) -> bool: # type: ignore[misc] # noqa: D105 diff --git a/tests/model/test_where_filter_spec.py b/tests/model/test_where_filter_spec.py index f7f1d41a0f..b48afacb81 100644 --- a/tests/model/test_where_filter_spec.py +++ b/tests/model/test_where_filter_spec.py @@ -371,7 +371,9 @@ def test_metric_in_filter( # noqa: D103 where_filter = PydanticWhereFilter(where_sql_template="{{ Metric('bookings', group_by=['listing']) }} > 2") group_by_metric_spec = GroupByMetricSpec( - element_name="bookings", entity_links=(EntityReference("listing"),), metric_subquery_entity_links=() + element_name="bookings", + entity_links=(EntityReference("listing"),), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ) where_filter_spec = WhereSpecFactory( column_association_resolver=column_association_resolver, diff --git a/tests/naming/conftest.py b/tests/naming/conftest.py index 07f8fb07d1..9d28e000cc 100644 --- a/tests/naming/conftest.py +++ b/tests/naming/conftest.py @@ -53,6 +53,6 @@ def specs() -> Sequence[LinkableInstanceSpec]: # noqa: D103 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ), ) diff --git a/tests/naming/test_object_builder_naming_scheme.py b/tests/naming/test_object_builder_naming_scheme.py index e003503b3d..0e906c8848 100644 --- a/tests/naming/test_object_builder_naming_scheme.py +++ b/tests/naming/test_object_builder_naming_scheme.py @@ -52,7 +52,7 @@ def test_input_str(object_builder_naming_scheme: ObjectBuilderNamingScheme) -> N GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ) ) == "Metric('bookings', group_by=['listing'])" @@ -125,6 +125,6 @@ def test_spec_pattern( # noqa: D103 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ), ) diff --git a/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_metric_where_filter__dfp_0.xml b/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_metric_where_filter__dfp_0.xml index 1f539c3a57..6fa76e63ee 100644 --- a/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_metric_where_filter__dfp_0.xml +++ b/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_metric_where_filter__dfp_0.xml @@ -23,11 +23,12 @@ - - - - - + + + + + + @@ -56,10 +57,14 @@ - + - + + + + + diff --git a/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_query_where_filter__dfp_0.xml b/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_query_where_filter__dfp_0.xml index f0a5328a55..37fcaf497c 100644 --- a/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_query_where_filter__dfp_0.xml +++ b/tests/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_metric_in_query_where_filter__dfp_0.xml @@ -32,11 +32,12 @@ - - - - - + + + + + + @@ -65,10 +66,14 @@ - + - + + + + + diff --git a/tests/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt b/tests/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt index 50853aecf0..b01f907f15 100644 --- a/tests/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt +++ b/tests/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt @@ -165,83 +165,61 @@ 'metric_time__year', 'user', 'user__active_listings', - 'user__approximate_continuous_booking_value_p99', - 'user__approximate_discrete_booking_value_p99', - 'user__average_booking_value', - 'user__average_instant_booking_value', - 'user__bookers', - 'user__booking_fees', - 'user__booking_fees_per_booker', - 'user__booking_payments', - 'user__booking_value', - 'user__booking_value_for_non_null_listing_id', - 'user__booking_value_p99', - 'user__booking_value_per_view', - 'user__booking_value_sub_instant', - 'user__booking_value_sub_instant_add_10', - 'user__bookings', - 'user__bookings_fill_nulls_with_0', - 'user__bookings_fill_nulls_with_0_without_time_spine', - 'user__bookings_join_to_time_spine', - 'user__bookings_per_booker', - 'user__bookings_per_dollar', 'user__bookings_per_listing', - 'user__bookings_per_lux_listing_derived', - 'user__bookings_per_view', 'user__company', 'user__company__active_listings', - 'user__company__approximate_continuous_booking_value_p99', - 'user__company__approximate_discrete_booking_value_p99', - 'user__company__average_booking_value', - 'user__company__average_instant_booking_value', - 'user__company__bookers', - 'user__company__booking_fees', - 'user__company__booking_fees_per_booker', - 'user__company__booking_payments', - 'user__company__booking_value', - 'user__company__booking_value_for_non_null_listing_id', - 'user__company__booking_value_p99', - 'user__company__booking_value_per_view', - 'user__company__booking_value_sub_instant', - 'user__company__booking_value_sub_instant_add_10', - 'user__company__bookings', - 'user__company__bookings_fill_nulls_with_0', - 'user__company__bookings_fill_nulls_with_0_without_time_spine', - 'user__company__bookings_join_to_time_spine', - 'user__company__bookings_per_booker', - 'user__company__bookings_per_dollar', - 'user__company__bookings_per_view', 'user__company__current_account_balance_by_user', - 'user__company__derived_bookings_0', - 'user__company__derived_bookings_1', - 'user__company__discrete_booking_value_p99', - 'user__company__double_counted_delayed_bookings', 'user__company__identity_verifications', - 'user__company__instant_booking_fraction_of_max_value', - 'user__company__instant_booking_value', - 'user__company__instant_booking_value_ratio', - 'user__company__instant_bookings', - 'user__company__instant_lux_booking_value_rate', - 'user__company__instant_plus_non_referred_bookings_pct', 'user__company__largest_listing', + 'user__company__listing__user__company__approximate_continuous_booking_value_p99', + 'user__company__listing__user__company__approximate_discrete_booking_value_p99', + 'user__company__listing__user__company__average_booking_value', + 'user__company__listing__user__company__average_instant_booking_value', + 'user__company__listing__user__company__bookers', + 'user__company__listing__user__company__booking_fees', + 'user__company__listing__user__company__booking_fees_per_booker', + 'user__company__listing__user__company__booking_payments', + 'user__company__listing__user__company__booking_value', + 'user__company__listing__user__company__booking_value_for_non_null_listing_id', + 'user__company__listing__user__company__booking_value_p99', + 'user__company__listing__user__company__booking_value_per_view', + 'user__company__listing__user__company__booking_value_sub_instant', + 'user__company__listing__user__company__booking_value_sub_instant_add_10', + 'user__company__listing__user__company__bookings', + 'user__company__listing__user__company__bookings_fill_nulls_with_0', + 'user__company__listing__user__company__bookings_fill_nulls_with_0_without_time_spine', + 'user__company__listing__user__company__bookings_join_to_time_spine', + 'user__company__listing__user__company__bookings_per_booker', + 'user__company__listing__user__company__bookings_per_dollar', + 'user__company__listing__user__company__bookings_per_view', + 'user__company__listing__user__company__derived_bookings_0', + 'user__company__listing__user__company__derived_bookings_1', + 'user__company__listing__user__company__discrete_booking_value_p99', + 'user__company__listing__user__company__double_counted_delayed_bookings', + 'user__company__listing__user__company__instant_booking_fraction_of_max_value', + 'user__company__listing__user__company__instant_booking_value', + 'user__company__listing__user__company__instant_booking_value_ratio', + 'user__company__listing__user__company__instant_bookings', + 'user__company__listing__user__company__instant_lux_booking_value_rate', + 'user__company__listing__user__company__instant_plus_non_referred_bookings_pct', + 'user__company__listing__user__company__lux_booking_fraction_of_max_value', + 'user__company__listing__user__company__lux_booking_value_rate_expr', + 'user__company__listing__user__company__max_booking_value', + 'user__company__listing__user__company__median_booking_value', + 'user__company__listing__user__company__min_booking_value', + 'user__company__listing__user__company__nested_fill_nulls_without_time_spine', + 'user__company__listing__user__company__non_referred_bookings_pct', + 'user__company__listing__user__company__referred_bookings', + 'user__company__listing__user__company__twice_bookings_fill_nulls_with_0_without_time_spine', + 'user__company__listing__user__company__views', + 'user__company__listing__user__company__views_times_booking_value', 'user__company__listings', - 'user__company__lux_booking_fraction_of_max_value', - 'user__company__lux_booking_value_rate_expr', 'user__company__lux_listings', - 'user__company__max_booking_value', - 'user__company__median_booking_value', - 'user__company__min_booking_value', - 'user__company__nested_fill_nulls_without_time_spine', - 'user__company__non_referred_bookings_pct', - 'user__company__referred_bookings', 'user__company__regional_starting_balance_ratios', 'user__company__revenue', 'user__company__revenue_all_time', 'user__company__smallest_listing', 'user__company__total_account_balance_first_day', - 'user__company__twice_bookings_fill_nulls_with_0_without_time_spine', - 'user__company__views', - 'user__company__views_times_booking_value', 'user__company__visit_buy_conversion_rate', 'user__company__visit_buy_conversion_rate_7days', 'user__company__visit_buy_conversion_rate_7days_fill_nulls_with_0', @@ -269,10 +247,6 @@ 'user__created_at__week', 'user__created_at__year', 'user__current_account_balance_by_user', - 'user__derived_bookings_0', - 'user__derived_bookings_1', - 'user__discrete_booking_value_p99', - 'user__double_counted_delayed_bookings', 'user__ds__day', 'user__ds__extract_day', 'user__ds__extract_dow', @@ -336,31 +310,57 @@ 'user__home_state', 'user__home_state_latest', 'user__identity_verifications', - 'user__instant_booking_fraction_of_max_value', - 'user__instant_booking_value', - 'user__instant_booking_value_ratio', - 'user__instant_bookings', - 'user__instant_lux_booking_value_rate', - 'user__instant_plus_non_referred_bookings_pct', 'user__largest_listing', + 'user__listing__user__approximate_continuous_booking_value_p99', + 'user__listing__user__approximate_discrete_booking_value_p99', + 'user__listing__user__average_booking_value', + 'user__listing__user__average_instant_booking_value', + 'user__listing__user__bookers', + 'user__listing__user__booking_fees', + 'user__listing__user__booking_fees_per_booker', + 'user__listing__user__booking_payments', + 'user__listing__user__booking_value', + 'user__listing__user__booking_value_for_non_null_listing_id', + 'user__listing__user__booking_value_p99', + 'user__listing__user__booking_value_per_view', + 'user__listing__user__booking_value_sub_instant', + 'user__listing__user__booking_value_sub_instant_add_10', + 'user__listing__user__bookings', + 'user__listing__user__bookings_fill_nulls_with_0', + 'user__listing__user__bookings_fill_nulls_with_0_without_time_spine', + 'user__listing__user__bookings_join_to_time_spine', + 'user__listing__user__bookings_per_booker', + 'user__listing__user__bookings_per_dollar', + 'user__listing__user__bookings_per_lux_listing_derived', + 'user__listing__user__bookings_per_view', + 'user__listing__user__derived_bookings_0', + 'user__listing__user__derived_bookings_1', + 'user__listing__user__discrete_booking_value_p99', + 'user__listing__user__double_counted_delayed_bookings', + 'user__listing__user__instant_booking_fraction_of_max_value', + 'user__listing__user__instant_booking_value', + 'user__listing__user__instant_booking_value_ratio', + 'user__listing__user__instant_bookings', + 'user__listing__user__instant_lux_booking_value_rate', + 'user__listing__user__instant_plus_non_referred_bookings_pct', + 'user__listing__user__lux_booking_fraction_of_max_value', + 'user__listing__user__lux_booking_value_rate_expr', + 'user__listing__user__max_booking_value', + 'user__listing__user__median_booking_value', + 'user__listing__user__min_booking_value', + 'user__listing__user__nested_fill_nulls_without_time_spine', + 'user__listing__user__non_referred_bookings_pct', + 'user__listing__user__referred_bookings', + 'user__listing__user__twice_bookings_fill_nulls_with_0_without_time_spine', + 'user__listing__user__views', + 'user__listing__user__views_times_booking_value', 'user__listings', - 'user__lux_booking_fraction_of_max_value', - 'user__lux_booking_value_rate_expr', 'user__lux_listings', - 'user__max_booking_value', - 'user__median_booking_value', - 'user__min_booking_value', - 'user__nested_fill_nulls_without_time_spine', - 'user__non_referred_bookings_pct', - 'user__referred_bookings', 'user__regional_starting_balance_ratios', 'user__revenue', 'user__revenue_all_time', 'user__smallest_listing', 'user__total_account_balance_first_day', - 'user__twice_bookings_fill_nulls_with_0_without_time_spine', - 'user__views', - 'user__views_times_booking_value', 'user__visit_buy_conversion_rate', 'user__visit_buy_conversion_rate_7days', 'user__visit_buy_conversion_rate_7days_fill_nulls_with_0', diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql index e899374cbf..af2d1974cd 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql @@ -24,7 +24,7 @@ FROM ( FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_28000 ) subq_4 FULL OUTER JOIN ( - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT subq_9.listing , subq_9.bookings diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql index ceb44d1602..28223e439b 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql @@ -11,7 +11,7 @@ FROM ( FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT listing , SUM(bookings) AS bookings diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql index 65a3c59db6..2b315eab94 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql @@ -227,7 +227,7 @@ FROM ( ) subq_5 ) subq_6 LEFT OUTER JOIN ( - -- Pass Only Elements: ['guest', 'booking_value'] + -- Pass Only Elements: ['guest', 'guest__booking_value'] SELECT subq_11.guest , subq_11.booking_value diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql index d7ee2ded1b..53c4da07c1 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql @@ -25,7 +25,7 @@ FROM ( -- Pass Only Elements: ['booking_value', 'guest'] -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['guest', 'booking_value'] + -- Pass Only Elements: ['guest', 'guest__booking_value'] SELECT guest_id AS guest , SUM(booking_value) AS booking_value diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql index 09749c68b5..503523e9cd 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql @@ -227,7 +227,7 @@ FROM ( ) subq_5 ) subq_6 LEFT OUTER JOIN ( - -- Pass Only Elements: ['guest', 'bookers'] + -- Pass Only Elements: ['guest', 'guest__bookers'] SELECT subq_11.guest , subq_11.bookers diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql index eb7a693290..07a356a39c 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql @@ -25,7 +25,7 @@ FROM ( -- Pass Only Elements: ['bookers', 'guest'] -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['guest', 'bookers'] + -- Pass Only Elements: ['guest', 'guest__bookers'] SELECT guest_id AS guest , COUNT(DISTINCT guest_id) AS bookers diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql index 62adc84823..575a247d37 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql @@ -171,7 +171,7 @@ FROM ( ) subq_5 ) subq_6 LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT subq_11.listing , subq_11.bookings diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql index 903c2101af..1ad72fa0ef 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql @@ -25,7 +25,7 @@ FROM ( LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT listing , SUM(bookings) AS bookings diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql index 6b74b95a17..3a031bcabc 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql @@ -164,7 +164,7 @@ FROM ( ) subq_5 ) subq_6 LEFT OUTER JOIN ( - -- Pass Only Elements: ['user', 'revenue_all_time'] + -- Pass Only Elements: ['user', 'user__revenue_all_time'] SELECT subq_11.user , subq_11.revenue_all_time diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql index a792c0fd8c..ca59324e35 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql @@ -25,7 +25,7 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'user'] -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['user', 'revenue_all_time'] + -- Pass Only Elements: ['user', 'user__revenue_all_time'] SELECT user_id AS user , SUM(revenue) AS revenue_all_time diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql index 77c1a58da0..c0386038eb 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql @@ -164,7 +164,7 @@ FROM ( ) subq_12 ) subq_13 LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'views_times_booking_value'] + -- Pass Only Elements: ['listing', 'listing__views_times_booking_value'] SELECT subq_25.listing , subq_25.views_times_booking_value diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql index 26cfeb4e15..d91def71f1 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql @@ -21,7 +21,7 @@ FROM ( ) subq_34 LEFT OUTER JOIN ( -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing', 'views_times_booking_value'] + -- Pass Only Elements: ['listing', 'listing__views_times_booking_value'] SELECT listing , booking_value * views AS views_times_booking_value diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql index 7216cec41a..c8ea694bf4 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql @@ -167,7 +167,7 @@ FROM ( ) subq_9 ) subq_10 LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT subq_15.listing , subq_15.bookings @@ -390,7 +390,7 @@ FROM ( ON subq_10.listing = subq_16.listing LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'bookers'] + -- Pass Only Elements: ['listing', 'listing__bookers'] SELECT subq_21.listing , subq_21.bookers diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql index f79437fa1d..746675a7dc 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql @@ -23,7 +23,7 @@ FROM ( LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT listing , SUM(bookings) AS bookings @@ -47,7 +47,7 @@ FROM ( -- Pass Only Elements: ['bookers', 'listing'] -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing', 'bookers'] + -- Pass Only Elements: ['listing', 'listing__bookers'] SELECT listing_id AS listing , COUNT(DISTINCT guest_id) AS bookers diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql index b0c7913eb8..83ffdd692a 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql @@ -164,7 +164,7 @@ FROM ( ) subq_12 ) subq_13 LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'bookings_per_booker'] + -- Pass Only Elements: ['listing', 'listing__bookings_per_booker'] SELECT subq_25.listing , subq_25.bookings_per_booker diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql index 568e713172..e81b40e399 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql @@ -164,7 +164,7 @@ FROM ( ) subq_5 ) subq_6 LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT subq_11.listing , subq_11.bookings diff --git a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql index 15f82749c5..d453137357 100644 --- a/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql +++ b/tests/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql @@ -22,7 +22,7 @@ FROM ( LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing', 'bookings'] + -- Pass Only Elements: ['listing', 'listing__bookings'] SELECT listing , SUM(bookings) AS bookings diff --git a/tests/specs/patterns/test_entity_link_pattern.py b/tests/specs/patterns/test_entity_link_pattern.py index 73e5fc2562..e83ba6e5bd 100644 --- a/tests/specs/patterns/test_entity_link_pattern.py +++ b/tests/specs/patterns/test_entity_link_pattern.py @@ -56,7 +56,7 @@ def specs() -> Sequence[LinkableInstanceSpec]: # noqa: D103 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ), ) @@ -131,7 +131,7 @@ def test_group_by_metric_match(specs: Sequence[LinkableInstanceSpec]) -> None: GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ), ) diff --git a/tests/specs/patterns/test_typed_patterns.py b/tests/specs/patterns/test_typed_patterns.py index d0625cd741..78b4017306 100644 --- a/tests/specs/patterns/test_typed_patterns.py +++ b/tests/specs/patterns/test_typed_patterns.py @@ -60,7 +60,7 @@ def specs() -> Sequence[LinkableInstanceSpec]: # noqa: D103 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ), ) @@ -158,6 +158,6 @@ def test_group_by_metric_pattern(specs: Sequence[LinkableInstanceSpec]) -> None: GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference("listing"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing"),), ), ) diff --git a/tests/test_specs.py b/tests/test_specs.py index 27c3a26be6..0ee5cc52bc 100644 --- a/tests/test_specs.py +++ b/tests/test_specs.py @@ -145,7 +145,7 @@ def spec_set() -> InstanceSpecSet: # noqa: D103 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing_id"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing_id"),), ), ), ) @@ -166,7 +166,7 @@ def test_spec_set_linkable_specs(spec_set: InstanceSpecSet) -> None: # noqa: D1 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing_id"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing_id"),), ), } @@ -190,7 +190,7 @@ def test_spec_set_all_specs(spec_set: InstanceSpecSet) -> None: # noqa: D103 GroupByMetricSpec( element_name="bookings", entity_links=(EntityReference(element_name="listing_id"),), - metric_subquery_entity_links=(), + metric_subquery_entity_links=(EntityReference(element_name="listing_id"),), ), }