Skip to content

Commit

Permalink
Always use spec's qualified name as column name
Browse files Browse the repository at this point in the history
Previously we were duplicating this logic, which made it easy to overlook updating the column name to use the qualified name. I updated this for all specs so that it will update automatically in the future. You can see in the snapshots that this changed nothing for most specs, except group by metrics (as expected).
  • Loading branch information
courtneyholcomb committed May 3, 2024
1 parent bbd5d4a commit a2bc7fd
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup
from metricflow_semantics.naming.linkable_spec_name import DUNDER, StructuredLinkableSpecName
from metricflow_semantics.naming.linkable_spec_name import DUNDER
from metricflow_semantics.specs.column_assoc import (
ColumnAssociation,
ColumnAssociationResolver,
Expand Down Expand Up @@ -59,23 +59,13 @@ def visit_measure_spec(self, measure_spec: MeasureSpec) -> ColumnAssociation: #

def visit_dimension_spec(self, dimension_spec: DimensionSpec) -> ColumnAssociation: # noqa: D102
return ColumnAssociation(
column_name=StructuredLinkableSpecName(
entity_link_names=tuple(x.element_name for x in dimension_spec.entity_links),
element_name=dimension_spec.element_name,
).qualified_name,
column_name=dimension_spec.qualified_name,
single_column_correlation_key=SingleColumnCorrelationKey(),
)

def visit_time_dimension_spec(self, time_dimension_spec: TimeDimensionSpec) -> ColumnAssociation: # noqa: D102
column_name = StructuredLinkableSpecName(
entity_link_names=tuple(x.element_name for x in time_dimension_spec.entity_links),
element_name=time_dimension_spec.element_name,
time_granularity=time_dimension_spec.time_granularity,
date_part=time_dimension_spec.date_part,
).qualified_name

return ColumnAssociation(
column_name=column_name
column_name=time_dimension_spec.qualified_name
+ (
f"{DUNDER}{time_dimension_spec.aggregation_state.value.lower()}"
if time_dimension_spec.aggregation_state
Expand All @@ -86,19 +76,13 @@ def visit_time_dimension_spec(self, time_dimension_spec: TimeDimensionSpec) -> C

def visit_entity_spec(self, entity_spec: EntitySpec) -> ColumnAssociation: # noqa: D102
return ColumnAssociation(
column_name=StructuredLinkableSpecName(
entity_link_names=tuple(x.element_name for x in entity_spec.entity_links),
element_name=entity_spec.element_name,
).qualified_name,
column_name=entity_spec.qualified_name,
single_column_correlation_key=SingleColumnCorrelationKey(),
)

def visit_group_by_metric_spec(self, group_by_metric_spec: GroupByMetricSpec) -> ColumnAssociation: # noqa: D102
return ColumnAssociation(
column_name=StructuredLinkableSpecName(
entity_link_names=tuple(x.element_name for x in group_by_metric_spec.entity_links),
element_name=group_by_metric_spec.element_name,
).qualified_name,
column_name=group_by_metric_spec.qualified_name,
single_column_correlation_key=SingleColumnCorrelationKey(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FROM (
subq_4.listing AS listing
, subq_4.lux_listing AS lux_listing
, subq_4.listing__lux_listing AS listing__lux_listing
, subq_10.bookings AS listing__bookings
, subq_10.listing__bookings AS listing__bookings
FROM (
-- Read Elements From Semantic Model 'lux_listing_mapping'
SELECT
Expand All @@ -27,12 +27,12 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookings']
SELECT
subq_9.listing
, subq_9.bookings
, subq_9.listing__bookings
FROM (
-- Compute Metrics via Expressions
SELECT
subq_8.listing
, subq_8.bookings
, subq_8.bookings AS listing__bookings
FROM (
-- Aggregate Measures
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ FROM (
-- Join Standard Outputs
SELECT
lux_listing_mapping_src_28000.listing_id AS listing
, subq_19.bookings AS listing__bookings
, subq_19.listing__bookings AS listing__bookings
FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_28000
FULL OUTER JOIN (
-- Aggregate Measures
-- Compute Metrics via Expressions
-- Pass Only Elements: ['listing', 'listing__bookings']
SELECT
listing
, SUM(bookings) AS bookings
, SUM(bookings) AS listing__bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM (
-- Join Standard Outputs
SELECT
subq_6.guest AS guest
, subq_12.booking_value AS guest__booking_value
, subq_12.guest__booking_value AS guest__booking_value
, subq_6.bookers AS bookers
FROM (
-- Pass Only Elements: ['bookers', 'guest']
Expand Down Expand Up @@ -230,12 +230,12 @@ FROM (
-- Pass Only Elements: ['guest', 'guest__booking_value']
SELECT
subq_11.guest
, subq_11.booking_value
, subq_11.guest__booking_value
FROM (
-- Compute Metrics via Expressions
SELECT
subq_10.guest
, subq_10.booking_value
, subq_10.booking_value AS guest__booking_value
FROM (
-- Aggregate Measures
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['bookers', 'guest__booking_value']
SELECT
subq_26.booking_value AS guest__booking_value
subq_26.guest__booking_value AS guest__booking_value
, subq_20.bookers AS bookers
FROM (
-- Read Elements From Semantic Model 'bookings_source'
Expand All @@ -28,7 +28,7 @@ FROM (
-- Pass Only Elements: ['guest', 'guest__booking_value']
SELECT
guest_id AS guest
, SUM(booking_value) AS booking_value
, SUM(booking_value) AS guest__booking_value
FROM ***************************.fct_bookings bookings_source_src_28000
GROUP BY
guest_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM (
-- Join Standard Outputs
SELECT
subq_6.guest AS guest
, subq_12.bookers AS guest__bookers
, subq_12.guest__bookers AS guest__bookers
, subq_6.bookers AS bookers
FROM (
-- Pass Only Elements: ['bookers', 'guest']
Expand Down Expand Up @@ -230,12 +230,12 @@ FROM (
-- Pass Only Elements: ['guest', 'guest__bookers']
SELECT
subq_11.guest
, subq_11.bookers
, subq_11.guest__bookers
FROM (
-- Compute Metrics via Expressions
SELECT
subq_10.guest
, subq_10.bookers
, subq_10.bookers AS guest__bookers
FROM (
-- Aggregate Measures
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['bookers', 'guest__bookers']
SELECT
subq_26.bookers AS guest__bookers
subq_26.guest__bookers AS guest__bookers
, subq_20.bookers AS bookers
FROM (
-- Read Elements From Semantic Model 'bookings_source'
Expand All @@ -28,7 +28,7 @@ FROM (
-- Pass Only Elements: ['guest', 'guest__bookers']
SELECT
guest_id AS guest
, COUNT(DISTINCT guest_id) AS bookers
, COUNT(DISTINCT guest_id) AS guest__bookers
FROM ***************************.fct_bookings bookings_source_src_28000
GROUP BY
guest_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FROM (
SELECT
subq_6.metric_time__day AS metric_time__day
, subq_6.listing AS listing
, subq_12.bookings AS listing__bookings
, subq_12.listing__bookings AS listing__bookings
, subq_6.listings AS listings
FROM (
-- Pass Only Elements: ['listings', 'metric_time__day', 'listing']
Expand Down Expand Up @@ -174,12 +174,12 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookings']
SELECT
subq_11.listing
, subq_11.bookings
, subq_11.listing__bookings
FROM (
-- Compute Metrics via Expressions
SELECT
subq_10.listing
, subq_10.bookings
, subq_10.bookings AS listing__bookings
FROM (
-- Aggregate Measures
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FROM (
-- Pass Only Elements: ['listings', 'metric_time__day', 'listing__bookings']
SELECT
subq_20.metric_time__day AS metric_time__day
, subq_26.bookings AS listing__bookings
, subq_26.listing__bookings AS listing__bookings
, subq_20.listings AS listings
FROM (
-- Read Elements From Semantic Model 'listings_latest'
Expand All @@ -28,7 +28,7 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookings']
SELECT
listing
, SUM(bookings) AS bookings
, SUM(bookings) AS listing__bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM (
-- Join Standard Outputs
SELECT
subq_6.user AS user
, subq_12.revenue_all_time AS user__revenue_all_time
, subq_12.user__revenue_all_time AS user__revenue_all_time
, subq_6.listings AS listings
FROM (
-- Pass Only Elements: ['listings', 'user']
Expand Down Expand Up @@ -167,12 +167,12 @@ FROM (
-- Pass Only Elements: ['user', 'user__revenue_all_time']
SELECT
subq_11.user
, subq_11.revenue_all_time
, subq_11.user__revenue_all_time
FROM (
-- Compute Metrics via Expressions
SELECT
subq_10.user
, subq_10.txn_revenue AS revenue_all_time
, subq_10.txn_revenue AS user__revenue_all_time
FROM (
-- Aggregate Measures
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['listings', 'user__revenue_all_time']
SELECT
subq_26.revenue_all_time AS user__revenue_all_time
subq_26.user__revenue_all_time AS user__revenue_all_time
, subq_20.listings AS listings
FROM (
-- Read Elements From Semantic Model 'listings_latest'
Expand All @@ -28,7 +28,7 @@ FROM (
-- Pass Only Elements: ['user', 'user__revenue_all_time']
SELECT
user_id AS user
, SUM(revenue) AS revenue_all_time
, SUM(revenue) AS user__revenue_all_time
FROM ***************************.fct_revenue revenue_src_28000
GROUP BY
user_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM (
-- Join Standard Outputs
SELECT
subq_13.listing AS listing
, subq_26.views_times_booking_value AS listing__views_times_booking_value
, subq_26.listing__views_times_booking_value AS listing__views_times_booking_value
, subq_13.listings AS listings
FROM (
-- Pass Only Elements: ['listings', 'listing']
Expand Down Expand Up @@ -167,12 +167,12 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__views_times_booking_value']
SELECT
subq_25.listing
, subq_25.views_times_booking_value
, subq_25.listing__views_times_booking_value
FROM (
-- Compute Metrics via Expressions
SELECT
subq_24.listing
, booking_value * views AS views_times_booking_value
, booking_value * views AS listing__views_times_booking_value
FROM (
-- Combine Aggregated Outputs
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['listings', 'listing__views_times_booking_value']
SELECT
subq_47.views_times_booking_value AS listing__views_times_booking_value
subq_47.listing__views_times_booking_value AS listing__views_times_booking_value
, subq_34.listings AS listings
FROM (
-- Read Elements From Semantic Model 'listings_latest'
Expand All @@ -24,7 +24,7 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__views_times_booking_value']
SELECT
listing
, booking_value * views AS views_times_booking_value
, booking_value * views AS listing__views_times_booking_value
FROM (
-- Combine Aggregated Outputs
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ FROM (
-- Join Standard Outputs
SELECT
subq_10.listing AS listing
, subq_16.bookings AS listing__bookings
, subq_22.bookers AS listing__bookers
, subq_16.listing__bookings AS listing__bookings
, subq_22.listing__bookers AS listing__bookers
, subq_10.listings AS listings
FROM (
-- Pass Only Elements: ['listings', 'listing', 'listing']
Expand Down Expand Up @@ -170,12 +170,12 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookings']
SELECT
subq_15.listing
, subq_15.bookings
, subq_15.listing__bookings
FROM (
-- Compute Metrics via Expressions
SELECT
subq_14.listing
, subq_14.bookings
, subq_14.bookings AS listing__bookings
FROM (
-- Aggregate Measures
SELECT
Expand Down Expand Up @@ -393,12 +393,12 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookers']
SELECT
subq_21.listing
, subq_21.bookers
, subq_21.listing__bookers
FROM (
-- Compute Metrics via Expressions
SELECT
subq_20.listing
, subq_20.bookers
, subq_20.bookers AS listing__bookers
FROM (
-- Aggregate Measures
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['listings', 'listing__bookings', 'listing__bookers']
SELECT
subq_36.bookings AS listing__bookings
, subq_42.bookers AS listing__bookers
subq_36.listing__bookings AS listing__bookings
, subq_42.listing__bookers AS listing__bookers
, subq_30.listings AS listings
FROM (
-- Read Elements From Semantic Model 'listings_latest'
Expand All @@ -26,7 +26,7 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookings']
SELECT
listing
, SUM(bookings) AS bookings
, SUM(bookings) AS listing__bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
Expand All @@ -50,7 +50,7 @@ FROM (
-- Pass Only Elements: ['listing', 'listing__bookers']
SELECT
listing_id AS listing
, COUNT(DISTINCT guest_id) AS bookers
, COUNT(DISTINCT guest_id) AS listing__bookers
FROM ***************************.fct_bookings bookings_source_src_28000
GROUP BY
listing_id
Expand Down
Loading

0 comments on commit a2bc7fd

Please sign in to comment.