Skip to content

Commit

Permalink
Added relation and supporting files (#144)
Browse files Browse the repository at this point in the history
Co-authored-by: nrodriguezmicrofocus <[email protected]>
Co-authored-by: nrodriguezmicrofocus <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent f5fe707 commit 030f1d6
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions dbt/adapters/vertica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions dbt/adapters/vertica/relation.py
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


13 changes: 13 additions & 0 deletions dbt/adapters/vertica/relation_configs/__init__.py
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",
]
25 changes: 25 additions & 0 deletions dbt/adapters/vertica/relation_configs/policies.py
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

0 comments on commit 030f1d6

Please sign in to comment.