Skip to content

Commit

Permalink
Dedupe qualified name for GroupByMetricSpecs
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed May 2, 2024
1 parent 78beac2 commit 37319ec
Show file tree
Hide file tree
Showing 22 changed files with 469 additions and 452 deletions.
17 changes: 17 additions & 0 deletions metricflow-semantics/metricflow_semantics/specs/spec_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,23 @@ def metric_subquery_entity_spec(self) -> EntitySpec:
entity_links=self.metric_subquery_entity_links[:-1],
)

@property
def qualified_name(self) -> str:
"""Element name prefixed with entity links.
If same entity links are used in inner & outer query, use standard qualified name (country__bookings).
Else, specify both sets of entity links (listing__country__user__country__bookings).
"""
if self.entity_links == self.metric_subquery_entity_links:
entity_links = self.entity_links
else:
entity_links = self.entity_links + self.metric_subquery_entity_links

return StructuredLinkableSpecName(
entity_link_names=tuple(entity_link.element_name for entity_link in entity_links),
element_name=self.element_name,
).qualified_name

def __eq__(self, other: Any) -> bool: # type: ignore[misc] # noqa: D105
if not isinstance(other, GroupByMetricSpec):
return False
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</MetricTimeDimensionTransformNode>
</FilterElementsNode>
<FilterElementsNode>
<!-- description = "Pass Only Elements: ['listing', 'bookings']" -->
<!-- description = "Pass Only Elements: ['listing', 'listing__bookings']" -->
<!-- node_id = NodeId(id_str='pfe_2') -->
<!-- include_spec = LinklessEntitySpec(element_name='listing') -->
<!-- include_spec = -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</MetricTimeDimensionTransformNode>
</FilterElementsNode>
<FilterElementsNode>
<!-- description = "Pass Only Elements: ['listing', 'bookings']" -->
<!-- description = "Pass Only Elements: ['listing', 'listing__bookings']" -->
<!-- node_id = NodeId(id_str='pfe_2') -->
<!-- include_spec = LinklessEntitySpec(element_name='listing') -->
<!-- include_spec = -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37319ec

Please sign in to comment.