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

Made DatePart an ExtendedEnum #207

Merged
merged 1 commit into from
Nov 8, 2023
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231107-175844.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: made DatePart an ExtendedEnum
time: 2023-11-07T17:58:44.412914-06:00
custom:
Author: DevonFulcher
Issue: None
22 changes: 18 additions & 4 deletions dbt_semantic_interfaces/type_enums/date_part.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
from enum import Enum
from typing import List

from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
from dbt_semantic_interfaces.enum_extension import ExtendedEnum, assert_values_exhausted
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity


class DatePart(Enum):
class DatePart(ExtendedEnum):
"""Date parts able to be extracted from a time dimension.

Week is not an option due to divergent results across engine contexts see: https://github.com/dbt-labs/metricflow/pull/812
Note this does not support WEEK (aka WEEKOFYEAR), because week numbering is very strange.
The ISO spec calls for weeks to start on Monday. Fair enough. It also calls for years to
start on Monday, but only about 1 out of every 7 do. In order to ensure years start on
Monday, the ISO decided that the first day of any given year is the Monday of the week
containing the first Thursday of that year. Consequently, the ISO standard produces
weeks numbered 1-53, but any days belonging to the preceding calendar year but in the
first week of the new year are part of the new ISO year. This is not really what people
expect.

But there's more - different SQL engines also have different implementations of week of year.
When not using ISO, you get either 0-53, 1-54, or 1-53 with different ways of deciding
how to count the first few days in any given year. As such, we just don't support this.

When the time comes, we can support week using whatever standard makes the most sense for
our usage context, but as it is not clear what that standard looks like we simply don't
support date_part = week for now.

TODO: add support for hour, minute, second once those granularities are available
"""
Expand Down
Loading