Skip to content
Open
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
4 changes: 4 additions & 0 deletions packages/gooddata-dbt/src/gooddata_dbt/dbt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ class GoodDataSortDirection(Enum):
"FISCAL_YEAR",
]
TIMESTAMP_GRANULARITIES = [
"SECOND",
"MINUTE",
"HOUR",
"SECOND_OF_MINUTE",
"SECOND_OF_DAY",
"MINUTE_OF_HOUR",
"MINUTE_OF_DAY",
"HOUR_OF_DAY",
]
T = TypeVar("T", bound="Base")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
"description": "All the supported granularities of the date attributes.",
"enum": [
"TIMESTAMP",
"SECOND",
"MINUTE",
"HOUR",
"DAY",
"WEEK",
"MONTH",
"QUARTER",
"YEAR",
"SECOND_OF_MINUTE",
"SECOND_OF_DAY",
"MINUTE_OF_HOUR",
"MINUTE_OF_DAY",
"HOUR_OF_DAY",
"DAY_OF_WEEK",
"DAY_OF_MONTH",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _get_date_converter_for_label(label_id: str, model_labels: dict):

- ``DAY`` / ``MONTH`` / ``YEAR`` → ``DateConverter`` (→ ``pandas.Timestamp`` via external fn)
- ``WEEK`` / ``QUARTER`` → ``StringConverter`` (no-op)
- ``MINUTE`` / ``HOUR`` → ``DatetimeConverter``
- ``SECOND`` / ``MINUTE`` / ``HOUR`` → ``DatetimeConverter``
- No granularity (text attrs) → ``None`` (caller skips conversion)
"""
info = model_labels.get(label_id, {})
Expand All @@ -84,6 +84,7 @@ def convert_label_values(label_id: str, values: list, model_labels: dict) -> lis
Mirrors the non-Arrow execution path (``AttributeConverterStore`` in ``_typed_attribute_value``):

- ``DAY`` / ``MONTH`` / ``YEAR`` granularity → ``pandas.Timestamp``
- ``SECOND`` / ``MINUTE`` / ``HOUR`` → ``pandas.Timestamp``
- ``WEEK`` / ``QUARTER`` → ``str`` (unchanged)
- No granularity (text attributes) → values returned as the **same object**

Expand Down
6 changes: 6 additions & 0 deletions packages/gooddata-pandas/tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def test_typed_attribute_values_batches_dates_to_timestamps():
pandas.Timestamp("2023-01-01"),
pandas.Timestamp("2023-03-01"),
]
assert _typed_attribute_values(
_date_catalog_attribute("SECOND"), ["2026-07-31 12:34:56", "2026-12-31 23:59:59"]
) == [
pandas.Timestamp("2026-07-31 12:34:56"),
pandas.Timestamp("2026-12-31 23:59:59"),
]


def test_typed_attribute_values_week_and_quarter_stay_strings():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ class LdmExtensionDataProcessor:
"""Create GoodData LDM from validated custom datasets and fields."""

DATE_GRANULARITIES: list[str] = [
"SECOND",
"MINUTE",
"HOUR",
"DAY",
"WEEK",
"MONTH",
"QUARTER",
"YEAR",
"SECOND_OF_MINUTE",
"SECOND_OF_DAY",
"MINUTE_OF_HOUR",
"MINUTE_OF_DAY",
"HOUR_OF_DAY",
"DAY_OF_WEEK",
"DAY_OF_MONTH",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def __eq__(self, other: object) -> bool:
"DAY",
"HOUR",
"MINUTE",
"SECOND",
"QUARTER_OF_YEAR",
"MONTH_OF_YEAR",
"WEEK_OF_YEAR",
Expand All @@ -272,6 +273,9 @@ def __eq__(self, other: object) -> bool:
"DAY_OF_WEEK",
"HOUR_OF_DAY",
"MINUTE_OF_HOUR",
"MINUTE_OF_DAY",
"SECOND_OF_DAY",
"SECOND_OF_MINUTE",
"FISCAL_MONTH",
"FISCAL_QUARTER",
"FISCAL_YEAR",
Expand Down
2 changes: 1 addition & 1 deletion packages/gooddata-sdk/src/gooddata_sdk/type_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def build_stores() -> None:
AttributeConverterStore.register("DATE", IntegerConverter)
AttributeConverterStore.register("DATE", StringConverter, ["WEEK", "QUARTER"])
AttributeConverterStore.register("DATE", DateConverter, ["DAY", "MONTH", "YEAR"])
AttributeConverterStore.register("DATE", DatetimeConverter, ["MINUTE", "HOUR"])
AttributeConverterStore.register("DATE", DatetimeConverter, ["SECOND", "MINUTE", "HOUR"])

DBTypeConverterStore.register("date", DateConverter)
DBTypeConverterStore.register("timestamp", DatetimeConverter)
Expand Down
4 changes: 4 additions & 0 deletions packages/gooddata-sdk/src/gooddata_sdk/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"GDC.time.date": "DAY",
"GDC.time.hour": "HOUR",
"GDC.time.minute": "MINUTE",
"GDC.time.second": "SECOND",
"GDC.time.quarter_in_year": "QUARTER_OF_YEAR",
"GDC.time.month_in_year": "MONTH_OF_YEAR",
"GDC.time.week_in_year": "WEEK_OF_YEAR",
Expand All @@ -57,6 +58,9 @@
"GDC.time.day_in_week": "DAY_OF_WEEK",
"GDC.time.hour_in_day": "HOUR_OF_DAY",
"GDC.time.minute_in_hour": "MINUTE_OF_HOUR",
"GDC.time.minute_in_day": "MINUTE_OF_DAY",
"GDC.time.second_in_day": "SECOND_OF_DAY",
"GDC.time.second_in_minute": "SECOND_OF_MINUTE",
"GDC.time.fiscal_month": "FISCAL_MONTH",
"GDC.time.fiscal_quarter": "FISCAL_QUARTER",
"GDC.time.fiscal_year": "FISCAL_YEAR",
Expand Down
37 changes: 37 additions & 0 deletions packages/gooddata-sdk/tests/compute_model/test_date_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,40 @@ def test_date_filters_description(scenario, filter, descriptions):
def test_all_time_date_filter_is_noop_by_default():
f = AllTimeDateFilter(dataset=ObjId(type="dataset", id="dataset.id"))
assert f.is_noop()


@pytest.mark.parametrize(
"granularity",
[
"YEAR",
"QUARTER",
"MONTH",
"WEEK",
"DAY",
"HOUR",
"MINUTE",
"SECOND",
"QUARTER_OF_YEAR",
"MONTH_OF_YEAR",
"WEEK_OF_YEAR",
"DAY_OF_YEAR",
"DAY_OF_MONTH",
"DAY_OF_WEEK",
"HOUR_OF_DAY",
"MINUTE_OF_HOUR",
"MINUTE_OF_DAY",
"SECOND_OF_DAY",
"SECOND_OF_MINUTE",
"FISCAL_MONTH",
"FISCAL_QUARTER",
"FISCAL_YEAR",
],
)
def test_relative_date_filter_accepts_all_supported_granularities(granularity):
f = RelativeDateFilter(
dataset=ObjId(type="dataset", id="dataset.id"),
granularity=granularity,
from_shift=-30,
to_shift=-1,
)
assert f.granularity == granularity
4 changes: 4 additions & 0 deletions packages/gooddata-sdk/tests/test_type_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def test_to_type_ok(self):
c = conv.DatetimeConverter()
assert c.to_type(test_value) == datetime.datetime(2021, 10, 20, 11, 0)

def test_second_granularity_values_convert_to_datetime(self):
c = conv.AttributeConverterStore.find_converter("DATE", "SECOND")
assert c.to_type("2026-07-31 12:34:56") == datetime.datetime(2026, 7, 31, 12, 34, 56)

def test_to_type_wrong_val(self):
test_value = "2021-10-20"
c = conv.DatetimeConverter()
Expand Down
Loading