-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use FULL OUTER JOIN for ratio metrics, too
- Loading branch information
1 parent
3e5e8c2
commit dbb8a2f
Showing
44 changed files
with
781 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 66 additions & 68 deletions
134
...gQuery/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,80 @@ | ||
-- Combine Metrics | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
COALESCE(subq_30.ds__day, subq_40.ds__day) AS ds__day | ||
, COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest) AS listing__country_latest | ||
, CAST(subq_30.bookings AS FLOAT64) / CAST(NULLIF(subq_40.views, 0) AS FLOAT64) AS bookings_per_view | ||
ds__day | ||
, listing__country_latest | ||
, CAST(bookings AS FLOAT64) / CAST(NULLIF(views, 0) AS FLOAT64) AS bookings_per_view | ||
FROM ( | ||
-- Join Standard Outputs | ||
-- Pass Only Elements: | ||
-- ['bookings', 'listing__country_latest', 'ds__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
-- Combine Metrics | ||
SELECT | ||
subq_23.ds__day AS ds__day | ||
, listings_latest_src_10004.country AS listing__country_latest | ||
, SUM(subq_23.bookings) AS bookings | ||
COALESCE(subq_30.ds__day, subq_40.ds__day) AS ds__day | ||
, COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest) AS listing__country_latest | ||
, MAX(subq_30.bookings) AS bookings | ||
, MAX(subq_40.views) AS views | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Join Standard Outputs | ||
-- Pass Only Elements: | ||
-- ['bookings', 'ds__day', 'listing'] | ||
-- ['bookings', 'listing__country_latest', 'ds__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, listing_id AS listing | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_10001 | ||
) subq_23 | ||
LEFT OUTER JOIN | ||
***************************.dim_listings_latest listings_latest_src_10004 | ||
ON | ||
subq_23.listing = listings_latest_src_10004.listing_id | ||
GROUP BY | ||
ds__day | ||
, listing__country_latest | ||
) subq_30 | ||
INNER JOIN ( | ||
-- Join Standard Outputs | ||
-- Pass Only Elements: | ||
-- ['views', 'listing__country_latest', 'ds__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
subq_33.ds__day AS ds__day | ||
, listings_latest_src_10004.country AS listing__country_latest | ||
, SUM(subq_33.views) AS views | ||
FROM ( | ||
-- Read Elements From Semantic Model 'views_source' | ||
-- Metric Time Dimension 'ds' | ||
subq_23.ds__day AS ds__day | ||
, listings_latest_src_10004.country AS listing__country_latest | ||
, SUM(subq_23.bookings) AS bookings | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['bookings', 'ds__day', 'listing'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, listing_id AS listing | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_10001 | ||
) subq_23 | ||
LEFT OUTER JOIN | ||
***************************.dim_listings_latest listings_latest_src_10004 | ||
ON | ||
subq_23.listing = listings_latest_src_10004.listing_id | ||
GROUP BY | ||
ds__day | ||
, listing__country_latest | ||
) subq_30 | ||
FULL OUTER JOIN ( | ||
-- Join Standard Outputs | ||
-- Pass Only Elements: | ||
-- ['views', 'ds__day', 'listing'] | ||
-- ['views', 'listing__country_latest', 'ds__day'] | ||
-- Aggregate Measures | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, listing_id AS listing | ||
, 1 AS views | ||
FROM ***************************.fct_views views_source_src_10009 | ||
) subq_33 | ||
LEFT OUTER JOIN | ||
***************************.dim_listings_latest listings_latest_src_10004 | ||
subq_33.ds__day AS ds__day | ||
, listings_latest_src_10004.country AS listing__country_latest | ||
, SUM(subq_33.views) AS views | ||
FROM ( | ||
-- Read Elements From Semantic Model 'views_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Pass Only Elements: | ||
-- ['views', 'ds__day', 'listing'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS ds__day | ||
, listing_id AS listing | ||
, 1 AS views | ||
FROM ***************************.fct_views views_source_src_10009 | ||
) subq_33 | ||
LEFT OUTER JOIN | ||
***************************.dim_listings_latest listings_latest_src_10004 | ||
ON | ||
subq_33.listing = listings_latest_src_10004.listing_id | ||
GROUP BY | ||
ds__day | ||
, listing__country_latest | ||
) subq_40 | ||
ON | ||
subq_33.listing = listings_latest_src_10004.listing_id | ||
GROUP BY | ||
ds__day | ||
, listing__country_latest | ||
) subq_40 | ||
ON | ||
( | ||
( | ||
subq_30.listing__country_latest = subq_40.listing__country_latest | ||
) OR ( | ||
( | ||
subq_30.listing__country_latest IS NULL | ||
) AND ( | ||
subq_40.listing__country_latest IS NULL | ||
) | ||
) | ||
) AND ( | ||
( | ||
) AND ( | ||
subq_30.ds__day = subq_40.ds__day | ||
) OR ( | ||
(subq_30.ds__day IS NULL) AND (subq_40.ds__day IS NULL) | ||
) | ||
) | ||
GROUP BY | ||
ds__day | ||
, listing__country_latest | ||
) subq_41 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.