From 8a40ff0389bac2225dbf93af24f36bf120416def Mon Sep 17 00:00:00 2001 From: Patrick Yost Date: Tue, 5 Nov 2024 15:59:34 -0800 Subject: [PATCH] DRAFT: Add tags to exports --- .../implementations/export.py | 3 ++- .../default_explicit_schema.json | 13 ++++++++++++ dbt_semantic_interfaces/parsing/schemas.py | 9 ++++++++ dbt_semantic_interfaces/protocols/export.py | 8 ++++++- tests/parsing/test_saved_query_parsing.py | 21 +++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/dbt_semantic_interfaces/implementations/export.py b/dbt_semantic_interfaces/implementations/export.py index 152613ce..d16b901d 100644 --- a/dbt_semantic_interfaces/implementations/export.py +++ b/dbt_semantic_interfaces/implementations/export.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Optional +from typing import List, Optional from typing_extensions import override @@ -31,6 +31,7 @@ def _implements_protocol(self) -> ExportConfig: export_as: ExportDestinationType schema_name: Optional[str] = Field(alias="schema", default=None) alias: Optional[str] = None + tags: Optional[List[str]] = Field(default_factory=list) class PydanticExport(HashableBaseModel, ProtocolHint[Export]): 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 613bffd7..ce7d6606 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 @@ -286,6 +286,19 @@ }, "schema": { "type": "string" + }, + "tags": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ] } }, "required": [ diff --git a/dbt_semantic_interfaces/parsing/schemas.py b/dbt_semantic_interfaces/parsing/schemas.py index 66652535..9dacbb6a 100644 --- a/dbt_semantic_interfaces/parsing/schemas.py +++ b/dbt_semantic_interfaces/parsing/schemas.py @@ -409,6 +409,15 @@ "export_as": {"enum": export_destination_type_values}, "schema": {"type": "string"}, "alias": {"type": "string"}, + "tags": { + "oneOf": [ + {"type": "string"}, + { + "type": "array", + "items": {"type": "string"}, + }, + ], + }, }, "required": ["export_as"], "additionalProperties": False, diff --git a/dbt_semantic_interfaces/protocols/export.py b/dbt_semantic_interfaces/protocols/export.py index 5c8fd5a4..25f5db83 100644 --- a/dbt_semantic_interfaces/protocols/export.py +++ b/dbt_semantic_interfaces/protocols/export.py @@ -1,7 +1,7 @@ from __future__ import annotations from abc import abstractmethod -from typing import Optional, Protocol +from typing import List, Optional, Protocol from dbt_semantic_interfaces.type_enums.export_destination_type import ( ExportDestinationType, @@ -42,3 +42,9 @@ def schema_name(self) -> Optional[str]: def alias(self) -> Optional[str]: """Name for table/filte export is written to. Defaults to export name.""" pass + + @property + @abstractmethod + def tags(self) -> Optional[List[str]]: + """List of tags to be used as part of resource selection in dbt.""" + pass diff --git a/tests/parsing/test_saved_query_parsing.py b/tests/parsing/test_saved_query_parsing.py index 20b8f4b3..1f46eed0 100644 --- a/tests/parsing/test_saved_query_parsing.py +++ b/tests/parsing/test_saved_query_parsing.py @@ -159,27 +159,48 @@ def test_saved_query_exports() -> None: export_as: VIEW schema: my_schema alias: my_view_name + tags: "tag_1" - name: test_exports2 config: export_as: table + tags: + - "tag_2_A" + - "tag_2_B" """ ) + # tags: "tag_1" + # tags: + # - "tag_2_B" + # - "tag_2_A" + + # - name: test_exports3 + # config: + # export_as: table + file = YamlConfigFile(filepath="inline_for_test", contents=yaml_contents) build_result = parse_yaml_files_to_semantic_manifest(files=[file, EXAMPLE_PROJECT_CONFIGURATION_YAML_CONFIG_FILE]) + print(build_result.issues) assert len(build_result.semantic_manifest.saved_queries) == 1 saved_query = build_result.semantic_manifest.saved_queries[0] assert saved_query.exports and len(saved_query.exports) == 2 names_to_exports = {export.name: export for export in saved_query.exports} assert set(names_to_exports.keys()) == {"test_exports1", "test_exports2"} + # assert set(names_to_exports.keys()) == {"test_exports1", "test_exports2", "test_exports3"} export1_config = names_to_exports["test_exports1"].config assert export1_config.export_as == ExportDestinationType.VIEW assert export1_config.schema_name == "my_schema" assert export1_config.alias == "my_view_name" + # assert export1_config.tags == ["tag_1"] export2_config = names_to_exports["test_exports2"].config assert export2_config.export_as == ExportDestinationType.TABLE assert export2_config.schema_name is None assert export2_config.alias is None + assert export2_config.tags == ["tag_2_A", "tag_2_B"] + + # export3_no_tags_config = names_to_exports["test_exports3"].config + # assert export2_config.export_as == ExportDestinationType.TABLE + # assert export3_no_tags_config.tags is None