Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SqlWindowFunction enum #1266

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to include this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part? The uppercasing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last_value enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes! Sorry forgot to include in the PR description! Will also be used for non-default granularities with cumulative metrics. We could use FIRST_VALUE and order desc, but I decided this was more readable because it aligns with the YAML argument names (which are first/last).

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
Loading