tokoko opened a new pull request, #60630:
URL: https://github.com/apache/spark/pull/60630

   ### What changes were proposed in this pull request?
   
   This PR adds a data source and a catalog for databases accessed with [ADBC 
(Arrow Database Connectivity)](https://arrow.apache.org/adbc/) drivers, as 
proposed in the SPIP 
[SPARK-60255](https://issues.apache.org/jira/browse/SPARK-60255).
   
   The data source is a DSv2 `TableProvider` registered as `adbc`, in 
`sql/core` under `org.apache.spark.sql.execution.datasources.v2.adbc`. Drivers 
are loaded with the ADBC driver manager from a class name (`driver` option), so 
any Java ADBC driver works: Flight SQL, the JDBC bridge, or native drivers 
through the JNI driver (`jni.driver`).
   
   Reads:
   - `dbtable` (with an optional `dbschema`) or `query`, like the JDBC data 
source. The schema comes from the driver's `executeSchema`, falling back to a 
query that returns no rows.
   - Results are read as columnar batches, wrapping the driver's Arrow vectors 
without copying.
   - Column pruning, with identifiers quoted with the driver's quote string, 
the `identifierQuoteChar` option, or the SQL standard `"` for tables.
   - Driver partitioning (`driverPartitioning=auto`, the default): the query is 
executed with `executePartitioned` when the job starts, and each partition 
descriptor is read by a task with `readPartition`. Drivers that don't support 
it read in a single task.
   - Range partitioning on an integer column (`partitionColumn`, `lowerBound`, 
`upperBound`, `numPartitions`), like the JDBC data source.
   - Killing a task cancels its query with the driver.
   
   Writes:
   - `append` and `overwrite` (rows deleted with `DELETE FROM` first) through 
the driver's bulk ingestion, in batches of `batchsize` rows. Columns are 
matched by name and cast to the table's types. Each task writes in its own 
transaction if the driver supports transactions.
   
   Catalog (`AdbcTableCatalog`):
   - Namespaces are the database schemas of the connection's current catalog, 
listed with `getObjects`; a table without a namespace is in the current schema.
   - Reading, `INSERT`, `INSERT OVERWRITE`, `CREATE TABLE` (with bulk 
ingestion's create mode), `DROP TABLE`, `CREATE NAMESPACE` and `DROP NAMESPACE`.
   
   Only the standard ADBC database parameters (`uri`, `username`, `password`) 
and `jni.driver` are passed to the driver. Errors are new sub-conditions of 
`INVALID_ADBC_OPTIONS`, and `ADBC_SCHEMA_MISMATCH`.
   
   Not included, since they depend on work in ADBC or elsewhere: filter, limit 
and aggregate pushdown, Substrait plans, and partitioned writes.
   
   Known limitations, documented in `docs/sql-data-sources-adbc.md`:
   - Only the Arrow types that `ArrowUtils` maps are supported, so e.g. 
timestamps in milliseconds (returned by the JDBC bridge for `TIMESTAMP`), 
decimals of other widths than 128 bits and dictionary-encoded columns fail with 
`UNSUPPORTED_ARROWTYPE`.
   - ADBC doesn't say whether a partition descriptor can be read more than 
once. With driver partitioning, task retries and later actions on the same 
DataFrame read the same descriptors, so drivers whose descriptors can be read 
only once should use `driverPartitioning=none`.
   - There is no transaction across tasks, and `overwrite` deletes the rows 
before the tasks run, as the JDBC data source truncates the table.
   - The JDBC bridge driver puts the ingestion table name into its SQL unquoted 
and doesn't support the target schema option, so it can only write to tables in 
the current schema whose names need no quoting.
   - The PostgreSQL driver reads `NUMERIC` as strings, so writing to `NUMERIC` 
columns fails.
   
   ### Why are the changes needed?
   
   See the SPIP: ADBC drivers return query results as Arrow, which Spark can 
read as columnar batches without converting rows, and they give access to 
databases and services that have ADBC drivers but no JDBC driver, or whose JDBC 
drivers are slow for bulk reads.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A new `adbc` data source, a new `AdbcTableCatalog` catalog, and their 
documentation page. The new dependencies are `adbc-core` and 
`adbc-driver-manager` 0.25.0; drivers are added by users.
   
   ### How was this patch tested?
   
   New test suites `AdbcDataSourceSuite`, `AdbcWriteSuite` and 
`AdbcTableCatalogSuite`, using an H2 database through the ADBC JDBC bridge 
driver (test dependency), and test drivers that wrap it to fake other driver 
behaviour: partitioned execution, reported quote strings, blocking queries for 
cancellation, drivers that quote ingestion table names, and unreadable types.
   
   It was also checked manually against PostgreSQL 18 in Docker with the native 
PostgreSQL ADBC driver through the JNI driver: reads of all common types, 
pruning, range partitioning, appends and overwrites from several tasks, the 
catalog, and cancellation of a running query.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to