Skip to content

Commit 11695ff

Browse files
committed
v1.7.3 changes
- Added support for Python 3.12 - oracledb driver upgraded to 2.1.0 - Added support for delete+insert incremental strategy addressing #128 - Added support for new config `partition_config`
1 parent b4cbb79 commit 11695ff

File tree

13 files changed

+99
-19
lines changed

13 files changed

+99
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
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.8', '3.9', '3.10', '3.11' ]
11+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']
1212

1313
services:
1414
oracle_db_xe:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Configuration variables
2-
VERSION=1.7.2
2+
VERSION=1.7.3
33
PROJ_DIR?=$(shell pwd)
44
VENV_DIR?=${PROJ_DIR}/.bldenv
55
BUILD_DIR=${PROJ_DIR}/build

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.7.7"
17+
version = "1.7.9"

dbt/adapters/oracle/impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def quote_seed_column(
397397
return column
398398

399399
def valid_incremental_strategies(self):
400-
return ["append", "merge"]
400+
return ["append", "merge", "delete+insert"]
401401

402402
@available
403403
@classmethod

dbt/include/oracle/macros/adapters.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
{%- set parallel = config.get('parallel', none) -%}
147147
{%- set compression_clause = config.get('table_compression_clause', none) -%}
148148
{%- set contract_config = config.get('contract') -%}
149+
{%- set partition_clause = config.get('partition_config', {}).get('clause') -%}
149150
{{ sql_header if sql_header is not none }}
150151
create {% if temporary -%}
151152
global temporary
@@ -157,6 +158,7 @@
157158
{% endif %}
158159
{% if temporary -%} on commit preserve rows {%- endif %}
159160
{% if not temporary -%}
161+
{% if partition_clause %} {{ partition_clause }} {% endif %}
160162
{% if parallel %} parallel {{ parallel }}{% endif %}
161163
{% if compression_clause %} {{ compression_clause }} {% endif %}
162164
{%- endif %}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,42 @@
149149
{% macro oracle__get_incremental_default_sql(arg_dict) %}
150150
{% do return(get_incremental_merge_sql(arg_dict)) %}
151151
{% endmacro %}
152+
153+
{% macro oracle__get_incremental_delete_insert_sql(args_dict) %}
154+
{%- set parallel = config.get('parallel', none) -%}
155+
{%- set dest_columns = args_dict["dest_columns"] -%}
156+
{%- set temp_relation = args_dict["temp_relation"] -%}
157+
{%- set target_relation = args_dict["target_relation"] -%}
158+
{%- set unique_key = args_dict["unique_key"] -%}
159+
{%- set dest_column_names = dest_columns | map(attribute='name') | list -%}
160+
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
161+
{%- set merge_update_columns = config.get('merge_update_columns') -%}
162+
{%- set merge_exclude_columns = config.get('merge_exclude_columns') -%}
163+
{%- set incremental_predicates = args_dict["incremental_predicates"] -%}
164+
{%- set update_columns = get_merge_update_columns(merge_update_columns, merge_exclude_columns, dest_columns) -%}
165+
{%- if unique_key -%}
166+
{%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates) -%}
167+
{%- set unique_key_list = unique_key_result['unique_key_list'] -%}
168+
{%- set unique_key_merge_predicates = unique_key_result['unique_key_merge_predicates'] -%}
169+
BEGIN
170+
EXECUTE IMMEDIATE 'merge {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} DBT_INTERNAL_DEST
171+
using {{ temp_relation }} DBT_INTERNAL_SOURCE
172+
on ({{ unique_key_merge_predicates | join(' AND ') }})
173+
when matched then
174+
update set
175+
{% for col in update_columns if (col.upper() not in unique_key_list and col not in unique_key_list) -%}
176+
DBT_INTERNAL_DEST.{{ col }} = DBT_INTERNAL_SOURCE.{{ col }}{% if not loop.last %}, {% endif %}
177+
{% endfor -%}
178+
DELETE WHERE 1=1';
179+
EXECUTE IMMEDIATE 'insert {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} ({{ dest_cols_csv }})(
180+
select {{ dest_cols_csv }}
181+
from {{ temp_relation }})';
182+
END;
183+
{%- else -%}
184+
insert {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} ({{ dest_cols_csv }})
185+
(
186+
select {{ dest_cols_csv }}
187+
from {{ temp_relation }}
188+
)
189+
{%- endif -%}
190+
{% endmacro %}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{#
2+
Copyright (c) 2024, Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#}
16+
{{
17+
config(
18+
materialized='incremental',
19+
incremental_strategy='delete+insert',
20+
parallel=4,
21+
partition_config={"clause": "PARTITION BY HASH(PROD_NAME) PARTITIONS 4"},
22+
table_compression_clause='COLUMN STORE COMPRESS FOR QUERY LOW')
23+
}}
24+
25+
SELECT prod_name, channel_desc, calendar_month_desc,
26+
{{ snapshot_hash_arguments(['prod_name', 'channel_desc', 'calendar_month_desc']) }} AS group_id,
27+
TO_CHAR(SUM(amount_sold), '9,999,999,999') SALES$,
28+
RANK() OVER (ORDER BY SUM(amount_sold)) AS default_rank,
29+
RANK() OVER (ORDER BY SUM(amount_sold) DESC NULLS LAST) AS custom_rank
30+
FROM {{ source('sh_database', 'sales') }}, {{ source('sh_database', 'products') }}, {{ source('sh_database', 'customers') }},
31+
{{ source('sh_database', 'times') }}, {{ source('sh_database', 'channels') }}, {{ source('sh_database', 'countries') }}
32+
WHERE sales.prod_id=products.prod_id AND sales.cust_id=customers.cust_id
33+
AND customers.country_id = countries.country_id AND sales.time_id=times.time_id
34+
AND sales.channel_id=channels.channel_id
35+
AND country_iso_code='US'
36+
37+
{% if is_incremental() %}
38+
39+
AND times.calendar_month_desc > (SELECT MAX(calendar_month_desc) FROM {{ this }})
40+
41+
{% endif %}
42+
43+
GROUP BY prod_name, channel_desc, calendar_month_desc

dbt_adbs_test_project/models/us_product_sales_channel_ranking.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{#
2-
Copyright (c) 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2024, Oracle and/or its affiliates.
33

44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -17,8 +17,8 @@
1717
config(
1818
materialized='incremental',
1919
unique_key='group_id',
20-
full_refresh=false,
2120
parallel=4,
21+
partition_config={"clause": "PARTITION BY HASH(PROD_NAME) PARTITIONS 4"},
2222
table_compression_clause='COLUMN STORE COMPRESS FOR QUERY LOW')
2323
}}
2424

dbt_adbs_test_project/profiles.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ dbt_test:
1919
module: "dbt-module-1.5.2"
2020
retry_count: 1
2121
retry_delay: 5
22-
shardingkey:
23-
- skey
24-
supershardingkey:
25-
- sskey
26-
cclass: CONNECTIVITY_CLASS
27-
purity: self
2822
threads: 1
2923
test:
3024
type: oracle

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dbt-core~=1.7,<1.8
22
cx_Oracle==8.3.0
3-
oracledb==2.0.1
3+
oracledb==2.1.0

0 commit comments

Comments
 (0)