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

ADAP-608: Finalize Materialized Views #527

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
new relation/materialization first draft
  • Loading branch information
mikealfare committed Jul 11, 2023
commit 9cc18b5f43c123aa1a08af469090fcf937be0d1e
18 changes: 17 additions & 1 deletion dbt/adapters/redshift/impl.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from collections import namedtuple
from dataclasses import dataclass
from typing import Optional, Set, Any, Dict, Type
from collections import namedtuple

from dbt.adapters.base import PythonJobHelper
from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport
from dbt.adapters.base.meta import available
from dbt.adapters.relation.factory import RelationFactory
from dbt.adapters.sql import SQLAdapter
from dbt.contracts.connection import AdapterResponse
from dbt.contracts.graph.nodes import ConstraintType
from dbt.contracts.relation import RelationType
from dbt.events import AdapterLogger
import dbt.exceptions

from dbt.adapters.redshift import RedshiftConnectionManager, RedshiftRelation
from dbt.adapters.redshift.relation import models as relation_models


logger = AdapterLogger("Redshift")
Expand Down Expand Up @@ -45,6 +48,19 @@ class RedshiftAdapter(SQLAdapter):
ConstraintType.foreign_key: ConstraintSupport.NOT_ENFORCED,
}

@property
def relation_factory(self):
return RelationFactory(
relation_models={
RelationType.MaterializedView: relation_models.RedshiftMaterializedViewRelation,
},
relation_changesets={
RelationType.MaterializedView: relation_models.RedshiftMaterializedViewRelationChangeset,
},
relation_can_be_renamed={RelationType.MaterializedView},
render_policy=relation_models.RedshiftRenderPolicy,
)

@classmethod
def date_function(cls):
return "getdate()"
Expand Down
19 changes: 0 additions & 19 deletions dbt/adapters/redshift/materialization_config/__init__.py

This file was deleted.

70 changes: 0 additions & 70 deletions dbt/adapters/redshift/materialization_config/base.py

This file was deleted.

58 changes: 0 additions & 58 deletions dbt/adapters/redshift/materialization_config/database.py

This file was deleted.

19 changes: 0 additions & 19 deletions dbt/adapters/redshift/materialization_config/policy.py

This file was deleted.

105 changes: 0 additions & 105 deletions dbt/adapters/redshift/relation.py

This file was deleted.

12 changes: 12 additions & 0 deletions dbt/adapters/redshift/relation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dbt.adapters.redshift.relation.models.database import RedshiftDatabaseRelation
from dbt.adapters.redshift.relation.models.dist import RedshiftDistRelation
from dbt.adapters.redshift.relation.models.materialized_view import (
RedshiftMaterializedViewRelation,
RedshiftMaterializedViewRelationChangeset,
)
from dbt.adapters.redshift.relation.models.policy import (
RedshiftRenderPolicy,
MAX_CHARACTERS_IN_IDENTIFIER,
)
from dbt.adapters.redshift.relation.models.schema import RedshiftSchemaRelation
from dbt.adapters.redshift.relation.models.sort import RedshiftSortRelation
42 changes: 42 additions & 0 deletions dbt/adapters/redshift/relation/models/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from dataclasses import dataclass
from typing import Set

from dbt.adapters.relation.models import DatabaseRelation
from dbt.adapters.validation import ValidationMixin, ValidationRule
from dbt.exceptions import DbtRuntimeError

from dbt.adapters.redshift.relation.models.policy import RedshiftRenderPolicy


@dataclass(frozen=True, eq=True, unsafe_hash=True)
class RedshiftDatabaseRelation(DatabaseRelation, ValidationMixin):
"""
This config follow the specs found here:
https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_DATABASE.html

The following parameters are configurable by dbt:
- name: name of the database
"""

# attribution
name: str

# configuration
render = RedshiftRenderPolicy

@property
def validation_rules(self) -> Set[ValidationRule]:
return {
ValidationRule(
validation_check=len(self.name or "") > 0,
validation_error=DbtRuntimeError(
f"dbt-redshift requires a name for a database, received: {self.name}"
),
)
}

@classmethod
def from_dict(cls, config_dict) -> "RedshiftDatabaseRelation":
database = super().from_dict(config_dict)
assert isinstance(database, RedshiftDatabaseRelation)
return database
Loading