-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added relation and supporting files (#144)
Co-authored-by: nrodriguezmicrofocus <[email protected]> Co-authored-by: nrodriguezmicrofocus <[email protected]>
- Loading branch information
1 parent
f5fe707
commit 030f1d6
Showing
4 changed files
with
95 additions
and
0 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
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,56 @@ | ||
from dataclasses import dataclass, field | ||
from typing import FrozenSet, List, Optional | ||
|
||
from dbt.adapters.base.relation import BaseRelation | ||
from dbt.adapters.contracts.relation import RelationConfig, RelationType | ||
from dbt.adapters.relation_configs import ( | ||
RelationConfigChangeAction, | ||
RelationResults, | ||
) | ||
from dbt_common.exceptions import DbtRuntimeError | ||
|
||
from dbt.adapters.vertica.relation_configs.policies import ( | ||
MAX_CHARACTERS_IN_IDENTIFIER, | ||
) | ||
|
||
|
||
@dataclass(frozen=True, eq=False, repr=False) | ||
class VerticaRelation(BaseRelation): | ||
quote_character: str = '"' | ||
require_alias: bool = ( | ||
False # used to govern whether to add an alias when render_limited is called | ||
) | ||
renameable_relations: FrozenSet[RelationType] = field( | ||
default_factory=lambda: frozenset( | ||
{ | ||
RelationType.View, | ||
RelationType.Table, | ||
} | ||
) | ||
) | ||
replaceable_relations: FrozenSet[RelationType] = field( | ||
default_factory=lambda: frozenset( | ||
{ | ||
RelationType.View, | ||
RelationType.Table, | ||
} | ||
) | ||
) | ||
|
||
def __post_init__(self): | ||
# Check for length of Postgres table/view names. | ||
# Check self.type to exclude test relation identifiers | ||
if ( | ||
self.identifier is not None | ||
and self.type is not None | ||
and len(self.identifier) > self.relation_max_name_length() | ||
): | ||
raise DbtRuntimeError( | ||
f"Relation name '{self.identifier}' " | ||
f"is longer than {self.relation_max_name_length()} characters" | ||
) | ||
|
||
def relation_max_name_length(self): | ||
return MAX_CHARACTERS_IN_IDENTIFIER | ||
|
||
|
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,13 @@ | ||
from dbt.adapters.vertica.relation_configs.policies import ( | ||
MAX_CHARACTERS_IN_IDENTIFIER, | ||
VerticaIncludePolicy, | ||
VerticaQuotePolicy, | ||
VerticaRelationType, | ||
) | ||
|
||
__all__ = [ | ||
"MAX_CHARACTERS_IN_IDENTIFIER", | ||
"VerticaIncludePolicy", | ||
"VerticaQuotePolicy", | ||
"VerticaRelationType", | ||
] |
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,25 @@ | ||
from dataclasses import dataclass | ||
|
||
from dbt.adapters.contracts.relation import Policy | ||
from dbt_common.dataclass_schema import StrEnum | ||
|
||
MAX_CHARACTERS_IN_IDENTIFIER = 127 | ||
|
||
|
||
class VerticaRelationType(StrEnum): | ||
Table = "table" | ||
View = "view" | ||
CTE = "cte" | ||
|
||
|
||
class VerticaIncludePolicy(Policy): | ||
database: bool = True | ||
schema: bool = True | ||
identifier: bool = True | ||
|
||
|
||
@dataclass | ||
class VerticaQuotePolicy(Policy): | ||
database: bool = True | ||
schema: bool = True | ||
identifier: bool = True |