Skip to content

Commit ee6b05f

Browse files
committed
Add user-friendly msgs for Athena errors. #239
1 parent 2243aac commit ee6b05f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

awswrangler/athena.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,20 @@ def read_sql_query( # pylint: disable=too-many-branches,too-many-locals,too-man
514514
boto3_session=session,
515515
)
516516
_logger.debug("query_id: %s", query_id)
517-
query_response: Dict[str, Any] = wait_query(query_execution_id=query_id, boto3_session=session)
517+
try:
518+
query_response: Dict[str, Any] = wait_query(query_execution_id=query_id, boto3_session=session)
519+
except exceptions.QueryFailed as ex:
520+
if ctas_approach is True:
521+
if "Column name not specified" in str(ex):
522+
raise exceptions.InvalidArgumentValue(
523+
"Please, define all columns names in your query. (E.g. 'SELECT MAX(col1) AS max_col1, ...')"
524+
)
525+
if "Column type is unknown" in str(ex):
526+
raise exceptions.InvalidArgumentValue(
527+
"Please, define all columns types in your query. "
528+
"(E.g. 'SELECT CAST(NULL AS INTEGER) AS MY_COL, ...')"
529+
)
530+
raise ex # pragma: no cover
518531
if query_response["QueryExecution"]["Status"]["State"] in ["FAILED", "CANCELLED"]: # pragma: no cover
519532
reason: str = query_response["QueryExecution"]["Status"]["StateChangeReason"]
520533
message_error: str = f"Query error: {reason}"

testing/test_awswrangler/test_data_lake.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,3 +1675,10 @@ def test_store_metadata_partitions_sample_dataset(database, table, path, partiti
16751675
assert df.c0.sum() * num_files == df2.c0.sum()
16761676
assert df.c1.sum() * num_files == df2.c1.sum()
16771677
assert df.c2.sum() * num_files == df2.c2.sum()
1678+
1679+
1680+
def test_athena_undefined_column(database):
1681+
with pytest.raises(wr.exceptions.InvalidArgumentValue):
1682+
wr.athena.read_sql_query("SELECT 1", database)
1683+
with pytest.raises(wr.exceptions.InvalidArgumentValue):
1684+
wr.athena.read_sql_query("SELECT NULL", database)

0 commit comments

Comments
 (0)