Skip to content

Commit 80cd791

Browse files
authored
feat: handle different schema for GetTableSchema/ExecuteSchema (#185)
1 parent 943aa28 commit 80cd791

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

adbc_drivers_validation/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ class SelectQuery:
406406
bind_schema_path: Path | None = None
407407
#: Data for the bind parameters.
408408
bind_path: Path | None = None
409+
#: Schema of the result set (when not executing a query). For some
410+
#: databases and some situations, this is different than the schema you get
411+
#: when you actually execute the query.
412+
catalog_schema_path: Path | None = None
409413

410414
def setup_query(self) -> str | None:
411415
if not self.setup_query_path:
@@ -434,6 +438,11 @@ def query(self) -> str:
434438
def expected_schema(self) -> pyarrow.Schema:
435439
return try_txtcase(self.expected_schema_path, query_schema, ["expected_schema"])
436440

441+
def catalog_schema(self) -> pyarrow.Schema:
442+
if not self.catalog_schema_path:
443+
return self.expected_schema()
444+
return try_txtcase(self.catalog_schema_path, query_schema, ["catalog_schema"])
445+
437446
def expected_result(self) -> pyarrow.Table:
438447
return try_txtcase(
439448
self.expected_path, query_table, ["expected"], self.expected_schema()
@@ -548,6 +557,8 @@ def merge(
548557
"expected_schema_path": parent.query.expected_schema_path,
549558
"expected_path": parent.query.expected_path,
550559
}
560+
if parent.query.catalog_schema_path:
561+
params["catalog_schema_path"] = parent.query.catalog_schema_path
551562
if parent.query.setup_query_path:
552563
params["setup_query_path"] = parent.query.setup_query_path
553564
# TODO: we also want to test with ExecuteQuery so perhaps
@@ -588,6 +599,7 @@ def merge(
588599
in {
589600
"query_path",
590601
"expected_schema_path",
602+
"catalog_schema_path",
591603
"expected_path",
592604
"setup_query_path",
593605
"bind_query_path",

adbc_drivers_validation/tests/query.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ def test_execute_schema(
123123
) -> None:
124124
subquery = query.query
125125
assert isinstance(subquery, model.SelectQuery)
126-
127126
sql = subquery.query()
128-
expected_schema = subquery.expected_schema()
127+
expected_schema = subquery.catalog_schema()
129128

130129
_setup_query(driver, conn, query)
131130

@@ -142,16 +141,16 @@ def test_get_table_schema(
142141
query: model.Query,
143142
) -> None:
144143
subquery = query.query
145-
146-
expected_schema = subquery.expected_schema()
144+
assert isinstance(subquery, model.SelectQuery)
145+
expected_schema = subquery.catalog_schema()
147146

148147
with setup_connection(query, conn):
149148
_setup_query(driver, conn, query)
150149

151150
table_name = None
152151
md = query.metadata()
153152
table_name = md.setup.drop
154-
if not table_name and isinstance(subquery, model.SelectQuery):
153+
if not table_name:
155154
# XXX: rather hacky, but extract the table name from the SELECT query
156155
# that would normally be executed
157156
query_str = subquery.query().split()

adbc_drivers_validation/txtcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_part(self, part: str, schema: pyarrow.Schema | None = None) -> typing.An
9292

9393
if part == "metadata":
9494
return tomllib.loads(value)
95-
if part in {"bind_schema", "expected_schema", "input_schema"}:
95+
if part in {"bind_schema", "expected_schema", "catalog_schema", "input_schema"}:
9696
return arrowjson.loads_schema(value)
9797
elif part in {"bind_query", "query", "setup_query"}:
9898
return value

0 commit comments

Comments
 (0)