Skip to content

Commit 6d73229

Browse files
authored
Merge pull request #71 from oracle/dev/v1.4.0
v1.4.0
2 parents a79496f + 6cd1e8f commit 6d73229

File tree

16 files changed

+167
-40
lines changed

16 files changed

+167
-40
lines changed

.github/workflows/oracle-xe-adapter-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: true
99
matrix:
1010
os: [ ubuntu-latest ]
11-
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
11+
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
1212

1313
services:
1414
oracle_db_xe:
@@ -48,7 +48,7 @@ jobs:
4848
- name: Install dbt-oracle with core dependencies
4949
run: |
5050
python -m pip install --upgrade pip
51-
pip install pytest dbt-tests-adapter==1.3.2
51+
pip install pytest dbt-tests-adapter==1.4.1
5252
pip install -r requirements.txt
5353
pip install -e .
5454

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,4 @@ doc/build.gitbak
144144
.bldenv
145145
.venv1.2/
146146
.venv1.3/
147+
.venv1.4/

dbt/adapters/oracle/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
version = "1.3.2"
17+
version = "1.4.1"

dbt/adapters/oracle/connection_helper.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
"""
2+
Copyright (c) 2023, Oracle and/or its affiliates.
3+
Copyright (c) 2020, Vitor Avancini
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
117
import enum
218
import os
319

420
import dbt.exceptions
521
from dbt.events import AdapterLogger
622

23+
from dbt.ui import warning_tag, yellow
24+
725
logger = AdapterLogger("oracle")
826

927

@@ -85,6 +103,16 @@ class OracleDriverType(str, enum.Enum):
85103
ORA_PYTHON_DRIVER_TYPE = os.getenv('ORA_PYTHON_DRIVER_TYPE', 'cx').upper()
86104
if ORA_PYTHON_DRIVER_TYPE == OracleDriverType.CX_ORACLE:
87105
logger.info("Running in cx mode")
106+
description = (
107+
f"cx_oracle will soon be deprecated, use python-oracledb"
108+
f"\n\nTo switch to python-oracledb set the environment variable ORA_PYTHON_DRIVER_TYPE=thin "
109+
f"or ORA_PYTHON_DRIVER_TYPE=thick"
110+
f"\n\nRead the guideline here: "
111+
f"https://docs.getdbt.com/reference/warehouse-setups/oracle-setup#configure-the-python-driver-mode"
112+
f"\n\nDocumentation for python-oracledb can be found here: "
113+
f"https://oracle.github.io/python-oracledb/"
114+
)
115+
logger.warning(warning_tag(yellow(description)))
88116
import cx_Oracle as oracledb
89117
elif ORA_PYTHON_DRIVER_TYPE == OracleDriverType.THICK:
90118
import oracledb
@@ -95,5 +123,5 @@ class OracleDriverType(str, enum.Enum):
95123
SQLNET_ORA_CONFIG = OracleNetConfig.from_env()
96124
logger.info("Running in thin mode")
97125
else:
98-
raise dbt.exceptions.RuntimeException("Invalid value set for ORA_PYTHON_DRIVER_TYPE\n"
99-
"Use any one of 'cx', 'thin', or 'thick'")
126+
raise dbt.exceptions.DbtRuntimeError("Invalid value set for ORA_PYTHON_DRIVER_TYPE\n"
127+
"Use any one of 'cx', 'thin', or 'thick'")

dbt/adapters/oracle/connections.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def open(cls, connection):
190190
connection.handle = None
191191
connection.state = 'fail'
192192

193-
raise dbt.exceptions.FailedToConnectException(str(e))
193+
raise dbt.exceptions.FailedToConnectError(str(e))
194194

195195
return connection
196196

@@ -236,18 +236,18 @@ def exception_handler(self, sql):
236236
logger.info("Failed to release connection!")
237237
pass
238238

239-
raise dbt.exceptions.DatabaseException(str(e).strip()) from e
239+
raise dbt.exceptions.DbtDatabaseError(str(e).strip()) from e
240240

241241
except Exception as e:
242242
logger.info("Rolling back transaction.")
243243
self.release()
244-
if isinstance(e, dbt.exceptions.RuntimeException):
244+
if isinstance(e, dbt.exceptions.DbtRuntimeError):
245245
# during a sql query, an internal to dbt exception was raised.
246246
# this sounds a lot like a signal handler and probably has
247247
# useful information, so raise it without modification.
248248
raise e
249249

250-
raise dbt.exceptions.RuntimeException(e) from e
250+
raise dbt.exceptions.DbtRuntimeError(str(e)) from e
251251

252252
@classmethod
253253
def get_credentials(cls, credentials):

dbt/adapters/oracle/impl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def verify_database(self, database):
121121
database = database.strip('"')
122122
expected = self.config.credentials.database
123123
if expected and database.lower() != expected.lower():
124-
raise dbt.exceptions.NotImplementedException(
124+
raise dbt.exceptions.DbtRuntimeError(
125125
'Cross-db references not allowed in {} ({} vs {})'
126126
.format(self.type(), database, expected)
127127
)
@@ -307,10 +307,8 @@ def quote_seed_column(
307307
elif quote_config is None:
308308
pass
309309
else:
310-
raise_compiler_error(
311-
f'The seed configuration value of "quote_columns" has an '
312-
f'invalid type {type(quote_config)}'
313-
)
310+
raise dbt.exceptions.CompilationError(f'The seed configuration value of "quote_columns" '
311+
f'has an invalid type {type(quote_config)}')
314312

315313
if quote_columns:
316314
return self.quote(column)

dbt/adapters/oracle/relation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
from dataclasses import dataclass
17+
from dataclasses import dataclass, field
1818

1919
from dbt.adapters.base.relation import BaseRelation, Policy
2020

2121

22-
2322
@dataclass
2423
class OracleQuotePolicy(Policy):
2524
database: bool = False
@@ -36,8 +35,8 @@ class OracleIncludePolicy(Policy):
3635

3736
@dataclass(frozen=True, eq=False, repr=False)
3837
class OracleRelation(BaseRelation):
39-
quote_policy: OracleQuotePolicy = OracleQuotePolicy()
40-
include_policy: OracleIncludePolicy = OracleIncludePolicy()
38+
quote_policy: OracleQuotePolicy = field(default_factory=lambda: OracleQuotePolicy())
39+
include_policy: OracleIncludePolicy = field(default_factory=lambda: OracleIncludePolicy())
4140

4241
@staticmethod
4342
def add_ephemeral_prefix(name):

dbt/include/oracle/macros/materializations/incremental/incremental.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959

6060
{#-- Get the incremental_strategy, the macro to use for the strategy, and build the sql --#}
6161
{% set incremental_strategy = config.get('incremental_strategy') or 'default' %}
62+
{% set incremental_predicates = config.get('predicates', none) or config.get('incremental_predicates', none) %}
6263
{% set strategy_sql_macro_func = adapter.get_incremental_strategy_macro(context, incremental_strategy) %}
63-
{% set strategy_arg_dict = ({'target_relation': target_relation, 'temp_relation': tmp_relation, 'unique_key': unique_key, 'dest_columns': dest_columns }) %}
64+
{% set strategy_arg_dict = ({'target_relation': target_relation, 'temp_relation': tmp_relation, 'unique_key': unique_key, 'dest_columns': dest_columns, 'incremental_predicates': incremental_predicates }) %}
6465
{% set build_sql = strategy_sql_macro_func(strategy_arg_dict) %}
6566

6667
{% endif %}

dbt/include/oracle/macros/materializations/incremental/strategies.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
)
3535
{%- endmacro %}
3636

37-
{% macro oracle_check_and_quote_unique_key_for_incremental_merge(unique_key) %}
37+
{% macro oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates=none) %}
3838
{%- set quote = "\"" -%}
3939
{%- set unique_key_list = [] -%}
40-
{%- set unique_key_merge_predicates = [] -%}
40+
{%- set unique_key_merge_predicates = [] if incremental_predicates is none else [] + incremental_predicates -%}
4141
{% if unique_key is sequence and unique_key is not mapping and unique_key is not string %}
4242
{% for key in unique_key | unique %}
4343
{% if adapter.should_identifier_be_quoted(key, model.columns) == true %}
@@ -55,7 +55,7 @@
5555
{% endif %}
5656
{% for key in unique_key_list %}
5757
{% set this_key_match %}
58-
temp.{{ key }} = target.{{ key }}
58+
DBT_INTERNAL_SOURCE.{{ key }} = DBT_INTERNAL_DEST.{{ key }}
5959
{% endset %}
6060
{% do unique_key_merge_predicates.append(this_key_match) %}
6161
{% endfor %}
@@ -114,24 +114,25 @@
114114
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
115115
{%- set merge_update_columns = config.get('merge_update_columns') -%}
116116
{%- set merge_exclude_columns = config.get('merge_exclude_columns') -%}
117+
{%- set incremental_predicates = args_dict["incremental_predicates"] -%}
117118
{%- set update_columns = get_merge_update_columns(merge_update_columns, merge_exclude_columns, dest_columns) -%}
118119
{%- if unique_key -%}
119-
{%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key) -%}
120+
{%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates) -%}
120121
{%- set unique_key_list = unique_key_result['unique_key_list'] -%}
121122
{%- set unique_key_merge_predicates = unique_key_result['unique_key_merge_predicates'] -%}
122-
merge into {{ target_relation }} target
123-
using {{ temp_relation }} temp
123+
merge into {{ target_relation }} DBT_INTERNAL_DEST
124+
using {{ temp_relation }} DBT_INTERNAL_SOURCE
124125
on ({{ unique_key_merge_predicates | join(' AND ') }})
125126
when matched then
126127
update set
127128
{% for col in update_columns if (col.upper() not in unique_key_list and col not in unique_key_list) -%}
128-
target.{{ col }} = temp.{{ col }}{% if not loop.last %}, {% endif %}
129+
DBT_INTERNAL_DEST.{{ col }} = DBT_INTERNAL_SOURCE.{{ col }}{% if not loop.last %}, {% endif %}
129130
{% endfor -%}
130131
when not matched then
131132
insert({{ dest_cols_csv }})
132133
values(
133134
{% for col in dest_columns -%}
134-
temp.{{ adapter.check_and_quote_identifier(col.name, model.columns) }}{% if not loop.last %}, {% endif %}
135+
DBT_INTERNAL_SOURCE.{{ adapter.check_and_quote_identifier(col.name, model.columns) }}{% if not loop.last %}, {% endif %}
135136
{% endfor -%}
136137
)
137138
{%- else -%}

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dbt-core==1.3.2
1+
dbt-core==1.4.1
22
cx_Oracle==8.3.0
33
oracledb==1.2.2
44

0 commit comments

Comments
 (0)