Skip to content

Commit

Permalink
Add sub-daily TimeGranularity options (#281)
Browse files Browse the repository at this point in the history
Resolves #280

### Description
Add support for sub-day `TimeGranularity` options: hour, minute, second,
millisecond, microsecond, and nanosecond.

### Checklist

- [x] I have read [the contributing
guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md)
and understand what's expected of me
- [x] I have signed the
[CLA](https://docs.getdbt.com/docs/contributor-license-agreements)
- [x] This PR includes tests, or tests are not required/relevant for
this PR
- [x] I have run `changie new` to [create a changelog
entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry)
  • Loading branch information
courtneyholcomb authored May 31, 2024
1 parent 4127671 commit 881fd53
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

0 comments on commit 881fd53

Please sign in to comment.