Skip to content

Commit 9df8f6f

Browse files
author
James Robinson
authored
Magics support for AWS Athena (#66)
1 parent 00ebb4c commit 9df8f6f

File tree

5 files changed

+1469
-195
lines changed

5 files changed

+1469
-195
lines changed

noteable_magics/datasource_postprocessing.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from tempfile import NamedTemporaryFile
55
from typing import Any, Callable, Dict
6-
from urllib.parse import urlparse
6+
from urllib.parse import quote_plus, urlparse
77

88
import structlog
99

@@ -236,3 +236,27 @@ def postprocess_sqlite(
236236
raise ValueError(
237237
f'SQLite database files should be located within /tmp, got "{cur_path}"'
238238
)
239+
240+
241+
@register_postprocessor('awsathena')
242+
def postprocess_awsathena(
243+
datasource_id: str, dsn_dict: Dict[str, str], create_engine_kwargs: Dict[str, Any]
244+
) -> None:
245+
"""Postprocess awsathena details:
246+
247+
1. Host will be just the region name. Expand to -> athena.{region_name}.amazonaws.com
248+
2. Username + password will be AWS access key id + secret value. Needs to be quote_plus protected.
249+
3. Likewise the 's3_staging_dir' present in create_engine_kwargs.
250+
251+
See https://github.com/laughingman7743/PyAthena/
252+
"""
253+
254+
# 1. Flesh out host
255+
dsn_dict['host'] = f"athena.{dsn_dict['host']}.amazonaws.com"
256+
257+
# 2. quote_plus username / password
258+
dsn_dict['username'] = quote_plus(dsn_dict['username'])
259+
dsn_dict['password'] = quote_plus(dsn_dict['password'])
260+
261+
# 3. quote_plus s3_staging_dir
262+
create_engine_kwargs['s3_staging_dir'] = quote_plus(create_engine_kwargs['s3_staging_dir'])

0 commit comments

Comments
 (0)