Skip to content

Commit 143a11c

Browse files
SNOW-725840 Async support for arrow fetch functions (#1399)
* SNOW-725840 Async support for arrow fetch functions [New Feature] Enabled fetch_arrow_batches and fetch_arrow_all to work for async query results.
1 parent faa906b commit 143a11c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/snowflake/connector/cursor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,8 @@ def query_result(self, qid):
995995

996996
def fetch_arrow_batches(self) -> Iterator[Table]:
997997
self.check_can_use_arrow_resultset()
998+
if self._prefetch_hook is not None:
999+
self._prefetch_hook()
9981000
if self._query_result_format != "arrow":
9991001
raise NotSupportedError
10001002
self._log_telemetry_job_data(
@@ -1004,6 +1006,8 @@ def fetch_arrow_batches(self) -> Iterator[Table]:
10041006

10051007
def fetch_arrow_all(self) -> Table | None:
10061008
self.check_can_use_arrow_resultset()
1009+
if self._prefetch_hook is not None:
1010+
self._prefetch_hook()
10071011
if self._query_result_format != "arrow":
10081012
raise NotSupportedError
10091013
self._log_telemetry_job_data(TelemetryField.ARROW_FETCH_ALL, TelemetryData.TRUE)

test/integ/pandas/test_arrow_pandas.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,25 @@ def test_execute_async_and_fetch_pandas_batches(conn_cnx):
982982
assert r_sync.values == r_async.values
983983

984984

985-
def test_simple_async_arrow(conn_cnx):
985+
def test_execute_async_and_fetch_arrow_batches(conn_cnx):
986+
"""Test fetching result of an asynchronous query as batches of arrow tables"""
987+
988+
with conn_cnx() as cnx:
989+
with cnx.cursor() as cur:
990+
cur.execute("select 1/2")
991+
res_sync = cur.fetch_arrow_batches()
992+
993+
result = cur.execute_async("select 1/2")
994+
cur.get_results_from_sfqid(result["queryId"])
995+
res_async = cur.fetch_arrow_batches()
996+
997+
assert res_sync is not None
998+
assert res_async is not None
999+
for r_sync, r_async in zip(res_sync, res_async):
1000+
assert r_sync == r_async
1001+
1002+
1003+
def test_simple_async_pandas(conn_cnx):
9861004
"""Simple test to that shows the most simple usage of fire and forget.
9871005
9881006
This test also makes sure that wait_until_ready function's sleeping is tested and
@@ -997,6 +1015,17 @@ def test_simple_async_arrow(conn_cnx):
9971015
assert cur.description
9981016

9991017

1018+
def test_simple_async_arrow(conn_cnx):
1019+
"""Simple test for async fetch_arrow_all"""
1020+
with conn_cnx() as con:
1021+
with con.cursor() as cur:
1022+
cur.execute_async("select count(*) from table(generator(timeLimit => 5))")
1023+
cur.get_results_from_sfqid(cur.sfqid)
1024+
assert len(cur.fetch_arrow_all()) == 1
1025+
assert cur.rowcount
1026+
assert cur.description
1027+
1028+
10001029
@pytest.mark.parametrize(
10011030
"use_decimal,expected",
10021031
[

0 commit comments

Comments
 (0)