diff --git a/.github/scripts/create_new_user.sh b/.github/scripts/create_new_user.sh index a6540c9..86a6cd7 100644 --- a/.github/scripts/create_new_user.sh +++ b/.github/scripts/create_new_user.sh @@ -5,7 +5,7 @@ set -Exeuo pipefail # Parameters DB_USER="${1}" DB_PASSWORD="${2}" -TARGET_PDB="${3:-XEPDB1}" +TARGET_PDB="${3:-FREEPDB1}" # Prepare container switch statement to create user in PDB. ALTER_SESSION_CMD="ALTER SESSION SET CONTAINER=${TARGET_PDB};" @@ -21,7 +21,7 @@ sqlplus -s / as sysdba << EOF -- Exit on any errors WHENEVER SQLERROR EXIT SQL.SQLCODE ${ALTER_SESSION_CMD} - CREATE USER ${DB_USER} IDENTIFIED BY "${DB_PASSWORD}" QUOTA UNLIMITED ON USERS; - GRANT ALL PRIVILEGES TO ${DB_USER}; + CREATE USER ${DB_USER} IDENTIFIED BY "${DB_PASSWORD}" QUOTA UNLIMITED ON SYSTEM; + GRANT DB_DEVELOPER_ROLE TO ${DB_USER}; exit; EOF diff --git a/.github/workflows/oracle-xe-adapter-tests.yml b/.github/workflows/dbt-oracle-adapter-tests.yml similarity index 74% rename from .github/workflows/oracle-xe-adapter-tests.yml rename to .github/workflows/dbt-oracle-adapter-tests.yml index 6185f8b..2ea9c1e 100644 --- a/.github/workflows/oracle-xe-adapter-tests.yml +++ b/.github/workflows/dbt-oracle-adapter-tests.yml @@ -2,7 +2,7 @@ name: dbt-tests-adapter on: push jobs: - oracle_xe_21_3: + dbt_oracle_adapter_tests: runs-on: ${{ matrix.os }} strategy: fail-fast: true @@ -11,11 +11,11 @@ jobs: python-version: ['3.9', '3.10', '3.11', '3.12'] services: - oracle_db_xe: - image: container-registry.oracle.com/database/express:21.3.0-xe + oracle_db: + image: container-registry.oracle.com/database/free:latest-lite env: ORACLE_PWD: ${{ secrets.DBT_ORACLE_PASSWORD }} - options: --name oracle_db_xe + options: --name oracle_db ports: - 1521:1521 @@ -36,19 +36,19 @@ jobs: - name: Copy Create User script run: | chmod +x ${{ github.workspace }}/.github/scripts/create_new_user.sh - docker cp ${{ github.workspace }}/.github/scripts/create_new_user.sh oracle_db_xe:/home/oracle/create_new_user.sh + docker cp ${{ github.workspace }}/.github/scripts/create_new_user.sh oracle_db:/home/oracle/create_new_user.sh - name: Create dbt test users run: | - docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test ${{ secrets.DBT_ORACLE_PASSWORD }} - docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test_user_1 ${{ secrets.DBT_ORACLE_PASSWORD }} - docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test_user_2 ${{ secrets.DBT_ORACLE_PASSWORD }} - docker exec oracle_db_xe /home/oracle/create_new_user.sh dbt_test_user_3 ${{ secrets.DBT_ORACLE_PASSWORD }} + docker exec oracle_db /home/oracle/create_new_user.sh dbt_test ${{ secrets.DBT_ORACLE_PASSWORD }} + docker exec oracle_db /home/oracle/create_new_user.sh dbt_test_user_1 ${{ secrets.DBT_ORACLE_PASSWORD }} + docker exec oracle_db /home/oracle/create_new_user.sh dbt_test_user_2 ${{ secrets.DBT_ORACLE_PASSWORD }} + docker exec oracle_db /home/oracle/create_new_user.sh dbt_test_user_3 ${{ secrets.DBT_ORACLE_PASSWORD }} - name: Install dbt-oracle with core dependencies run: | python -m pip install --upgrade pip - pip install pytest 'dbt-tests-adapter~=1.10,<1.11' + pip install pytest 'dbt-tests-adapter~=1.11,<1.12' pip install -r requirements.txt pip install -e . @@ -66,8 +66,8 @@ jobs: DBT_ORACLE_PORT: 1521 DBT_ORACLE_SCHEMA: DBT_TEST DBT_ORACLE_PASSWORD: ${{ secrets.DBT_ORACLE_PASSWORD }} - DBT_ORACLE_DATABASE: XEPDB1 - DBT_ORACLE_SERVICE: XEPDB1 + DBT_ORACLE_DATABASE: FREEPDB1 + DBT_ORACLE_SERVICE: FREEPDB1 DBT_ORACLE_PROTOCOL: tcp LD_LIBRARY_PATH: /opt/oracle/instantclient_23_7 TNS_ADMIN: /opt/tns_admin @@ -85,8 +85,8 @@ jobs: DBT_ORACLE_PORT: 1521 DBT_ORACLE_SCHEMA: DBT_TEST DBT_ORACLE_PASSWORD: ${{ secrets.DBT_ORACLE_PASSWORD }} - DBT_ORACLE_DATABASE: XEPDB1 - DBT_ORACLE_SERVICE: XEPDB1 + DBT_ORACLE_DATABASE: FREEPDB1 + DBT_ORACLE_SERVICE: FREEPDB1 DBT_ORACLE_PROTOCOL: tcp DISABLE_OOB: on TNS_ADMIN: /opt/tns_admin diff --git a/dbt/include/oracle/macros/materializations/snapshot/snapshot.sql b/dbt/include/oracle/macros/materializations/snapshot/snapshot.sql index 7df29a4..0745469 100644 --- a/dbt/include/oracle/macros/materializations/snapshot/snapshot.sql +++ b/dbt/include/oracle/macros/materializations/snapshot/snapshot.sql @@ -188,7 +188,7 @@ {{ new_scd_id }} as {{ columns.dbt_scd_id }}, 'True' as {{ columns.dbt_is_deleted }} from snapshotted_data - left join deletes_source_data as source_data + left join deletes_source_data source_data on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }} where {{ unique_key_is_null(strategy.unique_key, "source_data") }} diff --git a/dbt/include/oracle/macros/materializations/snapshot/strategies.sql b/dbt/include/oracle/macros/materializations/snapshot/strategies.sql index f825ee7..656cc07 100644 --- a/dbt/include/oracle/macros/materializations/snapshot/strategies.sql +++ b/dbt/include/oracle/macros/materializations/snapshot/strategies.sql @@ -15,8 +15,8 @@ limitations under the License. #} {% macro snapshot_check_strategy(node, snapshotted_rel, current_rel, config, target_exists) %} - {% set check_cols_config = config['check_cols'] %} - {% set primary_key = config['unique_key'] %} + {% set check_cols_config = config.get('check_cols') %} + {% set primary_key = config.get('unique_key') %} {% set hard_deletes = adapter.get_hard_deletes_behavior(config) %} {% set invalidate_hard_deletes = hard_deletes == 'invalidate' %} diff --git a/dbt_adbs_test_project/models/promotion_costs.sql b/dbt_adbs_test_project/models/promotion_costs.sql index 112adbc..f71ab59 100644 --- a/dbt_adbs_test_project/models/promotion_costs.sql +++ b/dbt_adbs_test_project/models/promotion_costs.sql @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. #} -{{ config(materialized='table', grants = {'select': ['dbt_test_1']})}} +{{ config(materialized='table', grants = {'select': ['DBT_TEST_USER_1']})}} with all_promo_costs as( select * from {{ source('sh_database', 'promotions') }} ) diff --git a/requirements.txt b/requirements.txt index 7519458..55a934d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ dbt-common>=1.1.0,<2.0 dbt-adapters>=1.2.1,<2.0 dbt-core>=1.9.1,<2.0 -oracledb==3.0.0 +oracledb==3.1.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 8208904..0eee263 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -6,4 +6,4 @@ tox coverage twine pytest -dbt-tests-adapter~=1.10,<1.11 +dbt-tests-adapter~=1.11,<1.12 diff --git a/setup.cfg b/setup.cfg index 069a393..9463bb0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = dbt-common>=1.1.0,<2.0 dbt-adapters>=1.2.1,<2.0 dbt-core~=1.9,<1.10 - oracledb==3.0.0 + oracledb==3.1.0 test_suite=tests test_requires = dbt-tests-adapter~=1.10,<1.11 diff --git a/setup.py b/setup.py index 3c20748..5df3ceb 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ "dbt-common>=1.1.0,<2.0", "dbt-adapters>=1.2.1,<2.0", "dbt-core~=1.9,<1.10", - "oracledb==3.0.0" + "oracledb==3.1.0" ] test_requirements = [ diff --git a/tests/functional/adapter/incremental_materialization/test_unique_id.py b/tests/functional/adapter/incremental_materialization/test_unique_id.py index a2e12b1..aab5243 100644 --- a/tests/functional/adapter/incremental_materialization/test_unique_id.py +++ b/tests/functional/adapter/incremental_materialization/test_unique_id.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2022, Oracle and/or its affiliates. +Copyright (c) 2025, Oracle and/or its affiliates. Copyright (c) 2020, Vitor Avancini Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,6 +57,11 @@ """ models__expected__unique_key_list__inplace_overwrite_sql = """ +{{ + config( + materialized='table' + ) +}} SELECT 'CT' AS state, 'Hartford' AS county, @@ -72,9 +77,16 @@ SELECT 'NY','New York','Manhattan', TO_DATE('2021-04-01', 'YYYY-MM-DD') FROM DUAL union all SELECT 'PA','Philadelphia','Philadelphia', TO_DATE('2021-05-21', 'YYYY-MM-DD') FROM DUAL +union all +select 'CO','Denver',null,TO_DATE('2021-06-18', 'YYYY-MM-DD') FROM DUAL """ models__expected__one_str__overwrite_sql = """ +{{ + config( + materialized='table' + ) +}} SELECT 'CT' AS state, 'Hartford' AS county, @@ -90,6 +102,8 @@ SELECT 'NY','New York','Manhattan', TO_DATE('2021-04-01', 'YYYY-MM-DD') FROM DUAL union all SELECT 'PA','Philadelphia','Philadelphia', TO_DATE('2021-05-21', 'YYYY-MM-DD') FROM DUAL +union all +select 'CO','Denver', null, TO_DATE('2021-06-18', 'YYYY-MM-DD') FROM DUAL """ diff --git a/tests/functional/adapter/snapshots/test_invalidate_deletes.py b/tests/functional/adapter/snapshots/test_invalidate_deletes.py index 5fe5b09..9dac3db 100644 --- a/tests/functional/adapter/snapshots/test_invalidate_deletes.py +++ b/tests/functional/adapter/snapshots/test_invalidate_deletes.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2022, Oracle and/or its affiliates. +Copyright (c) 2025, Oracle and/or its affiliates. Copyright (c) 2020, Vitor Avancini Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +34,7 @@ {% snapshot cc_all_snapshot %} {{ config( check_cols='all', - unique_key='id', + unique_key=['id'], strategy='check', target_database=database, target_schema=schema, diff --git a/tests/functional/adapter/test_basic.py b/tests/functional/adapter/test_basic.py index e26df4b..41b018f 100644 --- a/tests/functional/adapter/test_basic.py +++ b/tests/functional/adapter/test_basic.py @@ -103,6 +103,50 @@ """ +cc_all_snapshot_sql = """ +{% snapshot cc_all_snapshot %} + {{ config( + check_cols='all', unique_key=['id'], strategy='check', + target_database=database, target_schema=schema + ) }} + select * from {{ ref(var('seed_name', 'base')) }} +{% endsnapshot %} +""".strip() + +cc_name_snapshot_sql = """ +{% snapshot cc_name_snapshot %} + {{ config( + check_cols=['name'], unique_key=['id'], strategy='check', + target_database=database, target_schema=schema + ) }} + select * from {{ ref(var('seed_name', 'base')) }} +{% endsnapshot %} +""".strip() + +cc_date_snapshot_sql = """ +{% snapshot cc_date_snapshot %} + {{ config( + check_cols=['some_date'], unique_key=['id'], strategy='check', + target_database=database, target_schema=schema + ) }} + select * from {{ ref(var('seed_name', 'base')) }} +{% endsnapshot %} +""".strip() + +ts_snapshot_sql = """ +{% snapshot ts_snapshot %} + {{ config( + strategy='timestamp', + unique_key=['id'], + updated_at='some_date', + target_database=database, + target_schema=schema, + )}} + select * from {{ ref(var('seed_name', 'base')) }} +{% endsnapshot %} +""".strip() + + class TestSimpleMaterializationsOracle(BaseSimpleMaterializations): pass @@ -146,11 +190,23 @@ class TestGenericTestsOracle(BaseGenericTests): class TestSnapshotCheckColsOracle(BaseSnapshotCheckCols): - pass + + @pytest.fixture(scope="class") + def snapshots(self): + return { + "cc_all_snapshot.sql": cc_all_snapshot_sql, + "cc_date_snapshot.sql": cc_date_snapshot_sql, + "cc_name_snapshot.sql": cc_name_snapshot_sql, + } class TestSnapshotTimestampOracle(BaseSnapshotTimestamp): - pass + + @pytest.fixture(scope="class") + def snapshots(self): + return { + "ts_snapshot.sql": ts_snapshot_sql, + } class TestBaseAdapterMethodOracle(BaseAdapterMethod): diff --git a/tests/functional/adapter/test_grants.py b/tests/functional/adapter/test_grants.py index acb3555..0ea5708 100644 --- a/tests/functional/adapter/test_grants.py +++ b/tests/functional/adapter/test_grants.py @@ -38,10 +38,10 @@ my_snapshot_sql = """ {% snapshot my_snapshot %} {{ config( - check_cols='all', unique_key='id', strategy='check', + check_cols='all', unique_key=['id'], strategy='check', target_database=database, target_schema=schema ) }} - select 1 as id, cast('blue' as {{ type_string() }}) as color from dual + select 1 as id, cast('blue' as {{ type_string() }}) as color {% endsnapshot %} """.strip()