diff --git a/.changes/unreleased/Fixes-20231025-173704.yaml b/.changes/unreleased/Fixes-20231025-173704.yaml new file mode 100644 index 00000000..2b0f1216 --- /dev/null +++ b/.changes/unreleased/Fixes-20231025-173704.yaml @@ -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" diff --git a/dbt_semantic_interfaces/implementations/saved_query.py b/dbt_semantic_interfaces/implementations/saved_query.py index 4074c607..417daebc 100644 --- a/dbt_semantic_interfaces/implementations/saved_query.py +++ b/dbt_semantic_interfaces/implementations/saved_query.py @@ -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 diff --git a/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json b/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json index d689eea8..4a4b8100 100644 --- a/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json +++ b/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json @@ -477,7 +477,7 @@ }, "type": "array" }, - "group_bys": { + "group_by": { "items": { "type": "string" }, diff --git a/dbt_semantic_interfaces/parsing/schemas.py b/dbt_semantic_interfaces/parsing/schemas.py index 61f3e79e..5cc1f99a 100644 --- a/dbt_semantic_interfaces/parsing/schemas.py +++ b/dbt_semantic_interfaces/parsing/schemas.py @@ -326,7 +326,7 @@ "type": "array", "items": {"type": "string"}, }, - "group_bys": { + "group_by": { "type": "array", "items": {"type": "string"}, }, diff --git a/dbt_semantic_interfaces/protocols/saved_query.py b/dbt_semantic_interfaces/protocols/saved_query.py index f27eb0df..1ab086e6 100644 --- a/dbt_semantic_interfaces/protocols/saved_query.py +++ b/dbt_semantic_interfaces/protocols/saved_query.py @@ -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 diff --git a/dbt_semantic_interfaces/validations/saved_query.py b/dbt_semantic_interfaces/validations/saved_query.py index f9abd7f4..37fa20da 100644 --- a/dbt_semantic_interfaces/validations/saved_query.py +++ b/dbt_semantic_interfaces/validations/saved_query.py @@ -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: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml index 240cd30b..b5ec7e3c 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml @@ -5,7 +5,7 @@ saved_query: metrics: - bookings - instant_bookings - group_bys: + group_by: - TimeDimension('metric_time', 'DAY') - Dimension('listing__capacity_latest') where: diff --git a/tests/parsing/test_saved_query_parsing.py b/tests/parsing/test_saved_query_parsing.py index 4cd97e15..8f9013f4 100644 --- a/tests/parsing/test_saved_query_parsing.py +++ b/tests/parsing/test_saved_query_parsing.py @@ -89,7 +89,7 @@ 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( """\ @@ -97,9 +97,9 @@ def test_saved_query_group_bys() -> None: 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') """ ) @@ -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 ) diff --git a/tests/test_implements_satisfy_protocols.py b/tests/test_implements_satisfy_protocols.py index d59b0acf..c6d0fcd5 100644 --- a/tests/test_implements_satisfy_protocols.py +++ b/tests/test_implements_satisfy_protocols.py @@ -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, diff --git a/tests/validations/test_saved_query.py b/tests/validations/test_saved_query.py index 89ba8289..983b6ea3 100644 --- a/tests/validations/test_saved_query.py +++ b/tests/validations/test_saved_query.py @@ -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') }}")], ), @@ -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 }}")], ), @@ -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') }}")], ), @@ -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') }}")], ),