Skip to content

Commit 3919cec

Browse files
authored
Merge pull request #142 from oracle/1.6-backports
v1.6.4
2 parents 4bae91f + 82be460 commit 3919cec

File tree

11 files changed

+105
-15
lines changed

11 files changed

+105
-15
lines changed

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.6.3
2+
VERSION=1.6.4
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.6.9"
17+
version = "1.6.14"

dbt/adapters/oracle/impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def quote_seed_column(
329329
return column
330330

331331
def valid_incremental_strategies(self):
332-
return ["append", "merge"]
332+
return ["append", "merge", "delete+insert"]
333333

334334
@available
335335
@classmethod

dbt/include/oracle/macros/adapters.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,19 @@
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
152153
{%- endif %} table {{ relation.include(schema=(not temporary)) }}
153-
{%- if contract_config.enforced -%}
154+
{%- if contract_config.enforced and not temporary -%}
154155
{{ get_assert_columns_equivalent(sql) }}
155156
{{ get_table_columns_and_constraints() }}
156157
{%- set sql = get_select_subquery(sql) %}
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,53 @@
149149
{% macro oracle__get_incremental_default_sql(arg_dict) %}
150150
{% do return(get_incremental_merge_sql(arg_dict)) %}
151151
{% endmacro %}
152+
153+
154+
{% macro oracle__get_delete_sql_for_delete_insert_strategy(target, source, unique_key, incremental_predicates) %}
155+
{%- if unique_key -%}
156+
{%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates) -%}
157+
{%- set unique_key_list = unique_key_result['unique_key_list'] -%}
158+
DELETE FROM {{ target }} DBT_INTERNAL_DEST
159+
WHERE ({% for key in unique_key_list %}
160+
DBT_INTERNAL_DEST.{{ key }} {{ ", " if not loop.last}}
161+
{% endfor %})
162+
IN (SELECT {% for key in unique_key_list %}
163+
DBT_INTERNAL_SOURCE.{{ key }} {{ ", " if not loop.last}}
164+
{% endfor %} FROM {{source}} DBT_INTERNAL_SOURCE)
165+
{%- if incremental_predicates -%}
166+
{% for predicate in incremental_predicates %}
167+
AND {{ predicate }}
168+
{% endfor %}
169+
{%- endif -%}
170+
{%- elif incremental_predicates -%}
171+
DELETE FROM {{ target }} DBT_INTERNAL_DEST
172+
WHERE {%- for predicate in incremental_predicates -%}
173+
{{ "AND" if not loop.first}} {{ predicate }}
174+
{%- endfor -%}
175+
{%- endif -%}
176+
{% endmacro %}
177+
178+
{% macro oracle__get_incremental_delete_insert_sql(args_dict) %}
179+
{%- set parallel = config.get('parallel', none) -%}
180+
{%- set dest_columns = args_dict["dest_columns"] -%}
181+
{%- set temp_relation = args_dict["temp_relation"] -%}
182+
{%- set target_relation = args_dict["target_relation"] -%}
183+
{%- set unique_key = args_dict["unique_key"] -%}
184+
{%- set dest_column_names = dest_columns | map(attribute='name') | list -%}
185+
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
186+
{%- set incremental_predicates = args_dict["incremental_predicates"] -%}
187+
{%- if unique_key or incremental_predicates -%}
188+
BEGIN
189+
EXECUTE IMMEDIATE '{{ oracle__get_delete_sql_for_delete_insert_strategy(target_relation, temp_relation, unique_key, incremental_predicates) }}';
190+
EXECUTE IMMEDIATE 'insert {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} ({{ dest_cols_csv }})(
191+
select {{ dest_cols_csv }}
192+
from {{ temp_relation }})';
193+
END;
194+
{%- else -%}
195+
insert {%- if parallel -%} /*+parallel({{ parallel }})*/ {%- endif -%} into {{ target_relation }} ({{ dest_cols_csv }})
196+
(
197+
select {{ dest_cols_csv }}
198+
from {{ temp_relation }}
199+
)
200+
{%- endif -%}
201+
{% 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
unique_key='group_id',
2020
full_refresh=false,
2121
parallel=4,
22+
partition_config={"clause": "PARTITION BY HASH(PROD_NAME) PARTITIONS 4"},
2223
table_compression_clause='COLUMN STORE COMPRESS FOR QUERY LOW')
2324
}}
2425

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.6,<1.7
22
cx_Oracle==8.3.0
3-
oracledb==2.0.1
3+
oracledb==2.2.0

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = dbt-oracle
3-
version = 1.6.3
3+
version = 1.6.4
44
description = dbt (data build tool) adapter for the Oracle database
55
long_description = file: README.md
66
long_description_content_type = text/markdown
@@ -34,7 +34,7 @@ include_package_data = True
3434
install_requires =
3535
dbt-core~=1.6,<1.7
3636
cx_Oracle==8.3.0
37-
oracledb==2.0.1
37+
oracledb==2.2.0
3838
test_suite=tests
3939
test_requires =
4040
dbt-tests-adapter~=1.6

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
requirements = [
4343
"dbt-core~=1.6,<1.7",
4444
"cx_Oracle==8.3.0",
45-
"oracledb==2.0.1"
45+
"oracledb==2.2.0"
4646
]
4747

4848
test_requirements = [
@@ -60,7 +60,7 @@
6060

6161
url = 'https://github.com/oracle/dbt-oracle'
6262

63-
VERSION = '1.6.3'
63+
VERSION = '1.6.4'
6464
setup(
6565
author="Oracle",
6666
python_requires='>=3.8',

0 commit comments

Comments
 (0)