Skip to content

Commit 2ca6b98

Browse files
committed
perf: don't open new connections for test_get_table_schema
This means, however, that all queries need to undo any connection- level state changes.
1 parent 615e4a1 commit 2ca6b98

2 files changed

Lines changed: 27 additions & 25 deletions

File tree

adbc_drivers_validation/tests/query.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
pytest_generate_tests hook, call generate_tests.
2020
"""
2121

22-
import typing
23-
2422
import adbc_driver_manager.dbapi
2523
import pyarrow
2624
import pytest
@@ -140,35 +138,34 @@ def test_execute_schema(
140138
def test_get_table_schema(
141139
self,
142140
driver: model.DriverQuirks,
143-
conn_factory: typing.Callable[[], adbc_driver_manager.dbapi.Connection],
141+
conn: adbc_driver_manager.dbapi.Connection,
144142
query: model.Query,
145143
) -> None:
146144
subquery = query.query
147145

148146
expected_schema = subquery.expected_schema()
149147

150-
with conn_factory() as conn:
151-
with setup_connection(query, conn):
152-
_setup_query(driver, conn, query)
153-
154-
table_name = None
155-
md = query.metadata()
156-
table_name = md.setup.drop
157-
if not table_name and isinstance(subquery, model.SelectQuery):
158-
# XXX: rather hacky, but extract the table name from the SELECT query
159-
# that would normally be executed
160-
query_str = subquery.query().split()
161-
for i, word in enumerate(query_str):
162-
if word.upper() == "FROM":
163-
table_name = query_str[i + 1]
164-
break
165-
166-
assert table_name, "Could not determine table name"
167-
168-
schema = conn.adbc_get_table_schema(table_name)
169-
# Ignore the first column which is normally used to sort the table
170-
schema = pyarrow.schema(list(schema)[1:])
171-
compare.compare_schemas(expected_schema, schema)
148+
with setup_connection(query, conn):
149+
_setup_query(driver, conn, query)
150+
151+
table_name = None
152+
md = query.metadata()
153+
table_name = md.setup.drop
154+
if not table_name and isinstance(subquery, model.SelectQuery):
155+
# XXX: rather hacky, but extract the table name from the SELECT query
156+
# that would normally be executed
157+
query_str = subquery.query().split()
158+
for i, word in enumerate(query_str):
159+
if word.upper() == "FROM":
160+
table_name = query_str[i + 1]
161+
break
162+
163+
assert table_name, "Could not determine table name"
164+
165+
schema = conn.adbc_get_table_schema(table_name)
166+
# Ignore the first column which is normally used to sort the table
167+
schema = pyarrow.schema(list(schema)[1:])
168+
compare.compare_schemas(expected_schema, schema)
172169

173170
def test_show_queries(
174171
self,

adbc_drivers_validation/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def setup_connection(
7474
options[key] = value.apply
7575
if revert := value.revert:
7676
options_revert[key] = revert
77+
else:
78+
warnings.warn(
79+
f"No revert value for connection option {key} in {query.name}, this will likely have unexpected side effects!",
80+
DeprecationWarning,
81+
)
7782

7883
conn.adbc_connection.set_options(**options)
7984
yield

0 commit comments

Comments
 (0)