Skip to content

Commit d403fcd

Browse files
jprakash-dbvarun-edachali-dbx
authored andcommitted
Added example for async execute query (#537)
Added examples and fixed the async execute not working without pyarrow Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent ca51d1d commit d403fcd

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/databricks/sql/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,19 @@ def is_query_pending(self):
877877
ttypes.TOperationState.PENDING_STATE,
878878
]
879879

880+
def is_query_pending(self):
881+
"""
882+
Checks whether the async executing query is in pending state or not
883+
884+
:return:
885+
"""
886+
operation_state = self.get_query_state()
887+
888+
return not operation_state or operation_state in [
889+
ttypes.TOperationState.RUNNING_STATE,
890+
ttypes.TOperationState.PENDING_STATE,
891+
]
892+
880893
def get_async_execution_result(self):
881894
"""
882895

tests/e2e/test_driver.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,14 @@ def test_cloud_fetch(self):
179179

180180

181181
class TestPySQLAsyncQueriesSuite(PySQLPytestTestCase):
182-
def isExecuting(self, operation_state):
183-
return not operation_state or operation_state in [
184-
ttypes.TOperationState.RUNNING_STATE,
185-
ttypes.TOperationState.PENDING_STATE,
186-
]
187-
188182
def test_execute_async__long_running(self):
189183

190184
long_running_query = "SELECT COUNT(*) FROM RANGE(10000 * 16) x JOIN RANGE(10000) y ON FROM_UNIXTIME(x.id * y.id, 'yyyy-MM-dd') LIKE '%not%a%date%'"
191185
with self.cursor() as cursor:
192186
cursor.execute_async(long_running_query)
193187

194188
## Polling after every POLLING_INTERVAL seconds
195-
while self.isExecuting(cursor.get_query_state()):
189+
while cursor.is_query_pending():
196190
time.sleep(self.POLLING_INTERVAL)
197191
log.info("Polling the status in test_execute_async")
198192

@@ -211,7 +205,7 @@ def test_execute_async__small_result(self):
211205
time.sleep(5)
212206

213207
## Polling after every POLLING_INTERVAL seconds
214-
while self.isExecuting(cursor.get_query_state()):
208+
while cursor.is_query_pending():
215209
time.sleep(self.POLLING_INTERVAL)
216210
log.info("Polling the status in test_execute_async")
217211

@@ -241,7 +235,7 @@ def test_execute_async__large_result(self):
241235
time.sleep(5)
242236

243237
## Polling after every POLLING_INTERVAL seconds
244-
while self.isExecuting(cursor.get_query_state()):
238+
while cursor.is_query_pending():
245239
time.sleep(self.POLLING_INTERVAL)
246240
log.info("Polling the status in test_execute_async")
247241

0 commit comments

Comments
 (0)