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

Breakout connection from athena DB init #328

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

dogversioning
Copy link
Contributor

The automatic db connection is causing some issues for the packaging use case (where we want to generate sql based on db type, but aren't actually using a connection), so this creates an explicit connection function that is called seperately from the database object init. Connection logic is then moved from the individual db init functions to the connect function.

Checklist

  • Consider if documentation in docs/ needs to be updated
    • If you've changed the structure of a table, you may need to run generate-md
    • If you've added/removed core study fields that not in US Core, update our list of those in core-study-details.md
  • Consider if tests should be added
  • Update template repo if there are changes to study configuration in manifest.toml

Copy link

github-actions bot commented Dec 16, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2372 2366 100% 90% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
cumulus_library/init.py 100% 🟢
cumulus_library/databases/athena.py 100% 🟢
cumulus_library/databases/base.py 100% 🟢
cumulus_library/databases/duckdb.py 100% 🟢
cumulus_library/databases/utils.py 100% 🟢
TOTAL 100% 🟢

updated for commit: cb6bb41 by action🐍

@dogversioning dogversioning merged commit 38ccdc8 into main Dec 16, 2024
3 checks passed
@dogversioning dogversioning deleted the mg/athena_connect_decoupling branch December 16, 2024 18:45
Comment on lines 38 to 39
# the profile may not be required, provided the above three AWS env vars
# are set. If both are present, the env vars take precedence
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is lightly out of date now, since it refers to "above three AWS env vars" and it got moved around

@@ -102,8 +105,11 @@ def col_pyarrow_types_from_sql(self, columns: list[tuple]) -> list:
output.append((column[0], pyarrow.int64()))
case "double":
output.append((column[0], pyarrow.float64()))
# This is future proofing - we don't see this type currently.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we did see it in one edge case - I don't think a normal production flow, but it might have been when dealing with flat tables? Or I'm making it up.

Comment on lines +123 to +125
@abc.abstractmethod
def connect(self):
"""Initiates connection configuration of the database"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to be Extremely Python ™️, we would probably write this abstract class as a context manager, so you could do:

with AthenaDatabase(...) as db:
    # use db

To automatically get connect/close support (and make sure that callers don't forget one of the calls, even when an exception happens).

But not necessary right now and can often be a little annoying to reorganize code to support that style (but does have some benefits - mainly the exception handling).

Comment on lines +111 to +114
if "prepare" not in args.keys():
backend.connect()
elif not args["prepare"]:
backend.connect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if not args.get("prepare"):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants