-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for JoinConversionEventsNode
- Loading branch information
1 parent
7e53e74
commit e0e4546
Showing
8 changed files
with
521 additions
and
0 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
30 changes: 30 additions & 0 deletions
30
metricflow/test/fixtures/model_yamls/simple_model/data_sources/buys_source.yaml
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
data_source: | ||
name: buys_source | ||
description: buys_source | ||
owners: | ||
- [email protected] | ||
|
||
sql_query: | | ||
-- User Defined SQL Query | ||
SELECT * FROM $buys_source_table | ||
measures: | ||
- name: buys | ||
expr: 1 | ||
agg: count | ||
- name: buyers | ||
expr: user_id | ||
agg: count_distinct | ||
|
||
dimensions: | ||
- name: ds | ||
type: time | ||
type_params: | ||
is_primary: True | ||
time_granularity: day | ||
|
||
identifiers: | ||
- name: user | ||
type: foreign | ||
expr: user_id |
33 changes: 33 additions & 0 deletions
33
metricflow/test/fixtures/model_yamls/simple_model/data_sources/visits_source.yaml
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
data_source: | ||
name: visits_source | ||
description: visits_source | ||
owners: | ||
- [email protected] | ||
|
||
sql_query: | | ||
-- User Defined SQL Query | ||
SELECT * FROM $visits_source_table | ||
measures: | ||
- name: visits | ||
expr: 1 | ||
agg: count | ||
- name: visitors | ||
expr: user_id | ||
agg: count_distinct | ||
|
||
|
||
dimensions: | ||
- name: ds | ||
type: time | ||
type_params: | ||
is_primary: True | ||
time_granularity: day | ||
- name: referrer_id | ||
type: categorical | ||
|
||
identifiers: | ||
- name: user | ||
type: foreign | ||
expr: user_id |
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
76 changes: 76 additions & 0 deletions
76
...w_to_sql_plan.py/SqlQueryPlan/DuckDbSqlClient/test_join_conversion_events_node__plan0.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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
-- Find conversions for IdentifierSpec(element_name='user', identifier_links=()) within the range of 7 day | ||
SELECT DISTINCT | ||
subq_5.ds AS ds | ||
, subq_5.ds__week AS ds__week | ||
, subq_5.ds__month AS ds__month | ||
, subq_5.ds__quarter AS ds__quarter | ||
, subq_5.ds__year AS ds__year | ||
, subq_5.user AS user | ||
, subq_5.auto_gen_primary_key AS auto_gen_primary_key | ||
, subq_5.buys AS buys | ||
, subq_5.buyers AS buyers | ||
, first_value(subq_3.visits) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS visits | ||
, first_value(subq_3.visitors) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS visitors | ||
, first_value(subq_3.referrer_id) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS referrer_id | ||
, first_value(subq_3.ds) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS ds | ||
, first_value(subq_3.ds__week) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS ds__week | ||
, first_value(subq_3.ds__month) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS ds__month | ||
, first_value(subq_3.ds__quarter) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS ds__quarter | ||
, first_value(subq_3.ds__year) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS ds__year | ||
, first_value(subq_3.user) OVER (PARTITION BY subq_5.user, subq_5.ds ORDER BY subq_3.ds DESC) AS user | ||
FROM ( | ||
-- Read Elements From Data Source 'visits_source' | ||
SELECT | ||
1 AS visits | ||
, visits_source_src_10011.user_id AS visitors | ||
, visits_source_src_10011.ds | ||
, DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week | ||
, DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month | ||
, DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter | ||
, DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year | ||
, visits_source_src_10011.referrer_id | ||
, visits_source_src_10011.user_id AS user | ||
FROM ( | ||
-- User Defined SQL Query | ||
SELECT * FROM ***************************.fct_visits | ||
) visits_source_src_10011 | ||
) subq_3 | ||
INNER JOIN ( | ||
-- Append row number column | ||
SELECT | ||
subq_4.ds | ||
, subq_4.ds__week | ||
, subq_4.ds__month | ||
, subq_4.ds__quarter | ||
, subq_4.ds__year | ||
, subq_4.user | ||
, subq_4.buys | ||
, subq_4.buyers | ||
, row_number() OVER (ORDER BY subq_4.buys, subq_4.buyers, subq_4.ds, subq_4.ds__week, subq_4.ds__month, subq_4.ds__quarter, subq_4.ds__year, subq_4.user) AS auto_gen_primary_key | ||
FROM ( | ||
-- Read Elements From Data Source 'buys_source' | ||
SELECT | ||
1 AS buys | ||
, buys_source_src_10002.user_id AS buyers | ||
, buys_source_src_10002.ds | ||
, DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week | ||
, DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month | ||
, DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter | ||
, DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year | ||
, buys_source_src_10002.user_id AS user | ||
FROM ( | ||
-- User Defined SQL Query | ||
SELECT * FROM ***************************.fct_buys | ||
) buys_source_src_10002 | ||
) subq_4 | ||
) subq_5 | ||
ON | ||
( | ||
subq_3.user = subq_5.user | ||
) AND ( | ||
( | ||
subq_3.ds <= subq_5.ds | ||
) AND ( | ||
subq_3.ds > subq_5.ds - INTERVAL 7 day | ||
) | ||
) |
65 changes: 65 additions & 0 deletions
65
...lan.py/SqlQueryPlan/DuckDbSqlClient/test_join_conversion_events_node__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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
-- Find conversions for IdentifierSpec(element_name='user', identifier_links=()) within the range of 7 day | ||
SELECT | ||
subq_8.ds AS ds | ||
, subq_8.ds__week AS ds__week | ||
, subq_8.ds__month AS ds__month | ||
, subq_8.ds__quarter AS ds__quarter | ||
, subq_8.ds__year AS ds__year | ||
, subq_8.user AS user | ||
, subq_8.auto_gen_primary_key AS auto_gen_primary_key | ||
, subq_8.buys AS buys | ||
, subq_8.buyers AS buyers | ||
, first_value(subq_6.visits) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS visits | ||
, first_value(subq_6.visitors) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS visitors | ||
, first_value(subq_6.referrer_id) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS referrer_id | ||
, first_value(subq_6.ds) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS ds | ||
, first_value(subq_6.ds__week) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS ds__week | ||
, first_value(subq_6.ds__month) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS ds__month | ||
, first_value(subq_6.ds__quarter) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS ds__quarter | ||
, first_value(subq_6.ds__year) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS ds__year | ||
, first_value(subq_6.user) OVER (PARTITION BY subq_8.user, subq_8.ds ORDER BY subq_6.ds DESC) AS user | ||
FROM ( | ||
-- Read Elements From Data Source 'visits_source' | ||
SELECT | ||
1 AS visits | ||
, user_id AS visitors | ||
, ds | ||
, DATE_TRUNC('week', ds) AS ds__week | ||
, DATE_TRUNC('month', ds) AS ds__month | ||
, DATE_TRUNC('quarter', ds) AS ds__quarter | ||
, DATE_TRUNC('year', ds) AS ds__year | ||
, referrer_id | ||
, user_id AS user | ||
FROM ( | ||
-- User Defined SQL Query | ||
SELECT * FROM ***************************.fct_visits | ||
) visits_source_src_10011 | ||
) subq_6 | ||
INNER JOIN ( | ||
-- Read Elements From Data Source 'buys_source' | ||
-- Append row number column | ||
SELECT | ||
ds | ||
, DATE_TRUNC('week', ds) AS ds__week | ||
, DATE_TRUNC('month', ds) AS ds__month | ||
, DATE_TRUNC('quarter', ds) AS ds__quarter | ||
, DATE_TRUNC('year', ds) AS ds__year | ||
, user_id AS user | ||
, 1 AS buys | ||
, user_id AS buyers | ||
, row_number() OVER (ORDER BY 1, user_id, ds, DATE_TRUNC('week', ds), DATE_TRUNC('month', ds), DATE_TRUNC('quarter', ds), DATE_TRUNC('year', ds)) AS auto_gen_primary_key | ||
FROM ( | ||
-- User Defined SQL Query | ||
SELECT * FROM ***************************.fct_buys | ||
) buys_source_src_10002 | ||
) subq_8 | ||
ON | ||
( | ||
subq_6.user = subq_8.user | ||
) AND ( | ||
( | ||
subq_6.ds <= subq_8.ds | ||
) AND ( | ||
subq_6.ds > subq_8.ds - INTERVAL 7 day | ||
) | ||
) |
Oops, something went wrong.