Skip to content

Commit

Permalink
Update SqlWindowFunction enum (#1266)
Browse files Browse the repository at this point in the history
Update `SqlWindowFunction` enum in a few ways:
- Add `AVERAGE` & `LAST_VALUE` for cumulative metrics with non-default
granularities.
- Remove `ROW_NUMBER` since it isn't used anywhere.
- Update values to be uppercase for consistency with our other SQL
rendering practices.

All snapshot updates are just upper-casing from `first_value` to
`FIRST_VALUE`.
  • Loading branch information
courtneyholcomb authored Jun 12, 2024
1 parent c04f343 commit 59f40d5
Show file tree
Hide file tree
Showing 170 changed files with 710 additions and 709 deletions.
5 changes: 3 additions & 2 deletions metricflow/sql/sql_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,9 @@ class SqlWindowFunction(Enum):
Values are the SQL string to be used in rendering.
"""

FIRST_VALUE = "first_value"
ROW_NUMBER = "row_number"
FIRST_VALUE = "FIRST_VALUE"
LAST_VALUE = "LAST_VALUE"
AVERAGE = "AVG"


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,31 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_7.visits) OVER (
FIRST_VALUE(subq_7.visits) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_7.ds__day) OVER (
, FIRST_VALUE(subq_7.ds__day) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_7.metric_time__day) OVER (
, FIRST_VALUE(subq_7.metric_time__day) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_7.user) OVER (
, FIRST_VALUE(subq_7.user) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_23.visits) OVER (
FIRST_VALUE(subq_23.visits) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_23.ds__day) OVER (
, FIRST_VALUE(subq_23.ds__day) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_23.metric_time__day) OVER (
, FIRST_VALUE(subq_23.metric_time__day) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_23.user) OVER (
, FIRST_VALUE(subq_23.user) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,39 +139,39 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_7.visits) OVER (
FIRST_VALUE(subq_7.visits) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_7.visit__referrer_id) OVER (
, FIRST_VALUE(subq_7.visit__referrer_id) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, first_value(subq_7.ds__day) OVER (
, FIRST_VALUE(subq_7.ds__day) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_7.metric_time__day) OVER (
, FIRST_VALUE(subq_7.metric_time__day) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_7.user) OVER (
, FIRST_VALUE(subq_7.user) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,39 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_23.visits) OVER (
FIRST_VALUE(subq_23.visits) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_23.visit__referrer_id) OVER (
, FIRST_VALUE(subq_23.visit__referrer_id) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, first_value(subq_23.ds__day) OVER (
, FIRST_VALUE(subq_23.ds__day) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_23.metric_time__day) OVER (
, FIRST_VALUE(subq_23.metric_time__day) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_23.user) OVER (
, FIRST_VALUE(subq_23.user) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,31 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_13.visits) OVER (
FIRST_VALUE(subq_13.visits) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_13.visit__referrer_id) OVER (
, FIRST_VALUE(subq_13.visit__referrer_id) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, first_value(subq_13.ds__day) OVER (
, FIRST_VALUE(subq_13.ds__day) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_13.user) OVER (
, FIRST_VALUE(subq_13.user) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_31.visits) OVER (
FIRST_VALUE(subq_31.visits) OVER (
PARTITION BY
subq_34.user
, subq_34.ds__day
, subq_34.mf_internal_uuid
ORDER BY subq_31.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_31.visit__referrer_id) OVER (
, FIRST_VALUE(subq_31.visit__referrer_id) OVER (
PARTITION BY
subq_34.user
, subq_34.ds__day
, subq_34.mf_internal_uuid
ORDER BY subq_31.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, first_value(subq_31.ds__day) OVER (
, FIRST_VALUE(subq_31.ds__day) OVER (
PARTITION BY
subq_34.user
, subq_34.ds__day
, subq_34.mf_internal_uuid
ORDER BY subq_31.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_31.user) OVER (
, FIRST_VALUE(subq_31.user) OVER (
PARTITION BY
subq_34.user
, subq_34.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,31 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_7.visits) OVER (
FIRST_VALUE(subq_7.visits) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_7.ds__day) OVER (
, FIRST_VALUE(subq_7.ds__day) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_7.metric_time__day) OVER (
, FIRST_VALUE(subq_7.metric_time__day) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
, subq_10.mf_internal_uuid
ORDER BY subq_7.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_7.user) OVER (
, FIRST_VALUE(subq_7.user) OVER (
PARTITION BY
subq_10.user
, subq_10.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_23.visits) OVER (
FIRST_VALUE(subq_23.visits) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_23.ds__day) OVER (
, FIRST_VALUE(subq_23.ds__day) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_23.metric_time__day) OVER (
, FIRST_VALUE(subq_23.metric_time__day) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
, subq_26.mf_internal_uuid
ORDER BY subq_23.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_23.user) OVER (
, FIRST_VALUE(subq_23.user) OVER (
PARTITION BY
subq_26.user
, subq_26.ds__day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,39 +185,39 @@ FROM (
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
first_value(subq_13.visits) OVER (
FIRST_VALUE(subq_13.visits) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, first_value(subq_13.visit__referrer_id) OVER (
, FIRST_VALUE(subq_13.visit__referrer_id) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, first_value(subq_13.ds__day) OVER (
, FIRST_VALUE(subq_13.ds__day) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, first_value(subq_13.metric_time__day) OVER (
, FIRST_VALUE(subq_13.metric_time__day) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
, subq_16.mf_internal_uuid
ORDER BY subq_13.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS metric_time__day
, first_value(subq_13.user) OVER (
, FIRST_VALUE(subq_13.user) OVER (
PARTITION BY
subq_16.user
, subq_16.ds__day
Expand Down
Loading

0 comments on commit 59f40d5

Please sign in to comment.