Skip to content

Commit 607f332

Browse files
authored
Merge pull request #173 from oracle/fix/snapshot
v1.9.1 changes
2 parents 8c5de42 + 72e970b commit 607f332

File tree

13 files changed

+102
-32
lines changed

13 files changed

+102
-32
lines changed

.github/scripts/create_new_user.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -Exeuo pipefail
55
# Parameters
66
DB_USER="${1}"
77
DB_PASSWORD="${2}"
8-
TARGET_PDB="${3:-XEPDB1}"
8+
TARGET_PDB="${3:-FREEPDB1}"
99

1010
# Prepare container switch statement to create user in PDB.
1111
ALTER_SESSION_CMD="ALTER SESSION SET CONTAINER=${TARGET_PDB};"
@@ -21,7 +21,7 @@ sqlplus -s / as sysdba << EOF
2121
-- Exit on any errors
2222
WHENEVER SQLERROR EXIT SQL.SQLCODE
2323
${ALTER_SESSION_CMD}
24-
CREATE USER ${DB_USER} IDENTIFIED BY "${DB_PASSWORD}" QUOTA UNLIMITED ON USERS;
25-
GRANT ALL PRIVILEGES TO ${DB_USER};
24+
CREATE USER ${DB_USER} IDENTIFIED BY "${DB_PASSWORD}" QUOTA UNLIMITED ON SYSTEM;
25+
GRANT DB_DEVELOPER_ROLE TO ${DB_USER};
2626
exit;
2727
EOF

.github/workflows/oracle-xe-adapter-tests.yml renamed to .github/workflows/dbt-oracle-adapter-tests.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: dbt-tests-adapter
22
on: push
33

44
jobs:
5-
oracle_xe_21_3:
5+
dbt_oracle_adapter_tests:
66
runs-on: ${{ matrix.os }}
77
strategy:
88
fail-fast: true
@@ -11,11 +11,11 @@ jobs:
1111
python-version: ['3.9', '3.10', '3.11', '3.12']
1212

1313
services:
14-
oracle_db_xe:
15-
image: container-registry.oracle.com/database/express:21.3.0-xe
14+
oracle_db:
15+
image: container-registry.oracle.com/database/free:latest-lite
1616
env:
1717
ORACLE_PWD: ${{ secrets.DBT_ORACLE_PASSWORD }}
18-
options: --name oracle_db_xe
18+
options: --name oracle_db
1919
ports:
2020
- 1521:1521
2121

@@ -36,19 +36,19 @@ jobs:
3636
- name: Copy Create User script
3737
run: |
3838
chmod +x ${{ github.workspace }}/.github/scripts/create_new_user.sh
39-
docker cp ${{ github.workspace }}/.github/scripts/create_new_user.sh oracle_db_xe:/home/oracle/create_new_user.sh
39+
docker cp ${{ github.workspace }}/.github/scripts/create_new_user.sh oracle_db:/home/oracle/create_new_user.sh
4040
4141
- name: Create dbt test users
4242
run: |
43-
docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test ${{ secrets.DBT_ORACLE_PASSWORD }}
44-
docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test_user_1 ${{ secrets.DBT_ORACLE_PASSWORD }}
45-
docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test_user_2 ${{ secrets.DBT_ORACLE_PASSWORD }}
46-
docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test_user_3 ${{ secrets.DBT_ORACLE_PASSWORD }}
43+
docker exec oracle_db /home/oracle/create_new_user.sh dbt_test ${{ secrets.DBT_ORACLE_PASSWORD }}
44+
docker exec oracle_db /home/oracle/create_new_user.sh dbt_test_user_1 ${{ secrets.DBT_ORACLE_PASSWORD }}
45+
docker exec oracle_db /home/oracle/create_new_user.sh dbt_test_user_2 ${{ secrets.DBT_ORACLE_PASSWORD }}
46+
docker exec oracle_db /home/oracle/create_new_user.sh dbt_test_user_3 ${{ secrets.DBT_ORACLE_PASSWORD }}
4747
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.10,<1.11'
51+
pip install pytest 'dbt-tests-adapter~=1.11,<1.12'
5252
pip install -r requirements.txt
5353
pip install -e .
5454
@@ -66,8 +66,8 @@ jobs:
6666
DBT_ORACLE_PORT: 1521
6767
DBT_ORACLE_SCHEMA: DBT_TEST
6868
DBT_ORACLE_PASSWORD: ${{ secrets.DBT_ORACLE_PASSWORD }}
69-
DBT_ORACLE_DATABASE: XEPDB1
70-
DBT_ORACLE_SERVICE: XEPDB1
69+
DBT_ORACLE_DATABASE: FREEPDB1
70+
DBT_ORACLE_SERVICE: FREEPDB1
7171
DBT_ORACLE_PROTOCOL: tcp
7272
LD_LIBRARY_PATH: /opt/oracle/instantclient_23_7
7373
TNS_ADMIN: /opt/tns_admin
@@ -85,8 +85,8 @@ jobs:
8585
DBT_ORACLE_PORT: 1521
8686
DBT_ORACLE_SCHEMA: DBT_TEST
8787
DBT_ORACLE_PASSWORD: ${{ secrets.DBT_ORACLE_PASSWORD }}
88-
DBT_ORACLE_DATABASE: XEPDB1
89-
DBT_ORACLE_SERVICE: XEPDB1
88+
DBT_ORACLE_DATABASE: FREEPDB1
89+
DBT_ORACLE_SERVICE: FREEPDB1
9090
DBT_ORACLE_PROTOCOL: tcp
9191
DISABLE_OOB: on
9292
TNS_ADMIN: /opt/tns_admin

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
{{ new_scd_id }} as {{ columns.dbt_scd_id }},
189189
'True' as {{ columns.dbt_is_deleted }}
190190
from snapshotted_data
191-
left join deletes_source_data as source_data
191+
left join deletes_source_data source_data
192192
on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }}
193193
where {{ unique_key_is_null(strategy.unique_key, "source_data") }}
194194

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
limitations under the License.
1616
#}
1717
{% macro snapshot_check_strategy(node, snapshotted_rel, current_rel, config, target_exists) %}
18-
{% set check_cols_config = config['check_cols'] %}
19-
{% set primary_key = config['unique_key'] %}
18+
{% set check_cols_config = config.get('check_cols') %}
19+
{% set primary_key = config.get('unique_key') %}
2020
{% set hard_deletes = adapter.get_hard_deletes_behavior(config) %}
2121
{% set invalidate_hard_deletes = hard_deletes == 'invalidate' %}
2222

dbt_adbs_test_project/models/promotion_costs.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
#}
16-
{{ config(materialized='table', grants = {'select': ['dbt_test_1']})}}
16+
{{ config(materialized='table', grants = {'select': ['DBT_TEST_USER_1']})}}
1717
with all_promo_costs as(
1818
select * from {{ source('sh_database', 'promotions') }}
1919
)

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dbt-common>=1.1.0,<2.0
22
dbt-adapters>=1.2.1,<2.0
33
dbt-core>=1.9.1,<2.0
4-
oracledb==3.0.0
4+
oracledb==3.1.0

requirements_dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ tox
66
coverage
77
twine
88
pytest
9-
dbt-tests-adapter~=1.10,<1.11
9+
dbt-tests-adapter~=1.11,<1.12

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ install_requires =
3535
dbt-common>=1.1.0,<2.0
3636
dbt-adapters>=1.2.1,<2.0
3737
dbt-core~=1.9,<1.10
38-
oracledb==3.0.0
38+
oracledb==3.1.0
3939
test_suite=tests
4040
test_requires =
4141
dbt-tests-adapter~=1.10,<1.11

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"dbt-common>=1.1.0,<2.0",
4444
"dbt-adapters>=1.2.1,<2.0",
4545
"dbt-core~=1.9,<1.10",
46-
"oracledb==3.0.0"
46+
"oracledb==3.1.0"
4747
]
4848

4949
test_requirements = [

tests/functional/adapter/incremental_materialization/test_unique_id.py

+15-1
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) 2025, Oracle and/or its affiliates.
33
Copyright (c) 2020, Vitor Avancini
44
55
Licensed under the Apache License, Version 2.0 (the "License");
@@ -57,6 +57,11 @@
5757
"""
5858

5959
models__expected__unique_key_list__inplace_overwrite_sql = """
60+
{{
61+
config(
62+
materialized='table'
63+
)
64+
}}
6065
SELECT
6166
'CT' AS state,
6267
'Hartford' AS county,
@@ -72,9 +77,16 @@
7277
SELECT 'NY','New York','Manhattan', TO_DATE('2021-04-01', 'YYYY-MM-DD') FROM DUAL
7378
union all
7479
SELECT 'PA','Philadelphia','Philadelphia', TO_DATE('2021-05-21', 'YYYY-MM-DD') FROM DUAL
80+
union all
81+
select 'CO','Denver',null,TO_DATE('2021-06-18', 'YYYY-MM-DD') FROM DUAL
7582
"""
7683

7784
models__expected__one_str__overwrite_sql = """
85+
{{
86+
config(
87+
materialized='table'
88+
)
89+
}}
7890
SELECT
7991
'CT' AS state,
8092
'Hartford' AS county,
@@ -90,6 +102,8 @@
90102
SELECT 'NY','New York','Manhattan', TO_DATE('2021-04-01', 'YYYY-MM-DD') FROM DUAL
91103
union all
92104
SELECT 'PA','Philadelphia','Philadelphia', TO_DATE('2021-05-21', 'YYYY-MM-DD') FROM DUAL
105+
union all
106+
select 'CO','Denver', null, TO_DATE('2021-06-18', 'YYYY-MM-DD') FROM DUAL
93107
"""
94108

95109

tests/functional/adapter/snapshots/test_invalidate_deletes.py

+2-2
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) 2025, Oracle and/or its affiliates.
33
Copyright (c) 2020, Vitor Avancini
44
55
Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +34,7 @@
3434
{% snapshot cc_all_snapshot %}
3535
{{ config(
3636
check_cols='all',
37-
unique_key='id',
37+
unique_key=['id'],
3838
strategy='check',
3939
target_database=database,
4040
target_schema=schema,

tests/functional/adapter/test_basic.py

+58-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,50 @@
103103
"""
104104

105105

106+
cc_all_snapshot_sql = """
107+
{% snapshot cc_all_snapshot %}
108+
{{ config(
109+
check_cols='all', unique_key=['id'], strategy='check',
110+
target_database=database, target_schema=schema
111+
) }}
112+
select * from {{ ref(var('seed_name', 'base')) }}
113+
{% endsnapshot %}
114+
""".strip()
115+
116+
cc_name_snapshot_sql = """
117+
{% snapshot cc_name_snapshot %}
118+
{{ config(
119+
check_cols=['name'], unique_key=['id'], strategy='check',
120+
target_database=database, target_schema=schema
121+
) }}
122+
select * from {{ ref(var('seed_name', 'base')) }}
123+
{% endsnapshot %}
124+
""".strip()
125+
126+
cc_date_snapshot_sql = """
127+
{% snapshot cc_date_snapshot %}
128+
{{ config(
129+
check_cols=['some_date'], unique_key=['id'], strategy='check',
130+
target_database=database, target_schema=schema
131+
) }}
132+
select * from {{ ref(var('seed_name', 'base')) }}
133+
{% endsnapshot %}
134+
""".strip()
135+
136+
ts_snapshot_sql = """
137+
{% snapshot ts_snapshot %}
138+
{{ config(
139+
strategy='timestamp',
140+
unique_key=['id'],
141+
updated_at='some_date',
142+
target_database=database,
143+
target_schema=schema,
144+
)}}
145+
select * from {{ ref(var('seed_name', 'base')) }}
146+
{% endsnapshot %}
147+
""".strip()
148+
149+
106150
class TestSimpleMaterializationsOracle(BaseSimpleMaterializations):
107151
pass
108152

@@ -146,11 +190,23 @@ class TestGenericTestsOracle(BaseGenericTests):
146190

147191

148192
class TestSnapshotCheckColsOracle(BaseSnapshotCheckCols):
149-
pass
193+
194+
@pytest.fixture(scope="class")
195+
def snapshots(self):
196+
return {
197+
"cc_all_snapshot.sql": cc_all_snapshot_sql,
198+
"cc_date_snapshot.sql": cc_date_snapshot_sql,
199+
"cc_name_snapshot.sql": cc_name_snapshot_sql,
200+
}
150201

151202

152203
class TestSnapshotTimestampOracle(BaseSnapshotTimestamp):
153-
pass
204+
205+
@pytest.fixture(scope="class")
206+
def snapshots(self):
207+
return {
208+
"ts_snapshot.sql": ts_snapshot_sql,
209+
}
154210

155211

156212
class TestBaseAdapterMethodOracle(BaseAdapterMethod):

tests/functional/adapter/test_grants.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
my_snapshot_sql = """
3939
{% snapshot my_snapshot %}
4040
{{ config(
41-
check_cols='all', unique_key='id', strategy='check',
41+
check_cols='all', unique_key=['id'], strategy='check',
4242
target_database=database, target_schema=schema
4343
) }}
44-
select 1 as id, cast('blue' as {{ type_string() }}) as color from dual
44+
select 1 as id, cast('blue' as {{ type_string() }}) as color
4545
{% endsnapshot %}
4646
""".strip()
4747

0 commit comments

Comments
 (0)