Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions adbc_drivers_validation/tests/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,45 @@ def test_parameter_execute(
result = pyarrow.RecordBatchReader._import_from_c(handle.address).read_all()
assert result[0].to_pylist() == [2, 3, 4, 5]

@pytest.mark.requires_features(["statement_bind"])
def test_parameter_dictionary_encoded(
self,
driver: model.DriverQuirks,
conn: adbc_driver_manager.dbapi.Connection,
sample_table: str,
) -> None:
# Dictionary encoding is an encoding of the same logical values, not
# a different logical type (Arrow columnar format, "Dictionary-encoded
# Layout"). A driver that binds string parameters should also accept
# a dictionary-encoded string column (what pandas produces for
# categoricals), decoding it if the database has no equivalent.
id_ = driver.quote_identifier("id")
value = driver.quote_identifier("value")
ids = pyarrow.array([7101, 7102, 7103], type=pyarrow.int64())
values = pyarrow.array(
["apple", "banana", None], type=pyarrow.string()
).dictionary_encode()
parameters = pyarrow.RecordBatch.from_arrays([ids, values], names=["0", "1"])
with conn.cursor() as cursor:
cursor.adbc_statement.set_sql_query(
f"INSERT INTO {sample_table} ({id_}, {value}) "
f"VALUES ({driver.bind_parameter(1)}, {driver.bind_parameter(2)})"
)
# Prepare before Bind: some drivers (e.g. the Go FlightSQL
# driver) require it, and prepare-first works everywhere.
cursor.adbc_statement.prepare()
cursor.adbc_statement.bind(parameters)
cursor.adbc_statement.execute_update()

with conn.cursor() as cursor:
cursor.adbc_statement.set_sql_query(
f"SELECT {value} FROM {sample_table} "
f"WHERE {id_} IN (7101, 7102, 7103) ORDER BY {id_}"
)
handle, _ = cursor.adbc_statement.execute_query()
result = pyarrow.RecordBatchReader._import_from_c(handle.address).read_all()
assert result[0].to_pylist() == ["apple", "banana", None]

def test_parameter_schema(
self, driver: model.DriverQuirks, conn: adbc_driver_manager.dbapi.Connection
) -> None:
Expand Down