Skip to content

Commit

Permalink
Merge pull request #142 from oracle/1.6-backports
Browse files Browse the repository at this point in the history
v1.6.4
  • Loading branch information
aosingh authored May 14, 2024
2 parents 4bae91f + 82be460 commit 3919cec
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Configuration variables
VERSION=1.6.3
VERSION=1.6.4
PROJ_DIR?=$(shell pwd)
VENV_DIR?=${PROJ_DIR}/.bldenv
BUILD_DIR=${PROJ_DIR}/build
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/oracle/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
version = "1.6.9"
version = "1.6.14"
2 changes: 1 addition & 1 deletion dbt/adapters/oracle/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def quote_seed_column(
return column

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

@available
@classmethod
Expand Down
4 changes: 3 additions & 1 deletion dbt/include/oracle/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,19 @@
{%- set parallel = config.get('parallel', none) -%}
{%- set compression_clause = config.get('table_compression_clause', none) -%}
{%- set contract_config = config.get('contract') -%}
{%- set partition_clause = config.get('partition_config', {}).get('clause') -%}
{{ sql_header if sql_header is not none }}
create {% if temporary -%}
global temporary
{%- endif %} table {{ relation.include(schema=(not temporary)) }}
{%- if contract_config.enforced -%}
{%- if contract_config.enforced and not temporary -%}
{{ get_assert_columns_equivalent(sql) }}
{{ get_table_columns_and_constraints() }}
{%- set sql = get_select_subquery(sql) %}
{% endif %}
{% if temporary -%} on commit preserve rows {%- endif %}
{% if not temporary -%}
{% if partition_clause %} {{ partition_clause }} {% endif %}
{% if parallel %} parallel {{ parallel }}{% endif %}
{% if compression_clause %} {{ compression_clause }} {% endif %}
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,53 @@
{% macro oracle__get_incremental_default_sql(arg_dict) %}
{% do return(get_incremental_merge_sql(arg_dict)) %}
{% endmacro %}
{% macro oracle__get_delete_sql_for_delete_insert_strategy(target, source, unique_key, incremental_predicates) %}
{%- if unique_key -%}
{%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key, incremental_predicates) -%}
{%- set unique_key_list = unique_key_result['unique_key_list'] -%}
DELETE FROM {{ target }} DBT_INTERNAL_DEST
WHERE ({% for key in unique_key_list %}
DBT_INTERNAL_DEST.{{ key }} {{ ", " if not loop.last}}
{% endfor %})
IN (SELECT {% for key in unique_key_list %}
DBT_INTERNAL_SOURCE.{{ key }} {{ ", " if not loop.last}}
{% endfor %} FROM {{source}} DBT_INTERNAL_SOURCE)
{%- if incremental_predicates -%}
{% for predicate in incremental_predicates %}
AND {{ predicate }}
{% endfor %}
{%- endif -%}
{%- elif incremental_predicates -%}
DELETE FROM {{ target }} DBT_INTERNAL_DEST
WHERE {%- for predicate in incremental_predicates -%}
{{ "AND" if not loop.first}} {{ predicate }}
{%- endfor -%}
{%- endif -%}
{% endmacro %}
{% macro oracle__get_incremental_delete_insert_sql(args_dict) %}
{%- set parallel = config.get('parallel', none) -%}
{%- set dest_columns = args_dict["dest_columns"] -%}
{%- set temp_relation = args_dict["temp_relation"] -%}
{%- set target_relation = args_dict["target_relation"] -%}
{%- set unique_key = args_dict["unique_key"] -%}
{%- set dest_column_names = dest_columns | map(attribute='name') | list -%}
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
{%- set incremental_predicates = args_dict["incremental_predicates"] -%}
{%- if unique_key or incremental_predicates -%}
BEGIN
EXECUTE IMMEDIATE '{{ oracle__get_delete_sql_for_delete_insert_strategy(target_relation, temp_relation, unique_key, incremental_predicates) }}';
EXECUTE IMMEDIATE 'insert {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} ({{ dest_cols_csv }})(
select {{ dest_cols_csv }}
from {{ temp_relation }})';
END;
{%- else -%}
insert {%- if parallel -%} /*+parallel({{ parallel }})*/ {%- endif -%} into {{ target_relation }} ({{ dest_cols_csv }})
(
select {{ dest_cols_csv }}
from {{ temp_relation }}
)
{%- endif -%}
{% endmacro %}
43 changes: 43 additions & 0 deletions dbt_adbs_test_project/models/us_product_delete_insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{#
Copyright (c) 2024, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}
{{
config(
materialized='incremental',
incremental_strategy='delete+insert',
parallel=4,
partition_config={"clause": "PARTITION BY HASH(PROD_NAME) PARTITIONS 4"},
table_compression_clause='COLUMN STORE COMPRESS FOR QUERY LOW')
}}

SELECT prod_name, channel_desc, calendar_month_desc,
{{ snapshot_hash_arguments(['prod_name', 'channel_desc', 'calendar_month_desc']) }} AS group_id,
TO_CHAR(SUM(amount_sold), '9,999,999,999') SALES$,
RANK() OVER (ORDER BY SUM(amount_sold)) AS default_rank,
RANK() OVER (ORDER BY SUM(amount_sold) DESC NULLS LAST) AS custom_rank
FROM {{ source('sh_database', 'sales') }}, {{ source('sh_database', 'products') }}, {{ source('sh_database', 'customers') }},
{{ source('sh_database', 'times') }}, {{ source('sh_database', 'channels') }}, {{ source('sh_database', 'countries') }}
WHERE sales.prod_id=products.prod_id AND sales.cust_id=customers.cust_id
AND customers.country_id = countries.country_id AND sales.time_id=times.time_id
AND sales.channel_id=channels.channel_id
AND country_iso_code='US'

{% if is_incremental() %}

AND times.calendar_month_desc > (SELECT MAX(calendar_month_desc) FROM {{ this }})

{% endif %}

GROUP BY prod_name, channel_desc, calendar_month_desc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
unique_key='group_id',
full_refresh=false,
parallel=4,
partition_config={"clause": "PARTITION BY HASH(PROD_NAME) PARTITIONS 4"},
table_compression_clause='COLUMN STORE COMPRESS FOR QUERY LOW')
}}

Expand Down
6 changes: 0 additions & 6 deletions dbt_adbs_test_project/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ dbt_test:
module: "dbt-module-1.5.2"
retry_count: 1
retry_delay: 5
shardingkey:
- skey
supershardingkey:
- sskey
cclass: CONNECTIVITY_CLASS
purity: self
threads: 1
test:
type: oracle
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dbt-core~=1.6,<1.7
cx_Oracle==8.3.0
oracledb==2.0.1
oracledb==2.2.0
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = dbt-oracle
version = 1.6.3
version = 1.6.4
description = dbt (data build tool) adapter for the Oracle database
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -34,7 +34,7 @@ include_package_data = True
install_requires =
dbt-core~=1.6,<1.7
cx_Oracle==8.3.0
oracledb==2.0.1
oracledb==2.2.0
test_suite=tests
test_requires =
dbt-tests-adapter~=1.6
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
requirements = [
"dbt-core~=1.6,<1.7",
"cx_Oracle==8.3.0",
"oracledb==2.0.1"
"oracledb==2.2.0"
]

test_requirements = [
Expand All @@ -60,7 +60,7 @@

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

VERSION = '1.6.3'
VERSION = '1.6.4'
setup(
author="Oracle",
python_requires='>=3.8',
Expand Down

0 comments on commit 3919cec

Please sign in to comment.