Skip to content

Commit 9a87f40

Browse files
Add converter parameter to _fetch_all_rows and _as_*_from_api methods
Allow custom type converter to be passed through the API fallback chain. Defaults to DefaultTypeConverter for backward compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0c7edc9 commit 9a87f40

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

pyathena/arrow/result_set.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,19 @@ def _as_arrow(self) -> "Table":
348348
table = self._read_csv()
349349
return table
350350

351-
def _as_arrow_from_api(self) -> "Table":
351+
def _as_arrow_from_api(self, converter: Optional[Converter] = None) -> "Table":
352352
"""Build an Arrow Table from GetQueryResults API.
353353
354354
Used as a fallback when ``output_location`` is not available
355355
(e.g. managed query result storage).
356+
357+
Args:
358+
converter: Type converter for result values. Defaults to
359+
``DefaultTypeConverter`` if not specified.
356360
"""
357361
import pyarrow as pa
358362

359-
rows = self._fetch_all_rows()
363+
rows = self._fetch_all_rows(converter)
360364
if not rows:
361365
return pa.Table.from_pydict({})
362366
description = self.description if self.description else []

pyathena/pandas/result_set.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,19 @@ def _as_pandas(self) -> Union["TextFileReader", "DataFrame"]:
681681
df = self._read_csv()
682682
return df
683683

684-
def _as_pandas_from_api(self) -> "DataFrame":
684+
def _as_pandas_from_api(self, converter: Optional[Converter] = None) -> "DataFrame":
685685
"""Build a DataFrame from GetQueryResults API.
686686
687687
Used as a fallback when ``output_location`` is not available
688688
(e.g. managed query result storage).
689+
690+
Args:
691+
converter: Type converter for result values. Defaults to
692+
``DefaultTypeConverter`` if not specified.
689693
"""
690694
import pandas as pd
691695

692-
rows = self._fetch_all_rows()
696+
rows = self._fetch_all_rows(converter)
693697
if not rows:
694698
return pd.DataFrame()
695699
description = self.description if self.description else []

pyathena/polars/result_set.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,19 @@ def _as_polars(self) -> "pl.DataFrame":
542542
df = self._read_csv()
543543
return df
544544

545-
def _as_polars_from_api(self) -> "pl.DataFrame":
545+
def _as_polars_from_api(self, converter: Optional[Converter] = None) -> "pl.DataFrame":
546546
"""Build a Polars DataFrame from GetQueryResults API.
547547
548548
Used as a fallback when ``output_location`` is not available
549549
(e.g. managed query result storage).
550+
551+
Args:
552+
converter: Type converter for result values. Defaults to
553+
``DefaultTypeConverter`` if not specified.
550554
"""
551555
import polars as pl
552556

553-
rows = self._fetch_all_rows()
557+
rows = self._fetch_all_rows(converter)
554558
if not rows:
555559
return pl.DataFrame()
556560
description = self.description if self.description else []

pyathena/result_set.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,23 @@ def _is_first_row_column_labels(self, rows: List[Dict[str, Any]]) -> bool:
497497

498498
def _fetch_all_rows(
499499
self,
500+
converter: Optional[Converter] = None,
500501
) -> List[Tuple[Optional[Any], ...]]:
501502
"""Fetch all rows via GetQueryResults API with type conversion.
502503
503504
Paginates through all results from the beginning using MaxResults=1000.
504-
Uses ``DefaultTypeConverter`` for string-to-Python type conversion,
505-
ensuring consistent behavior regardless of subclass converter
506-
(e.g. Pandas/Arrow converters only handle a subset of types).
505+
Defaults to ``DefaultTypeConverter`` for string-to-Python type conversion,
506+
because subclass converters (e.g. Pandas/Arrow) are designed for S3 file
507+
reading and may not handle API result strings.
507508
508509
This method is intended for use by subclass result sets that need to
509510
fall back to the API when S3 output is not available (e.g., managed
510511
query result storage).
511512
513+
Args:
514+
converter: Type converter for result values. Defaults to
515+
``DefaultTypeConverter`` if not specified.
516+
512517
Returns:
513518
List of converted row tuples.
514519
"""
@@ -521,7 +526,7 @@ def _fetch_all_rows(
521526
"This may be slow for large result sets."
522527
)
523528

524-
converter = DefaultTypeConverter()
529+
converter = converter or DefaultTypeConverter()
525530
all_rows: List[Tuple[Optional[Any], ...]] = []
526531
next_token: Optional[str] = None
527532

0 commit comments

Comments
 (0)