Skip to content

Commit 8bf4442

Browse files
committed
add docs for functions
1 parent beffa2f commit 8bf4442

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/databricks/sql/client.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from databricks.sql.experimental.oauth_persistence import OAuthPersistence
4747

4848
from databricks.sql.thrift_api.TCLIService.ttypes import (
49-
TSparkParameter,
49+
TSparkParameter, TOperationState,
5050
)
5151

5252

@@ -764,6 +764,11 @@ def execute(
764764
Both will result in the query equivalent to "SELECT * FROM table WHERE field = 'foo'
765765
being sent to the server
766766
767+
async_op:
768+
Denotes whether the execute command will execute the request asynchronously or not
769+
By default it is set to False, if set True the execution request will be submitted and the code
770+
will be non-blocking. User can later poll and request the result when ready
771+
767772
:returns self
768773
"""
769774

@@ -819,14 +824,35 @@ def execute_async(
819824
self,
820825
operation: str,
821826
parameters: Optional[TParameterCollection] = None,
822-
):
823-
return self.execute(operation, parameters, True)
827+
) -> "Cursor":
828+
"""
829+
830+
Execute a query and do not wait for it to complete and just move ahead
831+
832+
Internally it calls execute function with async_op=True
833+
:param operation:
834+
:param parameters:
835+
:return:
836+
"""
837+
self.execute(operation, parameters, True)
838+
return self
824839

825-
def get_query_state(self):
840+
def get_query_state(self) -> "TOperationState":
841+
"""
842+
Get the state of the async executing query or basically poll the status of the query
843+
844+
:return:
845+
"""
826846
self._check_not_closed()
827847
return self.thrift_backend.get_query_state(self.active_op_handle)
828848

829849
def get_execution_result(self):
850+
"""
851+
852+
Checks for the status of the async executing query and fetches the result if the query is finished
853+
If executed sets the active_result_set to the obtained result
854+
:return:
855+
"""
830856
self._check_not_closed()
831857

832858
operation_state = self.get_query_state()

src/databricks/sql/thrift_backend.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import threading
88
from typing import List, Union
99

10+
from databricks.sql.thrift_api.TCLIService.ttypes import TOperationState
11+
1012
try:
1113
import pyarrow
1214
except ImportError:
@@ -844,7 +846,7 @@ def _wait_until_command_done(self, op_handle, initial_operation_status_resp):
844846
self._check_command_not_in_error_or_closed_state(op_handle, poll_resp)
845847
return operation_state
846848

847-
def get_query_state(self, op_handle):
849+
def get_query_state(self, op_handle) -> "TOperationState":
848850
poll_resp = self._poll_for_status(op_handle)
849851
operation_state = poll_resp.operationState
850852
self._check_command_not_in_error_or_closed_state(op_handle, poll_resp)

tests/e2e/test_driver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ def isExecuting(operation_state):
187187
with self.cursor() as cursor:
188188
cursor.execute_async(long_running_query)
189189

190-
## Polling
190+
## Polling after every 10 seconds
191191
while isExecuting(cursor.get_query_state()):
192+
time.sleep(10)
192193
log.info("Polling the status in test_execute_async")
193194

194195
cursor.get_execution_result()

0 commit comments

Comments
 (0)