Skip to content

Commit f7fe1fd

Browse files
authored
Merge pull request #50 from oracle/release/v1.3.0
v1.3.0
2 parents 8a437c7 + 2b97652 commit f7fe1fd

File tree

26 files changed

+394
-299
lines changed

26 files changed

+394
-299
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.2.2
51+
pip install pytest dbt-tests-adapter==1.3.0
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
@@ -143,3 +143,4 @@ doc/build.gitbak
143143
.venv
144144
.bldenv
145145
.venv1.2/
146+
.venv1.3/

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.2.0
2+
VERSION=1.3.0
33
PROJ_DIR?=$(shell pwd)
44
VENV_DIR?=${PROJ_DIR}/.bldenv
55
BUILD_DIR=${PROJ_DIR}/build

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
[![PyPI version](https://badge.fury.io/py/dbt-oracle.svg)](https://pypi.python.org/pypi/dbt-oracle)
44
[![dbt-tests-adapter](https://github.com/oracle/dbt-oracle/actions/workflows/oracle-xe-adapter-tests.yml/badge.svg)](https://github.com/oracle/dbt-oracle/actions/workflows/oracle-xe-adapter-tests.yml)
55

6-
dbt "adapters" are responsible for adapting dbt's functionality to a given database. `dbt-oracle` implements dbt functionalities for the Oracle database.
6+
`dbt-oracle` implements [dbt (data build tool)](https://docs.getdbt.com/docs/introduction) functionalities for the Oracle database.
77

88
> Prior to version 1.0.0, dbt-oracle was created and maintained by [Indicium](https://indicium.tech/) on [their GitHub repo](https://github.com/techindicium/dbt-oracle). Contributors in this repo are credited for laying the groundwork and maintaining the adapter till version 0.4.3.
99
From version 1.0.0, dbt-oracle is maintained and distributed by Oracle.
1010

1111

12-
For dbt documentation, refer https://docs.getdbt.com/docs/introduction
13-
1412
## Installation
1513

1614
For installation, read how you can set up [Oracle profile][1] for dbt

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.2.2"
17+
version = "1.3.0"

dbt/adapters/oracle/column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class OracleColumn(Column):
2929
TYPE_LABELS: ClassVar[Dict[str, str]] = {
3030
"STRING": "VARCHAR2(4000)",
3131
"TIMESTAMP": "TIMESTAMP",
32-
"FLOAT": "FLOAT",
32+
"FLOAT": "NUMBER",
3333
"INTEGER": "INTEGER",
3434
}
3535

dbt/adapters/oracle/impl.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939

4040
logger = AdapterLogger("oracle")
4141

42-
42+
# Added 6 random hex letters (56c36b) to table_a and table_b to avoid ORA-32031.
43+
# Some dbt test cases use relation names table_a and table_b
44+
# Oracle error: ORA-32031: illegal reference of a query name in WITH clause
4345
COLUMNS_EQUAL_SQL = '''
4446
with diff_count as (
4547
SELECT
@@ -51,15 +53,15 @@
5153
(SELECT {columns} FROM {relation_b} {except_op}
5254
SELECT {columns} FROM {relation_a})
5355
) a
54-
), table_a as (
56+
), table_a_56c36b as (
5557
SELECT COUNT(*) as num_rows FROM {relation_a}
56-
), table_b as (
58+
), table_b_56c36b as (
5759
SELECT COUNT(*) as num_rows FROM {relation_b}
5860
), row_count_diff as (
5961
select
6062
1 as id,
61-
table_a.num_rows - table_b.num_rows as difference
62-
from table_a, table_b
63+
table_a_56c36b.num_rows - table_b_56c36b.num_rows as difference
64+
from table_a_56c36b, table_b_56c36b
6365
)
6466
select
6567
row_count_diff.difference as row_count_difference,
@@ -314,3 +316,6 @@ def quote_seed_column(
314316
return self.quote(column)
315317
else:
316318
return column
319+
320+
def valid_incremental_strategies(self):
321+
return ["append", "merge"]

dbt/include/oracle/macros/adapters.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,6 @@
346346
{{ return(load_result('list_relations_without_caching').table) }}
347347
{% endmacro %}
348348

349-
{% macro oracle__current_timestamp() -%}
350-
CURRENT_TIMESTAMP
351-
{%- endmacro %}
352-
353349
{% macro oracle__make_temp_relation(base_relation, suffix) %}
354350
{% set dt = modules.datetime.datetime.now() %}
355351
{% set dtstring = dt.strftime("%H%M%S") %}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@
5656
{% if not dest_columns %}
5757
{% set dest_columns = adapter.get_columns_in_relation(existing_relation) %}
5858
{% endif %}
59-
{% set build_sql = oracle_incremental_upsert(tmp_relation, target_relation, dest_columns, unique_key=unique_key) %}
59+
60+
{#-- Get the incremental_strategy, the macro to use for the strategy, and build the sql --#}
61+
{% set incremental_strategy = config.get('incremental_strategy') or 'default' %}
62+
{% 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 build_sql = strategy_sql_macro_func(strategy_arg_dict) %}
65+
6066
{% endif %}
6167

6268
{% call statement("main") %}

dbt/include/oracle/macros/materializations/incremental/helpers.sql renamed to dbt/include/oracle/macros/materializations/incremental/strategies.sql

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@
3434
)
3535
{%- endmacro %}
3636

37-
{% macro oracle_check_and_quote_column_names_for_incremental_merge(dest_column_names) %}
38-
{%- set quoted_update_columns = [] -%}
39-
{%- set update_columns = config.get("merge_update_columns", default=dest_column_names) -%}
40-
{% for col in update_columns %}
41-
{% do quoted_update_columns.append(adapter.check_and_quote_identifier(col, model.columns)) %}
42-
{% endfor %}
43-
{{ return(quoted_update_columns)}}
44-
{% endmacro %}
45-
4637
{% macro oracle_check_and_quote_unique_key_for_incremental_merge(unique_key) %}
4738
{%- set quote = "\"" -%}
4839
{%- set unique_key_list = [] -%}
@@ -54,35 +45,82 @@
5445
{% else %}
5546
{% do unique_key_list.append(key.upper()) %}
5647
{% endif %}
57-
{% endfor %}
48+
{% endfor %}
49+
{% else %}
50+
{% if adapter.should_identifier_be_quoted(unique_key, model.columns) == true %}
51+
{% do unique_key_list.append(quote ~ unique_key ~ quote) %}
5852
{% else %}
59-
{% if adapter.should_identifier_be_quoted(unique_key, model.columns) == true %}
60-
{% do unique_key_list.append(quote ~ unique_key ~ quote) %}
61-
{% else %}
62-
{% do unique_key_list.append(unique_key.upper()) %}
63-
{% endif %}
53+
{% do unique_key_list.append(unique_key.upper()) %}
6454
{% endif %}
65-
{% for key in unique_key_list %}
66-
{% set this_key_match %}
67-
temp.{{ key }} = target.{{ key }}
68-
{% endset %}
69-
{% do unique_key_merge_predicates.append(this_key_match) %}
70-
{% endfor %}
55+
{% endif %}
56+
{% for key in unique_key_list %}
57+
{% set this_key_match %}
58+
temp.{{ key }} = target.{{ key }}
59+
{% endset %}
60+
{% do unique_key_merge_predicates.append(this_key_match) %}
61+
{% endfor %}
7162
{%- set unique_key_result = {'unique_key_list': unique_key_list, 'unique_key_merge_predicates': unique_key_merge_predicates} -%}
7263
{{ return(unique_key_result)}}
7364
{% endmacro %}
7465
7566
76-
{% macro oracle_incremental_upsert(tmp_relation, target_relation, dest_columns, unique_key=none, statement_name="main") %}
67+
{% macro oracle__get_merge_update_columns(merge_update_columns, merge_exclude_columns, dest_columns) %}
68+
{%- set default_cols = dest_columns | map(attribute='name') | list -%}
69+
70+
{%- if merge_update_columns and merge_exclude_columns -%}
71+
{{ exceptions.raise_compiler_error(
72+
'Model cannot specify merge_update_columns and merge_exclude_columns. Please update model to use only one config'
73+
)}}
74+
{%- elif merge_update_columns -%}
75+
{%- set update_columns = merge_update_columns -%}
76+
{%- elif merge_exclude_columns -%}
77+
{%- set update_columns = [] -%}
78+
{%- for column in dest_columns -%}
79+
{% if column.column | lower not in merge_exclude_columns | map("lower") | list %}
80+
{%- do update_columns.append(column.name) -%}
81+
{% endif %}
82+
{%- endfor -%}
83+
{%- else -%}
84+
{%- set update_columns = default_cols -%}
85+
{%- endif -%}
86+
87+
{%- set quoted_update_columns = [] -%}
88+
{% for col in update_columns %}
89+
{% do quoted_update_columns.append(adapter.check_and_quote_identifier(col, model.columns)) %}
90+
{% endfor %}
91+
{{ return(quoted_update_columns)}}
92+
{% endmacro %}
93+
94+
95+
{% macro oracle__get_incremental_append_sql(arg_dict) %}
96+
{%- set dest_columns = args_dict["dest_columns"] -%}
97+
{%- set temp_relation = args_dict["temp_relation"] -%}
98+
{%- set target_relation = args_dict["target_relation"] -%}
7799
{%- set dest_column_names = dest_columns | map(attribute='name') | list -%}
78100
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
79-
{%- set update_columns = oracle_check_and_quote_column_names_for_incremental_merge(dest_column_names) -%}
101+
INSERT INTO {{ target_relation }} ({{ dest_cols_csv }})
102+
(
103+
SELECT {{ dest_cols_csv }}
104+
FROM {{ temp_relation }}
105+
)
106+
{% endmacro %}
107+
108+
{% macro oracle__get_incremental_merge_sql(args_dict) %}
109+
{%- set dest_columns = args_dict["dest_columns"] -%}
110+
{%- set temp_relation = args_dict["temp_relation"] -%}
111+
{%- set target_relation = args_dict["target_relation"] -%}
112+
{%- set unique_key = args_dict["unique_key"] -%}
113+
{%- set dest_column_names = dest_columns | map(attribute='name') | list -%}
114+
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
115+
{%- set merge_update_columns = config.get('merge_update_columns') -%}
116+
{%- set merge_exclude_columns = config.get('merge_exclude_columns') -%}
117+
{%- set update_columns = get_merge_update_columns(merge_update_columns, merge_exclude_columns, dest_columns) -%}
80118
{%- if unique_key -%}
81119
{%- set unique_key_result = oracle_check_and_quote_unique_key_for_incremental_merge(unique_key) -%}
82120
{%- set unique_key_list = unique_key_result['unique_key_list'] -%}
83121
{%- set unique_key_merge_predicates = unique_key_result['unique_key_merge_predicates'] -%}
84122
merge into {{ target_relation }} target
85-
using {{ tmp_relation }} temp
123+
using {{ temp_relation }} temp
86124
on ({{ unique_key_merge_predicates | join(' AND ') }})
87125
when matched then
88126
update set
@@ -100,7 +138,11 @@
100138
insert into {{ target_relation }} ({{ dest_cols_csv }})
101139
(
102140
select {{ dest_cols_csv }}
103-
from {{ tmp_relation }}
141+
from {{ temp_relation }}
104142
)
105143
{%- endif -%}
106-
{%- endmacro %}
144+
{% endmacro %}
145+
146+
{% macro oracle__get_incremental_default_sql(arg_dict) %}
147+
{% do return(get_incremental_merge_sql(arg_dict)) %}
148+
{% endmacro %}

0 commit comments

Comments
 (0)