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 ff4f4ae2d fix(python/adbc_driver_manager): pass table_types filter to 
GetObjects (#4712)
ff4f4ae2d is described below

commit ff4f4ae2d86017c3640b9344a08f3e3190e1f998
Author: Fredrik Fornwall <[email protected]>
AuthorDate: Mon Aug 24 08:52:43 2026 +0200

    fix(python/adbc_driver_manager): pass table_types filter to GetObjects 
(#4712)
    
    The Cython binding accepted table_types but always passed `NULL` to
    `AdbcConnectionGetObjects`, so the DB-API `table_types_filter` was
    silently ignored.
    
    Convert the sequence to the null-terminated `const char**` the C API
    expects, keeping the encoded strings alive for the duration of the call,
    and add coverage proving multiple table types reach the driver.
    
    Signed-off-by: Fredrik Fornwall <[email protected]>
---
 .../adbc_driver_manager/_lib.pyx                   | 14 ++++++++++++-
 python/adbc_driver_manager/tests/test_dbapi.py     | 24 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/python/adbc_driver_manager/adbc_driver_manager/_lib.pyx 
b/python/adbc_driver_manager/adbc_driver_manager/_lib.pyx
index cf0a3171f..f84b71b94 100644
--- a/python/adbc_driver_manager/adbc_driver_manager/_lib.pyx
+++ b/python/adbc_driver_manager/adbc_driver_manager/_lib.pyx
@@ -1016,6 +1016,18 @@ cdef class AdbcConnection(_AdbcHandle):
             column_name = _to_bytes(column_name, "column_name")
             c_column_name = column_name
 
+        cdef c_vector[const char*] c_table_types
+        cdef const char** c_table_types_ptr = NULL
+        if table_types:
+            # Keep the encoded bytes alive while c_table_types points into 
their buffers
+            table_types = [
+                _to_bytes(table_type, "table_types") for table_type in 
table_types
+            ]
+            for table_type in table_types:
+                c_table_types.push_back(table_type)
+            c_table_types.push_back(<const char*> NULL)
+            c_table_types_ptr = c_table_types.data()
+
         with nogil:
             status = AdbcConnectionGetObjects(
                 &self.connection,
@@ -1023,7 +1035,7 @@ cdef class AdbcConnection(_AdbcHandle):
                 c_catalog,
                 c_db_schema,
                 c_table_name,
-                NULL,  # TODO: support table_types
+                c_table_types_ptr,
                 c_column_name,
                 &stream.stream,
                 &c_error)
diff --git a/python/adbc_driver_manager/tests/test_dbapi.py 
b/python/adbc_driver_manager/tests/test_dbapi.py
index d266dbd12..aa784a18d 100644
--- a/python/adbc_driver_manager/tests/test_dbapi.py
+++ b/python/adbc_driver_manager/tests/test_dbapi.py
@@ -116,6 +116,30 @@ def test_get_objects(sqlite) -> None:
     assert tables[0]["table_constraints"] == []
 
 
[email protected]
+def test_get_objects_table_types_filter(sqlite) -> None:
+    with sqlite.cursor() as cur:
+        cur.execute("CREATE TABLE base (ints)")
+        cur.execute("CREATE VIEW derived AS SELECT * FROM base")
+
+    def table_names(table_types_filter):
+        metadata = (
+            sqlite.adbc_get_objects(table_types_filter=table_types_filter)
+            .read_all()
+            .to_pylist()
+        )
+        return sorted(
+            table["table_name"]
+            for catalog in metadata
+            for schema in catalog["catalog_db_schemas"]
+            for table in schema["db_schema_tables"]
+        )
+
+    assert table_names(["table"]) == ["base"]
+    assert table_names(["view"]) == ["derived"]
+    assert table_names(["table", "view"]) == ["base", "derived"]
+
+
 @pytest.mark.sqlite
 def test_get_table_schema(sqlite) -> None:
     with sqlite.cursor() as cur:

Reply via email to