Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/local-fix' into fix-drop-relatio…
Browse files Browse the repository at this point in the history
…n-oracle-19c
  • Loading branch information
Thomas Sapelza committed May 10, 2022
2 parents 9f729ee + 45e6b0d commit de6af15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
30 changes: 13 additions & 17 deletions dbt/adapters/oracle/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class OracleAdapterCredentials(Credentials):
of parameters profiled in the profile.
"""
# Mandatory required arguments.
user: str
password: str
# Database will always be None or must be the same as schema
# as the database name (userenv DB_NAME) is not needed when initiating a connection
user: Optional[str] = None
password: Optional[str] = None
# Database is not needed when initiating an Oracle DB connecting
database: Optional[str] = None
schema: Optional[str] = None

# OracleConnectionMethod.TNS
tns_name: Optional[str] = None
Expand All @@ -68,7 +68,6 @@ class OracleAdapterCredentials(Credentials):
host: Optional[str] = None
port: Optional[Port] = None
service: Optional[str] = None
schema: Optional[str] = None

# OracleConnectionMethod.CONNECTION_STRING
connection_string: Optional[str] = None
Expand All @@ -81,11 +80,19 @@ class OracleAdapterCredentials(Credentials):
cclass: Optional[str] = None
purity: Optional[str] = None


_ALIASES = {
'pass': 'password',
}

def __post_init__(self):
# In Oracle the userenv DB_NAME (database) is not needed when initiating a connection
if self.database is not None:
raise dbt.exceptions.RuntimeException(
f' database: {self.database} \n'
f'With Oracle DB the database property must not be set'
)
self.database = None

@property
def type(self):
return 'oracle'
Expand All @@ -94,17 +101,6 @@ def type(self):
def unique_field(self):
return self.user

def __post_init__(self):
# In Oracle the userenv DB_NAME (database) is not needed when initiating a connection
if self.database is not None and self.database != self.schema:
raise dbt.exceptions.RuntimeException(
f' schema: {self.schema} \n'
f' database: {self.database} \n'
f'On Oracle, database must be omitted or have the same value as'
f' schema.'
)
self.database = None

def _connection_keys(self) -> Tuple[str]:
"""
List of keys to display in the `dbt debug` output. Omit password.
Expand Down
13 changes: 4 additions & 9 deletions dbt/adapters/oracle/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import dbt.exceptions
from dataclasses import dataclass

from dbt.adapters.base.relation import BaseRelation, Policy
Expand All @@ -39,20 +40,14 @@ class OracleRelation(BaseRelation):
quote_policy: OracleQuotePolicy = OracleQuotePolicy()
include_policy: OracleIncludePolicy = OracleIncludePolicy()

def __post_init__(self):
if self.database != self.schema and self.database:
raise dbt.exceptions.RuntimeException(
f'Cannot set database {self.database} in Oracle!'
)

@staticmethod
def add_ephemeral_prefix(name):
return f'dbt__cte__{name}__'

def render(self):
if self.include_policy.database and self.include_policy.schema:
raise dbt.exceptions.RuntimeException(
'Got a Oracle relation with schema and database set to '
'include, but only one can be set'
'Got a Oracle relation with schema and database include policy set to '
'True, but only schema should be set.'
)
return super().render()
return super().render()

0 comments on commit de6af15

Please sign in to comment.