Skip to content

Commit

Permalink
DRAFT: Add tags to exports
Browse files Browse the repository at this point in the history
  • Loading branch information
theyostalservice committed Nov 5, 2024
1 parent 98b5af5 commit 8a40ff0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dbt_semantic_interfaces/implementations/export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Optional
from typing import List, Optional

from typing_extensions import override

Expand Down Expand Up @@ -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]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@
},
"schema": {
"type": "string"
},
"tags": {
"oneOf": [
{
"type": "string"
},
{
"items": {
"type": "string"
},
"type": "array"
}
]
}
},
"required": [
Expand Down
9 changes: 9 additions & 0 deletions dbt_semantic_interfaces/parsing/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion dbt_semantic_interfaces/protocols/export.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
21 changes: 21 additions & 0 deletions tests/parsing/test_saved_query_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8a40ff0

Please sign in to comment.