Skip to content

Commit 1de6510

Browse files
authored
Merge pull request #103 from awslabs/athena
Athena
2 parents bf54802 + 220015a commit 1de6510

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

awswrangler/pandas.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,15 @@ def _read_sql_athena_ctas(self,
583583
manifest_path: str = f"{s3_output}/tables/{query_id}-manifest.csv"
584584
paths: List[str] = self._session.athena.extract_manifest_paths(path=manifest_path)
585585
logger.debug(f"paths: {paths}")
586-
return self.read_parquet(path=paths,
587-
procs_cpu_bound=procs_cpu_bound,
588-
wait_objects=True,
589-
wait_objects_timeout=15.0)
586+
if not paths:
587+
df: pd.DataFrame = pd.DataFrame()
588+
else:
589+
df = self.read_parquet(path=paths,
590+
procs_cpu_bound=procs_cpu_bound,
591+
wait_objects=True,
592+
wait_objects_timeout=15.0)
593+
self._session.s3.delete_listed_objects(objects_paths=[manifest_path] + paths)
594+
return df
590595

591596
def _read_sql_athena_regular(self,
592597
sql: str,

testing/test_awswrangler/test_pandas.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,3 +2020,17 @@ def test_read_csv_prefix_iterator(bucket, sample, row_num):
20202020
total_count += count
20212021
wr.s3.delete_listed_objects(objects_paths=paths)
20222022
assert total_count == row_num * n
2023+
2024+
2025+
@pytest.mark.parametrize("ctas_approach", [False, True])
2026+
def test_read_sql_athena_empty(ctas_approach):
2027+
sql = """
2028+
WITH dataset AS (
2029+
SELECT 0 AS id
2030+
)
2031+
SELECT id
2032+
FROM dataset
2033+
WHERE id != 0
2034+
"""
2035+
df = wr.pandas.read_sql_athena(sql=sql, ctas_approach=ctas_approach)
2036+
print(df)

0 commit comments

Comments
 (0)