diff --git a/cumulus_library/actions/cleaner.py b/cumulus_library/actions/cleaner.py index 33b1b56..131de0e 100644 --- a/cumulus_library/actions/cleaner.py +++ b/cumulus_library/actions/cleaner.py @@ -147,7 +147,12 @@ def clean_study( if dedicated := manifest.get_dedicated_schema(): view_table_list = [ ( - f"`{dedicated}`.`{x[0]}`", + # Athena uses different quoting strategies for drop view statements + # versus drop table statements. -_- + # TODO: Consider moving this logic to a database object? + f"`{dedicated}`.`{x[0]}`" + if (x[1] == "TABLE" and config.db.db_type == "athena") + else f'"{dedicated}"."{x[0]}"', x[1], ) for x in view_table_list diff --git a/pyproject.toml b/pyproject.toml index 991a1e3..76b0b6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "cumulus-library" requires-python = ">= 3.11" dependencies = [ "cumulus-fhir-support >= 1.2", - "duckdb >= 1.1", + "duckdb >= 1.1.3", "Jinja2 > 3", "pandas <3, >=2.1.3", "psmpy <1, >=0.3.13", diff --git a/tests/test_actions.py b/tests/test_actions.py index e963e5b..49d0a50 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -103,6 +103,30 @@ def test_clean_study(mock_db_config, verbose, prefix, confirm, stats, target, ra assert ("study_valid__456",) not in remaining_tables +def test_clean_dedicated_schema(mock_db_config): + with mock.patch.object(builtins, "input", lambda _: False): + mock_db_config.schema = "dedicated" + manifest = study_manifest.StudyManifest("./tests/test_data/study_dedicated_schema/") + mock_db_config.db.cursor().execute("CREATE SCHEMA dedicated") + builder.run_protected_table_builder( + config=mock_db_config, + manifest=manifest, + ) + mock_db_config.db.cursor().execute("CREATE TABLE dedicated.table_1 (test int)") + mock_db_config.db.cursor().execute( + "CREATE VIEW dedicated.view_2 AS SELECT * FROM dedicated.table_1" + ) + cleaner.clean_study(config=mock_db_config, manifest=manifest) + remaining_tables = ( + mock_db_config.db.cursor() + .execute("select distinct(table_name) from information_schema.tables") + .fetchall() + ) + assert (f"{enums.ProtectedTables.TRANSACTIONS.value}",) in remaining_tables + assert ("table_1",) not in remaining_tables + assert ("view_2",) not in remaining_tables + + def test_clean_throws_error_on_missing_params(mock_db_config): with pytest.raises(errors.CumulusLibraryError): cleaner.clean_study(config=mock_db_config, manifest=None) diff --git a/tests/test_cli.py b/tests/test_cli.py index 94cb172..75fb809 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -822,7 +822,7 @@ def test_dedicated_schema(tmp_path): ) for table in [ ("dedicated", "table_1"), - ("dedicated", "table_2"), + ("dedicated", "view_2"), ("dedicated", "table_raw_sql"), ("main", "core__condition"), ]: diff --git a/tests/test_data/study_dedicated_schema/module2.py b/tests/test_data/study_dedicated_schema/module2.py index ce4a5ed..2de6a3c 100644 --- a/tests/test_data/study_dedicated_schema/module2.py +++ b/tests/test_data/study_dedicated_schema/module2.py @@ -6,5 +6,6 @@ class ModuleTwoRunner(cumulus_library.BaseTableBuilder): def prepare_queries(self, *args, **kwargs): self.queries.append( - "CREATE TABLE IF NOT EXISTS study_dedicated_schema__table_2 (test int);" + """CREATE VIEW IF NOT EXISTS study_dedicated_schema__view_2 AS + SELECT * FROM dedicated.table_1;""" )