Skip to content

Commit

Permalink
Update snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Nov 13, 2024
1 parent 9e7c791 commit a2dbbd9
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
test_name: test_cte_for_shared_metrics
test_filename: test_cte_sql.py
docstring:
Check common branches in a query that uses derived metrics defined from metrics that are also in the query.
---
sql_without_cte:
-- Combine Aggregated Outputs
SELECT
COALESCE(subq_8.metric_time__day, subq_17.metric_time__day, subq_36.metric_time__day) AS metric_time__day
, COALESCE(subq_8.listing__country_latest, subq_17.listing__country_latest, subq_36.listing__country_latest) AS listing__country_latest
, MAX(subq_8.bookings) AS bookings
, MAX(subq_17.views) AS views
, MAX(CAST(subq_36.bookings AS DOUBLE) / CAST(NULLIF(subq_36.views, 0) AS DOUBLE)) AS bookings_per_view
FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_1.metric_time__day AS metric_time__day
, listings_latest_src_28000.country AS listing__country_latest
, SUM(subq_1.bookings) AS bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, listing_id AS listing
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_1
LEFT OUTER JOIN
***************************.dim_listings_latest listings_latest_src_28000
ON
subq_1.listing = listings_latest_src_28000.listing_id
GROUP BY
subq_1.metric_time__day
, listings_latest_src_28000.country
) subq_8
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['views', 'listing__country_latest', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_10.metric_time__day AS metric_time__day
, listings_latest_src_28000.country AS listing__country_latest
, SUM(subq_10.views) AS views
FROM (
-- Read Elements From Semantic Model 'views_source'
-- Metric Time Dimension 'ds'
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, listing_id AS listing
, 1 AS views
FROM ***************************.fct_views views_source_src_28000
) subq_10
LEFT OUTER JOIN
***************************.dim_listings_latest listings_latest_src_28000
ON
subq_10.listing = listings_latest_src_28000.listing_id
GROUP BY
subq_10.metric_time__day
, listings_latest_src_28000.country
) subq_17
ON
(
subq_8.listing__country_latest = subq_17.listing__country_latest
) AND (
subq_8.metric_time__day = subq_17.metric_time__day
)
FULL OUTER JOIN (
-- Combine Aggregated Outputs
SELECT
COALESCE(subq_26.metric_time__day, subq_35.metric_time__day) AS metric_time__day
, COALESCE(subq_26.listing__country_latest, subq_35.listing__country_latest) AS listing__country_latest
, MAX(subq_26.bookings) AS bookings
, MAX(subq_35.views) AS views
FROM (
-- Join Standard Outputs
-- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_19.metric_time__day AS metric_time__day
, listings_latest_src_28000.country AS listing__country_latest
, SUM(subq_19.bookings) AS bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, listing_id AS listing
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_19
LEFT OUTER JOIN
***************************.dim_listings_latest listings_latest_src_28000
ON
subq_19.listing = listings_latest_src_28000.listing_id
GROUP BY
subq_19.metric_time__day
, listings_latest_src_28000.country
) subq_26
FULL OUTER JOIN (
-- Join Standard Outputs
-- Pass Only Elements: ['views', 'listing__country_latest', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_28.metric_time__day AS metric_time__day
, listings_latest_src_28000.country AS listing__country_latest
, SUM(subq_28.views) AS views
FROM (
-- Read Elements From Semantic Model 'views_source'
-- Metric Time Dimension 'ds'
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, listing_id AS listing
, 1 AS views
FROM ***************************.fct_views views_source_src_28000
) subq_28
LEFT OUTER JOIN
***************************.dim_listings_latest listings_latest_src_28000
ON
subq_28.listing = listings_latest_src_28000.listing_id
GROUP BY
subq_28.metric_time__day
, listings_latest_src_28000.country
) subq_35
ON
(
subq_26.listing__country_latest = subq_35.listing__country_latest
) AND (
subq_26.metric_time__day = subq_35.metric_time__day
)
GROUP BY
COALESCE(subq_26.metric_time__day, subq_35.metric_time__day)
, COALESCE(subq_26.listing__country_latest, subq_35.listing__country_latest)
) subq_36
ON
(
COALESCE(subq_8.listing__country_latest, subq_17.listing__country_latest) = subq_36.listing__country_latest
) AND (
COALESCE(subq_8.metric_time__day, subq_17.metric_time__day) = subq_36.metric_time__day
)
GROUP BY
COALESCE(subq_8.metric_time__day, subq_17.metric_time__day, subq_36.metric_time__day)
, COALESCE(subq_8.listing__country_latest, subq_17.listing__country_latest, subq_36.listing__country_latest)


sql_with_cte:
-- Combine Aggregated Outputs
WITH cm_0_cte AS (
-- Join Standard Outputs
-- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_39.metric_time__day AS metric_time__day
, listings_latest_src_28000.country AS listing__country_latest
, SUM(subq_39.bookings) AS bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, listing_id AS listing
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_39
LEFT OUTER JOIN
***************************.dim_listings_latest listings_latest_src_28000
ON
subq_39.listing = listings_latest_src_28000.listing_id
GROUP BY
subq_39.metric_time__day
, listings_latest_src_28000.country
)

, cm_1_cte AS (
-- Join Standard Outputs
-- Pass Only Elements: ['views', 'listing__country_latest', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_48.metric_time__day AS metric_time__day
, listings_latest_src_28000.country AS listing__country_latest
, SUM(subq_48.views) AS views
FROM (
-- Read Elements From Semantic Model 'views_source'
-- Metric Time Dimension 'ds'
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, listing_id AS listing
, 1 AS views
FROM ***************************.fct_views views_source_src_28000
) subq_48
LEFT OUTER JOIN
***************************.dim_listings_latest listings_latest_src_28000
ON
subq_48.listing = listings_latest_src_28000.listing_id
GROUP BY
subq_48.metric_time__day
, listings_latest_src_28000.country
)

SELECT
COALESCE(cm_0_cte.metric_time__day, cm_1_cte.metric_time__day, subq_58.metric_time__day) AS metric_time__day
, COALESCE(cm_0_cte.listing__country_latest, cm_1_cte.listing__country_latest, subq_58.listing__country_latest) AS listing__country_latest
, MAX(cm_0_cte.bookings) AS bookings
, MAX(cm_1_cte.views) AS views
, MAX(CAST(subq_58.bookings AS DOUBLE) / CAST(NULLIF(subq_58.views, 0) AS DOUBLE)) AS bookings_per_view
FROM cm_0_cte cm_0_cte
FULL OUTER JOIN
cm_1_cte cm_1_cte
ON
(
cm_0_cte.listing__country_latest = cm_1_cte.listing__country_latest
) AND (
cm_0_cte.metric_time__day = cm_1_cte.metric_time__day
)
FULL OUTER JOIN (
-- Combine Aggregated Outputs
SELECT
COALESCE(cm_0_cte.metric_time__day, cm_1_cte.metric_time__day) AS metric_time__day
, COALESCE(cm_0_cte.listing__country_latest, cm_1_cte.listing__country_latest) AS listing__country_latest
, MAX(cm_0_cte.bookings) AS bookings
, MAX(cm_1_cte.views) AS views
FROM cm_0_cte cm_0_cte
FULL OUTER JOIN
cm_1_cte cm_1_cte
ON
(
cm_0_cte.listing__country_latest = cm_1_cte.listing__country_latest
) AND (
cm_0_cte.metric_time__day = cm_1_cte.metric_time__day
)
GROUP BY
COALESCE(cm_0_cte.metric_time__day, cm_1_cte.metric_time__day)
, COALESCE(cm_0_cte.listing__country_latest, cm_1_cte.listing__country_latest)
) subq_58
ON
(
COALESCE(cm_0_cte.listing__country_latest, cm_1_cte.listing__country_latest) = subq_58.listing__country_latest
) AND (
COALESCE(cm_0_cte.metric_time__day, cm_1_cte.metric_time__day) = subq_58.metric_time__day
)
GROUP BY
COALESCE(cm_0_cte.metric_time__day, cm_1_cte.metric_time__day, subq_58.metric_time__day)
, COALESCE(cm_0_cte.listing__country_latest, cm_1_cte.listing__country_latest, subq_58.listing__country_latest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test_name: test_cte_for_simple_dataflow_plan
test_filename: test_cte_sql.py
docstring:
Test a simple case for generating a CTE for a specific dataflow plan node.
---
sql_without_cte:
-- Read Elements From Semantic Model 'bookings_source'
-- Pass Only Elements: ['bookings',]
SELECT
1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000


sql_with_cte:
-- Read From CTE For node_id=rss_28001
-- Pass Only Elements: ['bookings',]
WITH rss_28001_cte AS (
-- Read Elements From Semantic Model 'bookings_source'
SELECT
1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
)

SELECT
bookings AS bookings
FROM rss_28001_cte rss_28001_cte

0 comments on commit a2dbbd9

Please sign in to comment.