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

Add sub-daily TimeGranularity options #281

Merged
merged 2 commits into from
May 31, 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240531-145904.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Add sub-daily TimeGranularity options.
time: 2024-05-31T14:59:04.804239-07:00
custom:
Author: courtneyholcomb
Issue: "280"
2 changes: 1 addition & 1 deletion dbt_semantic_interfaces/naming/dundered.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse_name(name: str) -> StructuredDunderedName:
def dundered_name(self) -> str:
"""Return the full name form. e.g. ds or listing__ds__month."""
items = [entity_reference.element_name for entity_reference in self.entity_links] + [self.element_name]
if self.time_granularity and self.time_granularity != TimeGranularity.DAY:
if self.time_granularity:
items.append(self.time_granularity.value)
return DUNDER.join(items)

Expand Down
18 changes: 18 additions & 0 deletions dbt_semantic_interfaces/type_enums/time_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class TimeGranularity(ExtendedEnum):

# Names are used in parameters to DATE_TRUNC, so don't change them.
# Values are used to convert user supplied strings to enums.
NANOSECOND = "nanosecond"
MICROSECOND = "microsecond"
MILLISECOND = "millisecond"
SECOND = "second"
MINUTE = "minute"
HOUR = "hour"
DAY = "day"
WEEK = "week"
MONTH = "month"
Expand All @@ -21,6 +27,18 @@ class TimeGranularity(ExtendedEnum):

def to_int(self) -> int:
"""Convert to an int so that the size of the granularity can be easily compared."""
if self is TimeGranularity.NANOSECOND:
return 4
elif self is TimeGranularity.MICROSECOND:
return 5
elif self is TimeGranularity.MILLISECOND:
return 6
elif self is TimeGranularity.SECOND:
return 7
elif self is TimeGranularity.MINUTE:
return 8
elif self is TimeGranularity.HOUR:
return 9
if self is TimeGranularity.DAY:
return 10
elif self is TimeGranularity.WEEK:
Expand Down
Loading