Summary
The ADBC Driver Foundry's MySQL driver (0.6.1, the latest release at the time of writing) ignores the target schema when it creates the table for an ingest. Given db_schema_name, it creates the table in the connection's default database, then inserts into the target database, so the ingest fails.
#255 works around this in the ADBC adapter. This issue tracks the workaround until the driver is fixed.
Reproduction
MySQL 8.4.11, adbc-driver-manager 1.12.0, MySQL driver 0.6.1 (dbc install mysql):
import pyarrow as pa
from adbc_driver_manager import dbapi
con = dbapi.connect(driver="mysql", db_kwargs={"uri": "mysql://root@127.0.0.1:3306/xql"})
with con.cursor() as cur:
cur.execute("CREATE DATABASE IF NOT EXISTS era5")
cur.adbc_ingest("surface", pa.table({"x": [1.0]}), mode="create", db_schema_name="era5")
-
Expected: a table era5.surface holding one row.
-
Actual:
ProgrammingError: NOT_FOUND: [MySQL] failed to prepare batch insert statement:
Error 1146 (42S02): Table 'era5.surface' doesn't exist.
The table was created as xql.surface, in the connection's default database, according to information_schema.tables.
Workaround in xarray-sql
For MySQL and MariaDB, xarray_sql/backends/adbc.py doesn't pass db_schema_name at all. Instead, _default_database makes the target database the connection's default (USE era5) for the duration of the ingest, then restores the previous default. MySQL can't unset a default database, so a connection that had no default keeps the target afterwards.
This is how mixed-dimension Datasets register as era5.<group> on MySQL. test_mysql_mixed_dimensions_register_in_a_database covers it; the test runs when XARRAY_SQL_TEST_MYSQL_URI is set.
Next steps
🤖 Generated with Claude Code
Summary
The ADBC Driver Foundry's MySQL driver (0.6.1, the latest release at the time of writing) ignores the target schema when it creates the table for an ingest. Given
db_schema_name, it creates the table in the connection's default database, then inserts into the target database, so the ingest fails.#255 works around this in the ADBC adapter. This issue tracks the workaround until the driver is fixed.
Reproduction
MySQL 8.4.11,
adbc-driver-manager1.12.0, MySQL driver 0.6.1 (dbc install mysql):Expected: a table
era5.surfaceholding one row.Actual:
The table was created as
xql.surface, in the connection's default database, according toinformation_schema.tables.Workaround in xarray-sql
For MySQL and MariaDB,
xarray_sql/backends/adbc.pydoesn't passdb_schema_nameat all. Instead,_default_databasemakes the target database the connection's default (USE era5) for the duration of the ingest, then restores the previous default. MySQL can't unset a default database, so a connection that had no default keeps the target afterwards.This is how mixed-dimension Datasets register as
era5.<group>on MySQL.test_mysql_mixed_dimensions_register_in_a_databasecovers it; the test runs whenXARRAY_SQL_TEST_MYSQL_URIis set.Next steps
_default_databaseand passdb_schema_namethrough on MySQL, as on every other database.🤖 Generated with Claude Code