Skip to content
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

Feature delete table only #105

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v5.5.7 - 2023-05-25

- Functions that delete tables only, see `pydbtools.delete_table`.

## v5.5.6 - 2023-05-05

- Reverted to the working version for Analytical Platform

## v5.5.5 - 2023-05-02

- Fixes region issue with new SSO method by getting region from bucket.

## v5.5.4 - 2023-04-26

- Fixes user_id parsing in preparation for SSO, which changes the userid to an email address.

## v5.5.3 - 2023-03-06

- Fixed issue in create_temp_table
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ pydb.delete_database('my_database')
pydb.delete_table_and_data(database='__temp__', table='my_temp_table')
```

### Delete table but keep data on S3

```python
import pydbtools as pydb

pydb.delete_table(database='my_database', table='my_table')

# These can be used for temporary databases and tables.
pydb.delete_table(database='__temp__', table='my_temp_table')
```


For more details see [the notebook on deletions](examples/delete_databases_tables_and_partitions.ipynb).

## Usage / Examples
Expand Down
1 change: 1 addition & 0 deletions pydbtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
read_sql_queries_gen,
delete_partitions_and_data,
delete_table_and_data,
delete_table,
delete_temp_table,
delete_database_and_data,
save_query_to_parquet,
Expand Down
23 changes: 23 additions & 0 deletions pydbtools/_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,29 @@ def delete_table_and_data(table: str, database: str, boto3_session=None):
return False


@init_athena_params(allow_boto3_session=True)
def delete_table(table: str, database: str, boto3_session=None):
"""
Deletes a table from an Athena database.

Args:
table (str): The table name to drop.
database (str): The database name.

Returns:
True if table exists and is deleted, False if table
does not exist
"""

if table in list(tables(database=database, limit=None)["Table"]):
wr.catalog.delete_table_if_exists(
database=database, table=table, boto3_session=boto3_session
)
return True
else:
return False


@init_athena_params(allow_boto3_session=True)
def delete_temp_table(table: str, boto3_session=None):
"""
Expand Down