Skip to content

feat: Implement drop_glue_database macro and method #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
20 changes: 19 additions & 1 deletion dbt-athena/src/dbt/adapters/athena/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import lru_cache
from textwrap import dedent
from threading import Lock
from typing import Any, Dict, FrozenSet, Iterable, List, Optional, Set, Tuple, Type
from typing import TYPE_CHECKING, Any, Dict, FrozenSet, Iterable, List, Optional, Set, Tuple, Type
from urllib.parse import urlparse
from uuid import uuid4

Expand Down Expand Up @@ -69,6 +69,10 @@
from dbt.adapters.contracts.relation import RelationConfig
from dbt.adapters.sql import SQLAdapter


if TYPE_CHECKING:
from mypy_boto3_glue.client import GlueClient

boto3_client_lock = Lock()


Expand Down Expand Up @@ -1173,6 +1177,20 @@ def delete_from_glue_catalog(self, relation: AthenaRelation) -> None:
LOGGER.error(e)
raise e

@available
def drop_glue_database(self, database_name: str, catalog_id: Optional[str] = None) -> None:
conn = self.connections.get_thread_connection()
creds = conn.credentials
client = conn.handle

with boto3_client_lock:
glue_client: GlueClient = client.session.client(
"glue",
region_name=client.region_name,
config=get_boto3_config(num_retries=creds.effective_num_retries),
)
glue_client.delete_database(Name=database_name, CatalogId=catalog_id)

@available.parse_none
def valid_snapshot_target(self, relation: BaseRelation) -> None:
"""Log an error to help developers migrate to the new snapshot logic"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
drop schema if exists {{ relation.without_identifier().render_hive() }} cascade
{% endcall %}
{% endmacro %}


{% macro drop_glue_database(database_name, catalog_id) -%}
{{ adapter.drop_glue_database(database_name, catalog_id) }}
{% endmacro %}