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

DRAFT: Add tags to exports #364

Closed
wants to merge 1 commit into from
Closed
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
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
22 changes: 22 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,49 @@ 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
Loading