diff --git a/dbt/adapters/vertica/__init__.py b/dbt/adapters/vertica/__init__.py index 69d8740..a82155a 100644 --- a/dbt/adapters/vertica/__init__.py +++ b/dbt/adapters/vertica/__init__.py @@ -17,6 +17,7 @@ from dbt.adapters.vertica.connections import verticaCredentials from dbt.adapters.vertica.impl import verticaAdapter from dbt.adapters.vertica.column import VerticaColumn +from dbt.adapters.vertica.relation import VerticaRelation from dbt.adapters.base import AdapterPlugin diff --git a/dbt/adapters/vertica/relation.py b/dbt/adapters/vertica/relation.py new file mode 100644 index 0000000..a8bdc07 --- /dev/null +++ b/dbt/adapters/vertica/relation.py @@ -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 + + \ No newline at end of file diff --git a/dbt/adapters/vertica/relation_configs/__init__.py b/dbt/adapters/vertica/relation_configs/__init__.py new file mode 100644 index 0000000..f1385dd --- /dev/null +++ b/dbt/adapters/vertica/relation_configs/__init__.py @@ -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", +] \ No newline at end of file diff --git a/dbt/adapters/vertica/relation_configs/policies.py b/dbt/adapters/vertica/relation_configs/policies.py new file mode 100644 index 0000000..af2edab --- /dev/null +++ b/dbt/adapters/vertica/relation_configs/policies.py @@ -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 \ No newline at end of file