-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for date_part for Dimension & TimeDimension (#183)
This PR adds support for the date_part for Dimension & TimeDimension. This is helpful for our Tableau integration. A time_dimension_call_parameter_set is now created if Dimension(...).grain(...) or Dimension(...).date_part(...) is used or both.
- Loading branch information
1 parent
a00ee84
commit 4c98d80
Showing
8 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Support for date_part for Dimension & TimeDimension | ||
time: 2023-10-24T17:10:20.59653-05:00 | ||
custom: | ||
Author: DevonFulcher | ||
Issue: "188" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from enum import Enum | ||
from typing import List | ||
|
||
from dbt_semantic_interfaces.enum_extension import assert_values_exhausted | ||
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity | ||
|
||
|
||
class DatePart(Enum): | ||
"""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 | ||
TODO: add support for hour, minute, second once those granularities are available | ||
""" | ||
|
||
YEAR = "year" | ||
QUARTER = "quarter" | ||
MONTH = "month" | ||
DAY = "day" | ||
DOW = "dow" | ||
DOY = "doy" | ||
|
||
def to_int(self) -> int: | ||
"""Convert to an int so that the size of the granularity can be easily compared.""" | ||
if self is DatePart.DAY: | ||
return TimeGranularity.DAY.to_int() | ||
elif self is DatePart.DOW: | ||
return TimeGranularity.DAY.to_int() | ||
elif self is DatePart.DOY: | ||
return TimeGranularity.DAY.to_int() | ||
elif self is DatePart.MONTH: | ||
return TimeGranularity.MONTH.to_int() | ||
elif self is DatePart.QUARTER: | ||
return TimeGranularity.QUARTER.to_int() | ||
elif self is DatePart.YEAR: | ||
return TimeGranularity.YEAR.to_int() | ||
else: | ||
assert_values_exhausted(self) | ||
|
||
@property | ||
def compatible_granularities(self) -> List[TimeGranularity]: | ||
"""Granularities that can be queried with this date part.""" | ||
return [granularity for granularity in TimeGranularity if granularity.to_int() >= self.to_int()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters