Skip to content

Commit

Permalink
Remove support for date_part week from extract expression
Browse files Browse the repository at this point in the history
Support for date_part `week` is fraught with peril, as there is
no good standard way of extracting a week number from a date.

Because we hew to the calendar standard for date_part `year`
(as opposed to using ISO year, which defines the year start as
the Monday of the week containing the first Thursday in January)
it would be odd to use ISO week of year, which is based on the
ISO year. However, no other standard exists, and so we simply
remove the property from the enum and thereby drop support for
it. We can add it later and apply a well-defined behavior to it,
if necessary.

For more details on the mayhem please refer to the docblock
changes for the DatePart enum that accompany this commit.
  • Loading branch information
tlento committed Oct 16, 2023
1 parent 78a006e commit e56c816
Show file tree
Hide file tree
Showing 454 changed files with 21,498 additions and 31,792 deletions.
2 changes: 0 additions & 2 deletions metricflow/sql/render/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ def render_date_part(self, date_part: DatePart) -> str:
return "dayofyear"
if date_part == DatePart.DOW:
return "dayofweek"
if date_part == DatePart.WEEK:
return "isoweek"

return super().render_date_part(date_part)

Expand Down
3 changes: 0 additions & 3 deletions metricflow/test/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,6 @@ integration_test:
{"name": "metric_time", "date_part": "dow"},
{"name": "metric_time", "date_part": "doy"},
{"name": "metric_time", "date_part": "day"},
{"name": "metric_time", "date_part": "week"},
]
check_query: |
SELECT
Expand All @@ -1076,14 +1075,12 @@ integration_test:
, {{ render_extract("ds", DatePart.DOW) }} AS metric_time__extract_dow
, {{ render_extract("ds", DatePart.DOY) }} AS metric_time__extract_doy
, {{ render_extract("ds", DatePart.DAY) }} AS metric_time__extract_day
, {{ render_extract("ds", DatePart.WEEK) }} AS metric_time__extract_week
FROM {{ source_schema }}.fct_bookings
GROUP BY
{{ render_extract("ds", DatePart.QUARTER) }}
, {{ render_extract("ds", DatePart.DOW) }}
, {{ render_extract("ds", DatePart.DOY) }}
, {{ render_extract("ds", DatePart.DAY) }}
, {{ render_extract("ds", DatePart.WEEK) }};
---
integration_test:
name: derived_metric_offset_window_and_date_part
Expand Down
4 changes: 2 additions & 2 deletions metricflow/test/model/test_data_warehouse_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def test_build_dimension_tasks( # noqa: D
)
# on semantic model query with all dimensions
assert len(tasks) == 1
# 1 categorical dimension task, 1 time dimension task, 4 granularity based time dimension tasks, 7 date_part tasks
assert len(tasks[0].on_fail_subtasks) == 13
# 1 categorical dimension task, 1 time dimension task, 4 granularity based time dimension tasks, 6 date_part tasks
assert len(tasks[0].on_fail_subtasks) == 12


def test_validate_dimensions( # noqa: D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,6 @@ def test_simple_query_with_multiple_date_parts( # noqa: D
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.DAY),
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.DOW),
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.DOY),
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.WEEK),
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.MONTH),
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.QUARTER),
DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY, date_part=DatePart.YEAR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month
, EXTRACT(isoweek FROM revenue_src_10006.created_at) AS ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day
, EXTRACT(dayofweek FROM revenue_src_10006.created_at) AS ds__extract_dow
, EXTRACT(dayofyear FROM revenue_src_10006.created_at) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month
, EXTRACT(isoweek FROM revenue_src_10006.created_at) AS company__ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day
, EXTRACT(dayofweek FROM revenue_src_10006.created_at) AS company__ds__extract_dow
, EXTRACT(dayofyear FROM revenue_src_10006.created_at) AS company__ds__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month
, EXTRACT(isoweek FROM id_verifications_src_10003.ds) AS ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day
, EXTRACT(dayofweek FROM id_verifications_src_10003.ds) AS ds__extract_dow
, EXTRACT(dayofyear FROM id_verifications_src_10003.ds) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month
, EXTRACT(isoweek FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day
, EXTRACT(dayofweek FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow
, EXTRACT(dayofyear FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy
Expand All @@ -34,7 +32,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month
, EXTRACT(isoweek FROM id_verifications_src_10003.ds) AS verification__ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day
, EXTRACT(dayofweek FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow
, EXTRACT(dayofyear FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy
Expand All @@ -46,7 +43,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month
, EXTRACT(isoweek FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day
, EXTRACT(dayofweek FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow
, EXTRACT(dayofyear FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SELECT
, EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year
, EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter
, EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month
, EXTRACT(isoweek FROM users_latest_src_10008.ds) AS ds_latest__extract_week
, EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day
, EXTRACT(dayofweek FROM users_latest_src_10008.ds) AS ds_latest__extract_dow
, EXTRACT(dayofyear FROM users_latest_src_10008.ds) AS ds_latest__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year
, EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter
, EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month
, EXTRACT(isoweek FROM users_latest_src_10008.ds) AS user__ds_latest__extract_week
, EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day
, EXTRACT(dayofweek FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow
, EXTRACT(dayofyear FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month
, EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day
, EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow
, EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month
, EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day
, EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow
, EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds) AS ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds) AS ds__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy
Expand All @@ -34,7 +32,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds) AS verification__ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy
Expand All @@ -46,7 +43,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SELECT
, EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year
, EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter
, EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month
, EXTRACT(week FROM users_latest_src_10008.ds) AS ds_latest__extract_week
, EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day
, EXTRACT(dow FROM users_latest_src_10008.ds) AS ds_latest__extract_dow
, EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year
, EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter
, EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month
, EXTRACT(week FROM users_latest_src_10008.ds) AS user__ds_latest__extract_week
, EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day
, EXTRACT(dow FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow
, EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month
, EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day
, EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow
, EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month
, EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day
, EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow
, EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds) AS ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS ds__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds) AS ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS ds__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds) AS ds__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS ds_partitioned__extract_doy
Expand All @@ -34,7 +32,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds) AS verification__ds__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds) AS verification__ds__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds) AS verification__ds__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds) AS verification__ds__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds) AS verification__ds__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds) AS verification__ds__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds) AS verification__ds__extract_doy
Expand All @@ -46,7 +43,6 @@ SELECT
, EXTRACT(year FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_year
, EXTRACT(quarter FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_quarter
, EXTRACT(month FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_month
, EXTRACT(week FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_week
, EXTRACT(day FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_day
, EXTRACT(dow FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_dow
, EXTRACT(doy FROM id_verifications_src_10003.ds_partitioned) AS verification__ds_partitioned__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ SELECT
, EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year
, EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter
, EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month
, EXTRACT(week FROM users_latest_src_10008.ds) AS ds_latest__extract_week
, EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day
, EXTRACT(dow FROM users_latest_src_10008.ds) AS ds_latest__extract_dow
, EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year
, EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter
, EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month
, EXTRACT(week FROM users_latest_src_10008.ds) AS user__ds_latest__extract_week
, EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day
, EXTRACT(dow FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow
, EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS ds__extract_month
, EXTRACT(week FROM revenue_src_10006.created_at) AS ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS ds__extract_day
, EXTRACT(dow FROM revenue_src_10006.created_at) AS ds__extract_dow
, EXTRACT(doy FROM revenue_src_10006.created_at) AS ds__extract_doy
Expand All @@ -21,7 +20,6 @@ SELECT
, EXTRACT(year FROM revenue_src_10006.created_at) AS company__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10006.created_at) AS company__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10006.created_at) AS company__ds__extract_month
, EXTRACT(week FROM revenue_src_10006.created_at) AS company__ds__extract_week
, EXTRACT(day FROM revenue_src_10006.created_at) AS company__ds__extract_day
, EXTRACT(dow FROM revenue_src_10006.created_at) AS company__ds__extract_dow
, EXTRACT(doy FROM revenue_src_10006.created_at) AS company__ds__extract_doy
Expand Down
Loading

0 comments on commit e56c816

Please sign in to comment.