|
| 1 | +""" |
| 2 | +Copyright (c) 2022, Oracle and/or its affiliates. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +""" |
| 16 | +from typing import Optional, Tuple |
| 17 | + |
| 18 | +import pytest |
| 19 | + |
| 20 | +from dbt.adapters.base.relation import BaseRelation |
| 21 | + |
| 22 | +from dbt.tests.adapter.materialized_view.basic import MaterializedViewBasic |
| 23 | +from dbt.tests.util import ( |
| 24 | + assert_message_in_logs, |
| 25 | + get_model_file, |
| 26 | + run_dbt, |
| 27 | + run_dbt_and_capture, |
| 28 | + set_model_file, |
| 29 | +) |
| 30 | +from tests.functional.adapter.materialized_view.utils import query_relation_type |
| 31 | + |
| 32 | + |
| 33 | +class TestOracleMaterializedViewBasic(MaterializedViewBasic): |
| 34 | + |
| 35 | + @staticmethod |
| 36 | + def insert_record(project, table: BaseRelation, record: Tuple[int, int]): |
| 37 | + my_id, value = record |
| 38 | + project.run_sql(f"insert into {table} (id, value) values ({my_id}, {value})") |
| 39 | + |
| 40 | + @staticmethod |
| 41 | + def refresh_materialized_view(project, materialized_view: BaseRelation): |
| 42 | + sql = f""" |
| 43 | + BEGIN |
| 44 | + DBMS_MVIEW.REFRESH('{materialized_view}'); |
| 45 | + END; |
| 46 | + """ |
| 47 | + project.run_sql(sql) |
| 48 | + |
| 49 | + @staticmethod |
| 50 | + def query_row_count(project, relation: BaseRelation) -> int: |
| 51 | + sql = f"select count(*) from {relation}" |
| 52 | + return project.run_sql(sql, fetch="one")[0] |
| 53 | + |
| 54 | + @staticmethod |
| 55 | + def query_relation_type(project, relation: BaseRelation) -> Optional[str]: |
| 56 | + return query_relation_type(project, relation) |
| 57 | + |
| 58 | + @pytest.fixture(scope="function", autouse=True) |
| 59 | + def setup(self, project, my_materialized_view): |
| 60 | + |
| 61 | + run_dbt(["seed"]) |
| 62 | + run_dbt(["run", "--models", my_materialized_view.identifier, "--full-refresh"]) |
| 63 | + |
| 64 | + # the tests touch these files, store their contents in memory |
| 65 | + initial_model = get_model_file(project, my_materialized_view) |
| 66 | + |
| 67 | + yield |
| 68 | + |
| 69 | + # and then reset them after the test runs |
| 70 | + set_model_file(project, my_materialized_view, initial_model) |
| 71 | + run_dbt(["run-operation", "drop_schema", "--args", f"relation: {my_materialized_view.schema}"]) |
| 72 | + |
| 73 | + @pytest.mark.skip( |
| 74 | + "The current implementation does not support overwriting materialized views with tables." |
| 75 | + ) |
| 76 | + def test_table_replaces_materialized_view(self, project, my_materialized_view): |
| 77 | + super().test_table_replaces_materialized_view(project, my_materialized_view) |
| 78 | + |
| 79 | + @pytest.mark.skip( |
| 80 | + "The current implementation does not support overwriting materialized views with views." |
| 81 | + ) |
| 82 | + def test_view_replaces_materialized_view(self, project, my_materialized_view): |
| 83 | + super().test_view_replaces_materialized_view(project, my_materialized_view) |
| 84 | + |
0 commit comments