Skip to content

Fix TimeDimension in group_by #82

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

Merged
merged 1 commit into from
Apr 15, 2025
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixes-20250414-204039.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixes
body: Fix TimeDimension in group_by
time: 2025-04-14T20:40:39.754768-05:00
2 changes: 2 additions & 0 deletions dbtsl/api/adbc/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def _serialize_val(cls, val: Any) -> str:
g = f'Dimension("{val.name}")'
elif val.type == GroupByType.ENTITY:
g = f'Entity("{val.name}")'
else: # val.type == GroupByType.TIME_DIMENSION
return f'TimeDimension("{val.name}", "{val.grain}")'
if val.grain:
grain_str = val.grain.lower()
g += f'.grain("{grain_str}")'
Expand Down
1 change: 1 addition & 0 deletions dbtsl/api/shared/query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class GroupByType(Enum):
"""The type of a group_by, i.e a dimension or an entity."""

DIMENSION = "dimension"
TIME_DIMENSION = "time_dimension"
ENTITY = "entity"


Expand Down
15 changes: 15 additions & 0 deletions tests/api/adbc/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ def test_serialize_val_OrderByGroupBy() -> None:
)


def test_serialize_time_dimension_group_by() -> None:
assert (
ADBCProtocol._serialize_val(
GroupByParam(name="time_dim", type=GroupByType.TIME_DIMENSION, grain="month"),
)
== 'TimeDimension("time_dim", "month")'
)
assert (
ADBCProtocol._serialize_val(
GroupByParam(name="time_dim", type=GroupByType.TIME_DIMENSION, grain="week"),
)
== 'TimeDimension("time_dim", "week")'
)


def test_serialize_query_params_metrics() -> None:
params = ADBCProtocol._serialize_params_dict({"metrics": ["a", "b"]}, ["metrics"])

Expand Down