You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2023/06/08 14:21:43 UTC

[arrow-adbc] branch main updated: fix(python/adbc_driver_manager): fix fetching queries with empty results (#744)

This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new bff0c801 fix(python/adbc_driver_manager): fix fetching queries with empty results (#744)
bff0c801 is described below

commit bff0c801f0c84615d5cbc6bbf9bb7f48f0323a0b
Author: vipere <vi...@users.noreply.github.com>
AuthorDate: Thu Jun 8 17:21:38 2023 +0300

    fix(python/adbc_driver_manager): fix fetching queries with empty results (#744)
    
    `fetchall` currently fails on queries that return no results.
    
    The issue is `_reader.read_next_batch()` returns a batch with no rows
    which is not expected by the python code.
    I've added a condition similar to the one in the [go
    driver](https://github.com/apache/arrow-adbc/blob/main/go/adbc/sqldriver/driver.go#L590).
---
 python/adbc_driver_manager/adbc_driver_manager/dbapi.py | 5 ++++-
 python/adbc_driver_manager/tests/test_dbapi.py          | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/python/adbc_driver_manager/adbc_driver_manager/dbapi.py b/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
index 9a05f73a..53f41d0c 100644
--- a/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
+++ b/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
@@ -920,7 +920,10 @@ class _RowIterator(_Closeable):
     def fetchone(self):
         if self._current_batch is None or self._next_row >= len(self._current_batch):
             try:
-                self._current_batch = self._reader.read_next_batch()
+                while True:
+                    self._current_batch = self._reader.read_next_batch()
+                    if self._current_batch.num_rows > 0:
+                        break
                 self._next_row = 0
             except StopIteration:
                 self._current_batch = None
diff --git a/python/adbc_driver_manager/tests/test_dbapi.py b/python/adbc_driver_manager/tests/test_dbapi.py
index 478067f7..1eba12fd 100644
--- a/python/adbc_driver_manager/tests/test_dbapi.py
+++ b/python/adbc_driver_manager/tests/test_dbapi.py
@@ -294,6 +294,14 @@ def test_executemany(sqlite):
         assert next(cur) == (5, 6)
 
 
+@pytest.mark.sqlite
+def test_fetch_empty(sqlite):
+    with sqlite.cursor() as cur:
+        cur.execute("CREATE TABLE foo (bar)")
+        cur.execute("SELECT * FROM foo")
+        assert cur.fetchall() == []
+
+
 @pytest.mark.sqlite
 def test_prepare(sqlite):
     with sqlite.cursor() as cur: