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

Rename SavedQuery.group_bys to SavedQuery.group_by #186

Merged
merged 1 commit into from
Oct 26, 2023
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/Fixes-20231025-173704.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Rename `SavedQuery.group_bys` to `SavedQuery.group_by`
time: 2023-10-25T17:37:04.840909-07:00
custom:
Author: plypaul
Issue: "192"
2 changes: 1 addition & 1 deletion dbt_semantic_interfaces/implementations/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _implements_protocol(self) -> SavedQuery:

name: str
metrics: List[str]
group_bys: List[str] = []
group_by: List[str] = []
where: Optional[PydanticWhereFilterIntersection] = None

description: Optional[str] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@
},
"type": "array"
},
"group_bys": {
"group_by": {
"items": {
"type": "string"
},
Expand Down
2 changes: 1 addition & 1 deletion dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
"type": "array",
"items": {"type": "string"},
},
"group_bys": {
"group_by": {
"type": "array",
"items": {"type": "string"},
},
Expand Down
2 changes: 1 addition & 1 deletion dbt_semantic_interfaces/protocols/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def metrics(self) -> Sequence[str]: # noqa: D

@property
@abstractmethod
def group_bys(self) -> Sequence[str]: # noqa: D
def group_by(self) -> Sequence[str]: # noqa: D
pass

@property
Expand Down
2 changes: 1 addition & 1 deletion dbt_semantic_interfaces/validations/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SavedQueryRule(SemanticManifestValidationRule[SemanticManifestT], Generic[
def _check_group_bys(valid_group_by_element_names: Set[str], saved_query: SavedQuery) -> Sequence[ValidationIssue]:
issues: List[ValidationIssue] = []

for group_by_item in saved_query.group_bys:
for group_by_item in saved_query.group_by:
# TODO: Replace with more appropriate abstractions once available.
parameter_sets: FilterCallParameterSets
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ saved_query:
metrics:
- bookings
- instant_bookings
group_bys:
group_by:
- TimeDimension('metric_time', 'DAY')
- Dimension('listing__capacity_latest')
where:
Expand Down
14 changes: 7 additions & 7 deletions tests/parsing/test_saved_query_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ def test_saved_query_metrics_parsing() -> None:
assert {"test_metric_a", "test_metric_b", "test_metric_c"} == set(saved_query.metrics)


def test_saved_query_group_bys() -> None:
def test_saved_query_group_by() -> None:
"""Test for parsing group_bys in a saved query."""
yaml_contents = textwrap.dedent(
"""\
saved_query:
name: test_saved_query_group_bys
metrics:
- test_metric_a
group_bys:
- Dimension(test_entity__test_dimension_a)
- Dimension(test_entity__test_dimension_b)
group_by:
- Dimension('test_entity__test_dimension_a')
- Dimension('test_entity__test_dimension_b')

"""
)
Expand All @@ -109,9 +109,9 @@ def test_saved_query_group_bys() -> None:

assert len(build_result.semantic_manifest.saved_queries) == 1
saved_query = build_result.semantic_manifest.saved_queries[0]
assert len(saved_query.group_bys) == 2
assert {"Dimension(test_entity__test_dimension_a)", "Dimension(test_entity__test_dimension_b)"} == set(
saved_query.group_bys
assert len(saved_query.group_by) == 2
assert {"Dimension('test_entity__test_dimension_a')", "Dimension('test_entity__test_dimension_b')"} == set(
saved_query.group_by
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_implements_satisfy_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

SAVED_QUERY_STRATEGY = builds(
PydanticSavedQuery,
group_bys=from_type(List[str]),
group_by=from_type(List[str]),
where=from_type(List[PydanticWhereFilter]),
description=OPTIONAL_STR_STRATEGY,
metadata=OPTIONAL_METADATA_STRATEGY,
Expand Down
8 changes: 4 additions & 4 deletions tests/validations/test_saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_invalid_metric_in_saved_query( # noqa: D
name="Example Saved Query",
description="Example description.",
metrics=["invalid_metric"],
group_bys=["Dimension('booking__is_instant')"],
group_by=["Dimension('booking__is_instant')"],
where=PydanticWhereFilterIntersection(
where_filters=[PydanticWhereFilter(where_sql_template="{{ Dimension('booking__is_instant') }}")],
),
Expand All @@ -66,7 +66,7 @@ def test_invalid_where_in_saved_query( # noqa: D
name="Example Saved Query",
description="Example description.",
metrics=["bookings"],
group_bys=["Dimension('booking__is_instant')"],
group_by=["Dimension('booking__is_instant')"],
where=PydanticWhereFilterIntersection(
where_filters=[PydanticWhereFilter(where_sql_template="{{ invalid_jinja }}")],
),
Expand All @@ -89,7 +89,7 @@ def test_invalid_group_by_element_in_saved_query( # noqa: D
name="Example Saved Query",
description="Example description.",
metrics=["bookings"],
group_bys=["Dimension('booking__invalid_dimension')"],
group_by=["Dimension('booking__invalid_dimension')"],
where=PydanticWhereFilterIntersection(
where_filters=[PydanticWhereFilter(where_sql_template="{{ Dimension('booking__is_instant') }}")],
),
Expand All @@ -112,7 +112,7 @@ def test_invalid_group_by_format_in_saved_query( # noqa: D
name="Example Saved Query",
description="Example description.",
metrics=["bookings"],
group_bys=["invalid_format"],
group_by=["invalid_format"],
where=PydanticWhereFilterIntersection(
where_filters=[PydanticWhereFilter(where_sql_template="{{ Dimension('booking__is_instant') }}")],
),
Expand Down
Loading