From 9d011fe494e3e1b30a285f09f10be61f90cc27a1 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 23 Oct 2023 23:56:42 -0700 Subject: [PATCH] Rename `group_bys` field in SavedQueries to `group_by`. In the Github issue describing the saved query feature (#765), there was a typo in the field name. --- .../implementations/saved_query.py | 2 +- .../default_explicit_schema.json | 2 +- dbt_semantic_interfaces/parsing/schemas.py | 2 +- dbt_semantic_interfaces/protocols/saved_query.py | 2 +- dbt_semantic_interfaces/validations/saved_query.py | 2 +- .../simple_semantic_manifest/saved_queries.yaml | 2 +- tests/parsing/test_saved_query_parsing.py | 14 +++++++------- tests/test_implements_satisfy_protocols.py | 2 +- tests/validations/test_saved_query.py | 8 ++++---- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/dbt_semantic_interfaces/implementations/saved_query.py b/dbt_semantic_interfaces/implementations/saved_query.py index 53de5038..eda2ac7b 100644 --- a/dbt_semantic_interfaces/implementations/saved_query.py +++ b/dbt_semantic_interfaces/implementations/saved_query.py @@ -25,7 +25,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 7d0c3253..7082c684 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 @@ -430,7 +430,7 @@ "description": { "type": "string" }, - "group_bys": { + "group_by": { "items": { "type": "string" }, diff --git a/dbt_semantic_interfaces/parsing/schemas.py b/dbt_semantic_interfaces/parsing/schemas.py index 9144c2b2..9e9a218a 100644 --- a/dbt_semantic_interfaces/parsing/schemas.py +++ b/dbt_semantic_interfaces/parsing/schemas.py @@ -299,7 +299,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 3bd739d9..875db092 100644 --- a/dbt_semantic_interfaces/protocols/saved_query.py +++ b/dbt_semantic_interfaces/protocols/saved_query.py @@ -30,7 +30,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 e822550f..2ec290d0 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 95b0e6aa..2a367d7d 100644 --- a/tests/parsing/test_saved_query_parsing.py +++ b/tests/parsing/test_saved_query_parsing.py @@ -86,7 +86,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( """\ @@ -94,9 +94,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') """ ) @@ -106,9 +106,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 6bc1a6e3..c04a0a51 100644 --- a/tests/test_implements_satisfy_protocols.py +++ b/tests/test_implements_satisfy_protocols.py @@ -119,7 +119,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') }}")], ),