Skip to content

v1.7.3 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/oracle-xe-adapter-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']

services:
oracle_db_xe:
Expand Down
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.7.2
VERSION=1.7.3
PROJ_DIR?=$(shell pwd)
VENV_DIR?=${PROJ_DIR}/.bldenv
BUILD_DIR=${PROJ_DIR}/build
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pip install dbt-oracle

Please refer to the [Oracle setup on dbt docs website][1] for documentation.

## Help

Questions can be asked either in [db-oracle community Slack channel][6] or in [GitHub Discussions][7]

Bugs reports or feature requests can be raised in [GitHub Issues][8]

## Sample project

To get started, a sample dbt project can be found in the directory [/dbt_adbs_test_project][5].
Expand All @@ -42,3 +48,7 @@ dbt-oracle is licensed under Apache 2.0 License which you can find [here][4].
[3]: https://github.com/oracle/dbt-oracle/blob/main/SECURITY.md
[4]: https://github.com/oracle/dbt-oracle/blob/main/LICENSE.txt
[5]: https://github.com/oracle/dbt-oracle/tree/main/dbt_adbs_test_project
[6]: https://getdbt.slack.com/archives/C01PWH4TXLY
[7]: https://github.com/oracle/dbt-oracle/discussions
[8]: https://github.com/oracle/dbt-oracle/issues

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.7.7"
version = "1.7.9"
2 changes: 1 addition & 1 deletion dbt/adapters/oracle/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def quote_seed_column(
return column

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

@available
@classmethod
Expand Down
2 changes: 2 additions & 0 deletions dbt/include/oracle/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
{%- 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
Expand All @@ -157,6 +158,7 @@
{% 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,42 @@
{% macro oracle__get_incremental_default_sql(arg_dict) %}
{% do return(get_incremental_merge_sql(arg_dict)) %}
{% 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 merge_update_columns = config.get('merge_update_columns') -%}
{%- set merge_exclude_columns = config.get('merge_exclude_columns') -%}
{%- set incremental_predicates = args_dict["incremental_predicates"] -%}
{%- set update_columns = get_merge_update_columns(merge_update_columns, merge_exclude_columns, dest_columns) -%}
{%- 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'] -%}
{%- set unique_key_merge_predicates = unique_key_result['unique_key_merge_predicates'] -%}
BEGIN
EXECUTE IMMEDIATE 'merge {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} into {{ target_relation }} DBT_INTERNAL_DEST
using {{ temp_relation }} DBT_INTERNAL_SOURCE
on ({{ unique_key_merge_predicates | join(' AND ') }})
when matched then
update set
{% for col in update_columns if (col.upper() not in unique_key_list and col not in unique_key_list) -%}
DBT_INTERNAL_DEST.{{ col }} = DBT_INTERNAL_SOURCE.{{ col }}{% if not loop.last %}, {% endif %}
{% endfor -%}
DELETE WHERE 1=1';
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
@@ -1,5 +1,5 @@
{#
Copyright (c) 2022, Oracle and/or its affiliates.
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.
Expand All @@ -17,8 +17,8 @@
config(
materialized='incremental',
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.7,<1.8
cx_Oracle==8.3.0
oracledb==2.0.1
oracledb==2.1.0
5 changes: 3 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.7.2
version = 1.7.3
description = dbt (data build tool) adapter for Oracle Autonomous Database
long_description = file: README.md
long_description_content_type = text/markdown
Expand All @@ -16,6 +16,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12

# Map or URL names to links
# Github, PyPI and documentations urls should be added below
Expand All @@ -34,7 +35,7 @@ include_package_data = True
install_requires =
dbt-core~=1.7,<1.8
cx_Oracle==8.3.0
oracledb==2.0.1
oracledb==2.1.0
test_suite=tests
test_requires =
dbt-tests-adapter~=1.7,<1.8
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
requirements = [
"dbt-core~=1.7,<1.8",
"cx_Oracle==8.3.0",
"oracledb==2.0.1"
"oracledb==2.1.0"
]

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

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

VERSION = '1.7.2'
VERSION = '1.7.3'
setup(
author="Oracle",
python_requires='>=3.8',
Expand All @@ -73,7 +73,8 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11'
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12'
],
description="dbt (data build tool) adapter for Oracle Autonomous Database",
install_requires=requirements,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py3{8,9,10,11}
envlist = py3{8,9,10,11,12}

[testenv]
passenv =
Expand Down