Skip to content

Commit

Permalink
fixup! Add integration test for derived metrics with shared aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
serramatutu committed Nov 4, 2024
1 parent 8a7b603 commit 57e0611
Show file tree
Hide file tree
Showing 13 changed files with 3,127 additions and 4 deletions.
23 changes: 19 additions & 4 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,31 @@ integration_test:
) a
---
integration_test:
name: shared_alias_derived_metric
name: shared_alias_derived_metric_same
description: Tests derived metrics which use the same alias for the same thing
model: SIMPLE_MODEL
metrics: ["derived_shared_alias_1a", "derived_shared_alias_1b"]
group_bys: ["booking__is_instant"]
check_query: |
SELECT
is_instant AS booking__is_instant
, COUNT(*) - 10 AS derived_shared_alias_1a
, COUNT(*) - 100 AS derived_shared_alias_1b
FROM {{ source_schema }}.fct_bookings
GROUP BY
booking__is_instant
---
integration_test:
name: shared_alias_derived_metric_different
description: Tests derived metrics which use the same alias for different things
model: SIMPLE_MODEL
metrics: ["derived_sharedalias_1a", "derived_sharedalias_2"]
metrics: ["derived_shared_alias_1a", "derived_shared_alias_2"]
group_bys: ["booking__is_instant"]
check_query: |
SELECT
is_instant AS booking__is_instant
, COUNT(*) - 10 AS derived_sharedalias_1a
, SUM(CASE WHEN is_instant THEN 1 ELSE 0 END) + 10 AS derived_sharedalias_2
, COUNT(*) - 10 AS derived_shared_alias_1a
, SUM(CASE WHEN is_instant THEN 1 ELSE 0 END) + 10 AS derived_shared_alias_2
FROM {{ source_schema }}.fct_bookings
GROUP BY
booking__is_instant
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Combine Aggregated Outputs
-- Order By [] Limit 1
SELECT
COALESCE(subq_18.booking__is_instant, subq_24.booking__is_instant) AS booking__is_instant
, MAX(subq_18.derived_shared_alias_1a) AS derived_shared_alias_1a
, MAX(subq_24.derived_shared_alias_2) AS derived_shared_alias_2
FROM (
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, shared_alias - 10 AS derived_shared_alias_1a
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, SUM(bookings) AS shared_alias
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['bookings', 'booking__is_instant']
SELECT
is_instant AS booking__is_instant
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_15
GROUP BY
booking__is_instant
) subq_17
) subq_18
FULL OUTER JOIN (
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, shared_alias + 10 AS derived_shared_alias_2
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, SUM(instant_bookings) AS shared_alias
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['instant_bookings', 'booking__is_instant']
SELECT
is_instant AS booking__is_instant
, CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_21
GROUP BY
booking__is_instant
) subq_23
) subq_24
ON
subq_18.booking__is_instant = subq_24.booking__is_instant
GROUP BY
booking__is_instant
LIMIT 1

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Combine Aggregated Outputs
-- Order By [] Limit 1
SELECT
COALESCE(subq_18.booking__is_instant, subq_24.booking__is_instant) AS booking__is_instant
, MAX(subq_18.derived_shared_alias_1a) AS derived_shared_alias_1a
, MAX(subq_24.derived_shared_alias_2) AS derived_shared_alias_2
FROM (
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, shared_alias - 10 AS derived_shared_alias_1a
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, SUM(bookings) AS shared_alias
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['bookings', 'booking__is_instant']
SELECT
is_instant AS booking__is_instant
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_15
GROUP BY
booking__is_instant
) subq_17
) subq_18
FULL OUTER JOIN (
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, shared_alias + 10 AS derived_shared_alias_2
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
booking__is_instant
, SUM(instant_bookings) AS shared_alias
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['instant_bookings', 'booking__is_instant']
SELECT
is_instant AS booking__is_instant
, CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_21
GROUP BY
booking__is_instant
) subq_23
) subq_24
ON
subq_18.booking__is_instant = subq_24.booking__is_instant
GROUP BY
COALESCE(subq_18.booking__is_instant, subq_24.booking__is_instant)
LIMIT 1
Loading

0 comments on commit 57e0611

Please sign in to comment.