55
55
56
56
TIMESTAMP_AS_STRING_CONFIG = "spark.thriftserver.arrowBasedRowSet.timestampAsString"
57
57
DEFAULT_SOCKET_TIMEOUT = float (900 )
58
+ DEFAULT_STATEMENT_HEARTBEAT_INTERVAL = float (25 )
58
59
59
60
# see Connection.__init__ for parameter descriptions.
60
61
# - Min/Max avoids unsustainable configs (sane values are far more constrained)
@@ -77,6 +78,7 @@ class ThriftBackend:
77
78
_retry_stop_after_attempts_count : int
78
79
_retry_stop_after_attempts_duration : float
79
80
_retry_delay_default : float
81
+ _statement_heartbeat_interval : float
80
82
81
83
def __init__ (
82
84
self ,
@@ -134,6 +136,10 @@ def __init__(
134
136
# An integer representing the maximum number of redirects to follow for a request.
135
137
# This number must be <= _retry_stop_after_attempts_count.
136
138
# (defaults to None)
139
+ # _statement_heartbeat_interval
140
+ # The number of seconds to wait between sending GetOperationStatus requests to the server.
141
+ # (defaults to 25), as the server will already wait 5 seconds before responding to the request if the
142
+ # statement is still running, making a 30 second total interval between each heartbeat.
137
143
# max_download_threads
138
144
# Number of threads for handling cloud fetch downloads. Defaults to 10
139
145
@@ -231,6 +237,10 @@ def __init__(
231
237
# setTimeout defaults to 15 minutes and is expected in ms
232
238
self ._transport .setTimeout (timeout and (float (timeout ) * 1000.0 ))
233
239
240
+ self ._statement_heartbeat_interval = kwargs .get (
241
+ "_statement_heartbeat_interval" , DEFAULT_STATEMENT_HEARTBEAT_INTERVAL
242
+ )
243
+
234
244
self ._transport .setCustomHeaders (dict (http_headers ))
235
245
protocol = thrift .protocol .TBinaryProtocol .TBinaryProtocol (self ._transport )
236
246
self ._client = TCLIService .Client (protocol )
@@ -802,6 +812,7 @@ def _wait_until_command_done(self, op_handle, initial_operation_status_resp):
802
812
ttypes .TOperationState .RUNNING_STATE ,
803
813
ttypes .TOperationState .PENDING_STATE ,
804
814
]:
815
+ time .sleep (self ._statement_heartbeat_interval )
805
816
poll_resp = self ._poll_for_status (op_handle )
806
817
operation_state = poll_resp .operationState
807
818
self ._check_command_not_in_error_or_closed_state (op_handle , poll_resp )
0 commit comments