-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exports config to YAML spec for saved queries (#190)
- Loading branch information
1 parent
099b916
commit d919c0c
Showing
13 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Add exports configuration to YAML spec. | ||
time: 2023-10-24T16:28:42.013032-07:00 | ||
custom: | ||
Author: courtneyholcomb | ||
Issue: "189" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import Field | ||
from typing_extensions import override | ||
|
||
from dbt_semantic_interfaces.implementations.base import HashableBaseModel | ||
from dbt_semantic_interfaces.protocols import ProtocolHint | ||
from dbt_semantic_interfaces.protocols.export import Export, ExportConfig | ||
from dbt_semantic_interfaces.type_enums.export_destination_type import ( | ||
ExportDestinationType, | ||
) | ||
|
||
|
||
class PydanticExportConfig(HashableBaseModel, ProtocolHint[ExportConfig]): | ||
"""Pydantic implementation of ExportConfig. | ||
Note on `schema_name`: `schema` is an existing BaseModel attribute, so we need to alias it here. | ||
`Field.alias="schema"` enables using the `schema` key in YAML. `Config.allow_population_by_field_name` | ||
enables parsing for both `schema` and `schema_name` when deserializing from JSON. | ||
""" | ||
|
||
class Config: # noqa: D | ||
allow_population_by_field_name = True | ||
|
||
@override | ||
def _implements_protocol(self) -> ExportConfig: | ||
return self | ||
|
||
export_as: ExportDestinationType | ||
schema_name: Optional[str] = Field(alias="schema", default=None) | ||
alias: Optional[str] = None | ||
|
||
|
||
class PydanticExport(HashableBaseModel, ProtocolHint[Export]): | ||
"""Pydantic implementation of Export.""" | ||
|
||
@override | ||
def _implements_protocol(self) -> Export: | ||
return self | ||
|
||
name: str | ||
config: PydanticExportConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
from abc import abstractmethod | ||
from typing import Optional, Protocol | ||
|
||
from dbt_semantic_interfaces.type_enums.export_destination_type import ( | ||
ExportDestinationType, | ||
) | ||
|
||
|
||
class Export(Protocol): | ||
"""Configuration for writing query results to a table.""" | ||
|
||
@property | ||
@abstractmethod | ||
def name(self) -> str: # noqa: D | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def config(self) -> ExportConfig: # noqa: D | ||
pass | ||
|
||
|
||
class ExportConfig(Protocol): | ||
"""Nested configuration attributes for exports.""" | ||
|
||
@property | ||
@abstractmethod | ||
def export_as(self) -> ExportDestinationType: | ||
"""Type of destination to write export to.""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def schema_name(self) -> Optional[str]: | ||
"""Schema to write export to. Defaults to deployment schema.""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def alias(self) -> Optional[str]: | ||
"""Name for table/filte export is written to. Defaults to export name.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
dbt_semantic_interfaces/type_enums/export_destination_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from dbt_semantic_interfaces.enum_extension import ExtendedEnum | ||
|
||
|
||
class ExportDestinationType(ExtendedEnum): | ||
"""Types of destinations that exports can be written to.""" | ||
|
||
TABLE = "table" | ||
VIEW = "view" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters