Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb3e32c

Browse files
authored
Fix : Unable to poll results in async API (#515)
* Fixed the async issue* Added unit tests* Minor change* Changed to 5* Increased time
1 parent3111158 commitfb3e32c

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

‎src/databricks/sql/thrift_backend.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,12 @@ def execute_command(
899899
sessionHandle=session_handle,
900900
statement=operation,
901901
runAsync=True,
902-
getDirectResults=ttypes.TSparkGetDirectResults(
903-
maxRows=max_rows,maxBytes=max_bytes
902+
# For async operation we don't want the direct results
903+
getDirectResults=None
904+
ifasync_op
905+
elsettypes.TSparkGetDirectResults(
906+
maxRows=max_rows,
907+
maxBytes=max_bytes,
904908
),
905909
canReadArrowResult=TrueifpyarrowelseFalse,
906910
canDecompressLZ4Result=lz4_compression,

‎tests/e2e/common/large_queries_mixin.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_long_running_query(self):
9494
scale_factor=1
9595
withself.cursor()ascursor:
9696
whileduration<min_duration:
97-
assertscale_factor<512,"Detected infinite loop"
97+
assertscale_factor<1024,"Detected infinite loop"
9898
start=time.time()
9999

100100
cursor.execute(

‎tests/e2e/test_driver.py‎

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,22 @@ def test_cloud_fetch(self):
177177
foriinrange(len(cf_result)):
178178
assertcf_result[i]==noop_result[i]
179179

180-
deftest_execute_async(self):
181-
defisExecuting(operation_state):
182-
returnnotoperation_stateoroperation_statein [
183-
ttypes.TOperationState.RUNNING_STATE,
184-
ttypes.TOperationState.PENDING_STATE,
185-
]
180+
181+
classTestPySQLAsyncQueriesSuite(PySQLPytestTestCase):
182+
defisExecuting(self,operation_state):
183+
returnnotoperation_stateoroperation_statein [
184+
ttypes.TOperationState.RUNNING_STATE,
185+
ttypes.TOperationState.PENDING_STATE,
186+
]
187+
188+
deftest_execute_async__long_running(self):
186189

187190
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%'"
188191
withself.cursor()ascursor:
189192
cursor.execute_async(long_running_query)
190193

191194
## Polling after every POLLING_INTERVAL seconds
192-
whileisExecuting(cursor.get_query_state()):
195+
whileself.isExecuting(cursor.get_query_state()):
193196
time.sleep(self.POLLING_INTERVAL)
194197
log.info("Polling the status in test_execute_async")
195198

@@ -198,6 +201,55 @@ def isExecuting(operation_state):
198201

199202
assertresult[0].asDict()== {"count(1)":0}
200203

204+
deftest_execute_async__small_result(self):
205+
small_result_query="SELECT 1"
206+
207+
withself.cursor()ascursor:
208+
cursor.execute_async(small_result_query)
209+
210+
## Fake sleep for 5 secs
211+
time.sleep(5)
212+
213+
## Polling after every POLLING_INTERVAL seconds
214+
whileself.isExecuting(cursor.get_query_state()):
215+
time.sleep(self.POLLING_INTERVAL)
216+
log.info("Polling the status in test_execute_async")
217+
218+
cursor.get_async_execution_result()
219+
result=cursor.fetchall()
220+
221+
assertresult[0].asDict()== {"1":1}
222+
223+
deftest_execute_async__large_result(self):
224+
x_dimension=1000
225+
y_dimension=1000
226+
large_result_query=f"""
227+
SELECT
228+
x.id AS x_id,
229+
y.id AS y_id,
230+
FROM_UNIXTIME(x.id * y.id, 'yyyy-MM-dd') AS date
231+
FROM
232+
RANGE({x_dimension}) x
233+
JOIN
234+
RANGE({y_dimension}) y
235+
"""
236+
237+
withself.cursor()ascursor:
238+
cursor.execute_async(large_result_query)
239+
240+
## Fake sleep for 5 secs
241+
time.sleep(5)
242+
243+
## Polling after every POLLING_INTERVAL seconds
244+
whileself.isExecuting(cursor.get_query_state()):
245+
time.sleep(self.POLLING_INTERVAL)
246+
log.info("Polling the status in test_execute_async")
247+
248+
cursor.get_async_execution_result()
249+
result=cursor.fetchall()
250+
251+
assertlen(result)==x_dimension*y_dimension
252+
201253

202254
# Exclude Retry tests because they require specific setups, and LargeQueries too slow for core
203255
# tests

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp