Compare commits

...

3 Commits

Author SHA1 Message Date
Wojtek
14aba033a6 Fix docs generating for cross-db sources (#2)
Co-authored-by: kostkaw <wojciech.kostka@contractors.roche.com>
2021-06-02 00:19:25 +02:00
Wojtek
ef69ca4761 Merge pull request #1 from kostek-pl/fix/cross_db_docs_generation
Fix docs generating for cross-db sources
2021-05-31 14:28:01 +02:00
kostkaw
03162946dc Fix docs generating for cross-db sources 2021-05-31 14:21:08 +02:00
4 changed files with 39 additions and 7 deletions

View File

@@ -433,13 +433,14 @@ class SchemaSearchMap(Dict[InformationSchema, Set[Optional[str]]]):
for schema in schemas:
yield information_schema_name, schema
def flatten(self):
def flatten(self, allow_multiple_databases: bool=False):
new = self.__class__()
# make sure we don't have duplicates
seen = {r.database.lower() for r in self if r.database}
if len(seen) > 1:
dbt.exceptions.raise_compiler_error(str(seen))
# make sure we don't have multiple databases if allow_multiple_databases is set to False
if not allow_multiple_databases:
seen = {r.database.lower() for r in self if r.database}
if len(seen) > 1:
dbt.exceptions.raise_compiler_error(str(seen))
for information_schema_name, schema in self.search():
path = {

View File

@@ -112,7 +112,7 @@ class PostgresAdapter(SQLAdapter):
self.cache.add_link(referenced, dependent)
def _get_catalog_schemas(self, manifest):
# postgres/redshift only allow one database (the main one)
# postgres only allow one database (the main one)
schemas = super()._get_catalog_schemas(manifest)
try:
return schemas.flatten()

View File

@@ -49,6 +49,7 @@ class RedshiftCredentials(PostgresCredentials):
keepalives_idle: int = 240
autocreate: bool = False
db_groups: List[str] = field(default_factory=list)
ra3_node: Optional[bool] = False
@property
def type(self):

View File

@@ -1,11 +1,14 @@
from dataclasses import dataclass
from typing import Optional
from dbt.adapters.base.impl import AdapterConfig
from dbt.adapters.sql import SQLAdapter
from dbt.adapters.base.meta import available
from dbt.adapters.postgres import PostgresAdapter
from dbt.adapters.redshift import RedshiftConnectionManager
from dbt.adapters.redshift import RedshiftColumn
from dbt.adapters.redshift import RedshiftRelation
from dbt.logger import GLOBAL_LOGGER as logger # noqa
import dbt.exceptions
@dataclass
@@ -16,7 +19,7 @@ class RedshiftConfig(AdapterConfig):
bind: Optional[bool] = None
class RedshiftAdapter(PostgresAdapter):
class RedshiftAdapter(PostgresAdapter, SQLAdapter):
Relation = RedshiftRelation
ConnectionManager = RedshiftConnectionManager
Column = RedshiftColumn
@@ -57,3 +60,30 @@ class RedshiftAdapter(PostgresAdapter):
@classmethod
def convert_time_type(cls, agate_table, col_idx):
return "varchar(24)"
@available
def verify_database(self, database):
if database.startswith('"'):
database = database.strip('"')
expected = self.config.credentials.database
ra3_node = self.config.credentials.ra3_node
if database.lower() != expected.lower() and not ra3_node:
raise dbt.exceptions.NotImplementedException(
'Cross-db references allowed only in RA3.* node. ({} vs {})'
.format(database, expected)
)
# return an empty string on success so macros can call this
return ''
def _get_catalog_schemas(self, manifest):
# redshift(besides ra3) only allow one database (the main one)
schemas = super(SQLAdapter, self)._get_catalog_schemas(manifest)
try:
return schemas.flatten(allow_multiple_databases=self.config.credentials.ra3_node)
except dbt.exceptions.RuntimeException as exc:
dbt.exceptions.raise_compiler_error(
'Cross-db references not allowed in adapter {}: Got {}'.format(
self.type(), exc.msg
)
)