Skip to content

Commit 9734053

Browse files
Centralize on_start_query_execution storage in BaseCursor
Move the on_start_query_execution field from the five synchronous cursors (Cursor, PandasCursor, ArrowCursor, PolarsCursor, S3FSCursor) into BaseCursor.__init__, mirroring on_poll, so both connection-level callbacks live in one place. The per-execute() override and its invocation stay in each synchronous cursor (the broader execute() kwargs consolidation is tracked in #691). Async/aio/Spark cursors inherit the field but do not invoke it, as they return the query id immediately through their execution model. Behavior is unchanged; a clarifying comment documents this. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f4b8f64 commit 9734053

6 files changed

Lines changed: 5 additions & 14 deletions

File tree

pyathena/arrow/cursor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def __init__(
6363
unload: bool = False,
6464
result_reuse_enable: bool = False,
6565
result_reuse_minutes: int = CursorIterator.DEFAULT_RESULT_REUSE_MINUTES,
66-
on_start_query_execution: Callable[[str], None] | None = None,
6766
connect_timeout: float | None = None,
6867
request_timeout: float | None = None,
6968
**kwargs,
@@ -82,7 +81,6 @@ def __init__(
8281
unload: Enable UNLOAD for high-performance Parquet output.
8382
result_reuse_enable: Enable Athena query result reuse.
8483
result_reuse_minutes: Minutes to reuse cached results.
85-
on_start_query_execution: Callback invoked when query starts.
8684
connect_timeout: Socket connection timeout in seconds for S3 operations.
8785
Defaults to AWS SDK default (typically 1 second) if not specified.
8886
request_timeout: Request timeout in seconds for S3 operations.
@@ -113,7 +111,6 @@ def __init__(
113111
**kwargs,
114112
)
115113
self._unload = unload
116-
self._on_start_query_execution = on_start_query_execution
117114
self._connect_timeout = connect_timeout
118115
self._request_timeout = request_timeout
119116

pyathena/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def __init__(
173173
kill_on_interrupt: bool,
174174
result_reuse_enable: bool,
175175
result_reuse_minutes: int,
176+
on_start_query_execution: Callable[[str], None] | None = None,
176177
on_poll: OnPollCallback | None = None,
177178
**kwargs,
178179
) -> None:
@@ -191,6 +192,10 @@ def __init__(
191192
self._kill_on_interrupt = kill_on_interrupt
192193
self._result_reuse_enable = result_reuse_enable
193194
self._result_reuse_minutes = result_reuse_minutes
195+
# ``on_start_query_execution`` is invoked only by cursors whose ``execute()``
196+
# supports it (the synchronous cursors). Async/aio/Spark cursors return the
197+
# query id immediately through their execution model and do not invoke it.
198+
self._on_start_query_execution = on_start_query_execution
194199
self._on_poll = on_poll
195200

196201
@staticmethod

pyathena/cursor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def __init__(
5252
kill_on_interrupt: bool = True,
5353
result_reuse_enable: bool = False,
5454
result_reuse_minutes: int = CursorIterator.DEFAULT_RESULT_REUSE_MINUTES,
55-
on_start_query_execution: Callable[[str], None] | None = None,
5655
**kwargs,
5756
) -> None:
5857
super().__init__(
@@ -69,7 +68,6 @@ def __init__(
6968
**kwargs,
7069
)
7170
self._result_set_class = AthenaResultSet
72-
self._on_start_query_execution = on_start_query_execution
7371

7472
@property
7573
def arraysize(self) -> int:

pyathena/pandas/cursor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __init__(
7979
result_reuse_enable: bool = False,
8080
result_reuse_minutes: int = CursorIterator.DEFAULT_RESULT_REUSE_MINUTES,
8181
auto_optimize_chunksize: bool = False,
82-
on_start_query_execution: Callable[[str], None] | None = None,
8382
**kwargs,
8483
) -> None:
8584
"""Initialize PandasCursor with configuration options.
@@ -105,7 +104,6 @@ def __init__(
105104
auto_optimize_chunksize: Enable automatic chunksize determination for
106105
large files. Only effective when chunksize is None.
107106
Default: False (no automatic chunking).
108-
on_start_query_execution: Callback for query start events.
109107
**kwargs: Additional arguments passed to pandas.read_csv.
110108
"""
111109
super().__init__(
@@ -128,7 +126,6 @@ def __init__(
128126
self._cache_type = cache_type
129127
self._max_workers = max_workers
130128
self._auto_optimize_chunksize = auto_optimize_chunksize
131-
self._on_start_query_execution = on_start_query_execution
132129

133130
@staticmethod
134131
def get_default_converter(

pyathena/polars/cursor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def __init__(
7474
unload: bool = False,
7575
result_reuse_enable: bool = False,
7676
result_reuse_minutes: int = CursorIterator.DEFAULT_RESULT_REUSE_MINUTES,
77-
on_start_query_execution: Callable[[str], None] | None = None,
7877
block_size: int | None = None,
7978
cache_type: str | None = None,
8079
max_workers: int = (cpu_count() or 1) * 5,
@@ -95,7 +94,6 @@ def __init__(
9594
unload: Enable UNLOAD for high-performance Parquet output.
9695
result_reuse_enable: Enable Athena query result reuse.
9796
result_reuse_minutes: Minutes to reuse cached results.
98-
on_start_query_execution: Callback invoked when query starts.
9997
block_size: S3 read block size.
10098
cache_type: S3 caching strategy.
10199
max_workers: Maximum worker threads for parallel S3 operations.
@@ -123,7 +121,6 @@ def __init__(
123121
**kwargs,
124122
)
125123
self._unload = unload
126-
self._on_start_query_execution = on_start_query_execution
127124
self._block_size = block_size
128125
self._cache_type = cache_type
129126
self._max_workers = max_workers

pyathena/s3fs/cursor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def __init__(
5858
kill_on_interrupt: bool = True,
5959
result_reuse_enable: bool = False,
6060
result_reuse_minutes: int = CursorIterator.DEFAULT_RESULT_REUSE_MINUTES,
61-
on_start_query_execution: Callable[[str], None] | None = None,
6261
csv_reader: CSVReaderType | None = None,
6362
**kwargs,
6463
) -> None:
@@ -75,7 +74,6 @@ def __init__(
7574
kill_on_interrupt: Cancel running query on keyboard interrupt.
7675
result_reuse_enable: Enable Athena query result reuse.
7776
result_reuse_minutes: Minutes to reuse cached results.
78-
on_start_query_execution: Callback invoked when query starts.
7977
csv_reader: CSV reader class to use for parsing results.
8078
Use AthenaCSVReader (default) to distinguish between NULL
8179
(unquoted empty) and empty string (quoted empty "").
@@ -104,7 +102,6 @@ def __init__(
104102
result_reuse_minutes=result_reuse_minutes,
105103
**kwargs,
106104
)
107-
self._on_start_query_execution = on_start_query_execution
108105
self._csv_reader = csv_reader
109106

110107
@staticmethod

0 commit comments

Comments
 (0)