Skip to content

Commit 1e4a8e7

Browse files
committed
fix: support driver manifest use, and adbc_scan batch size hints
1 parent 9083486 commit 1e4a8e7

File tree

6 files changed

+326
-239
lines changed

6 files changed

+326
-239
lines changed

CLAUDE.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,41 @@ There is also a checkout of the Airport DuckDB extension under ./airport. The Ai
1515
The extension provides the following functions:
1616

1717
### Connection Management
18-
- `adbc_connect(options)` - Connect to an ADBC data source. Returns a connection handle (BIGINT). Options can be passed as a STRUCT (preferred) or MAP. The `driver` option is required.
18+
- `adbc_connect(options)` - Connect to an ADBC data source. Returns a connection handle (BIGINT). Options can be passed as a STRUCT (preferred) or MAP.
19+
- **Required options:**
20+
- `driver` - Driver name, path to shared library, or path to manifest file (.toml)
21+
- **Optional options:**
22+
- `entrypoint` - Custom entry point function name
23+
- `search_paths` - Additional paths to search for driver manifests (colon-separated on Unix, semicolon on Windows)
24+
- `use_manifests` - Enable/disable manifest search (default: 'true'). Set to 'false' to only use direct library paths.
25+
- Other options are passed directly to the ADBC driver
1926
- `adbc_disconnect(handle)` - Disconnect from an ADBC data source. Returns true on success.
2027

28+
#### Driver Manifest Support
29+
The extension supports ADBC driver manifests, which allow referencing drivers by name instead of full paths. When `use_manifests` is enabled (default), the driver manager searches for manifests in these locations:
30+
31+
**macOS/Linux:**
32+
1. `ADBC_DRIVER_PATH` environment variable (colon-separated paths)
33+
2. `$VIRTUAL_ENV/etc/adbc/drivers` (if in a virtual environment)
34+
3. `$CONDA_PREFIX/etc/adbc/drivers` (if in a Conda environment)
35+
4. `~/.config/adbc/drivers` (Linux) or `~/Library/Application Support/ADBC/Drivers` (macOS)
36+
5. `/etc/adbc/drivers`
37+
38+
**Windows:**
39+
1. `ADBC_DRIVER_PATH` environment variable (semicolon-separated paths)
40+
2. Registry: `HKEY_CURRENT_USER\SOFTWARE\ADBC\Drivers\{name}`
41+
3. `%LOCAL_APPDATA%\ADBC\Drivers`
42+
4. Registry: `HKEY_LOCAL_MACHINE\SOFTWARE\ADBC\Drivers\{name}`
43+
44+
A manifest file is a TOML file (e.g., `sqlite.toml`) containing driver metadata and the path to the shared library.
45+
2146
### Transaction Control
2247
- `adbc_set_autocommit(handle, enabled)` - Enable or disable autocommit mode. When disabled, changes require explicit commit.
2348
- `adbc_commit(handle)` - Commit the current transaction.
2449
- `adbc_rollback(handle)` - Rollback the current transaction, discarding all uncommitted changes.
2550

2651
### Query Execution
27-
- `adbc_scan(handle, query, [params := row(...)])` - Execute a SELECT query and return results as a table. Supports parameterized queries via the optional `params` named parameter.
52+
- `adbc_scan(handle, query, [params := row(...)], [batch_size := N])` - Execute a SELECT query and return results as a table. Supports parameterized queries via the optional `params` named parameter. The optional `batch_size` parameter hints to the driver how many rows to return per batch (default: driver-specific, typically 2048). This is a best-effort hint that may be ignored by drivers that don't support it.
2853
- `adbc_execute(handle, query)` - Execute DDL/DML statements (CREATE, INSERT, UPDATE, DELETE). Returns affected row count.
2954
- `adbc_insert(handle, table_name, <table>, [mode := ...])` - Bulk insert data from a subquery. Modes: 'create', 'append', 'replace', 'create_append'.
3055

@@ -38,15 +63,24 @@ The extension provides the following functions:
3863
### Example Usage
3964

4065
```sql
41-
-- Connect to SQLite (driver path varies by installation)
66+
-- Connect using a driver manifest (if sqlite.toml is installed in a search path)
67+
SET VARIABLE conn = (SELECT adbc_connect({'driver': 'sqlite', 'uri': ':memory:'}));
68+
69+
-- Connect with explicit driver path (traditional method)
4270
SET VARIABLE conn = (SELECT adbc_connect({'driver': '/path/to/libadbc_driver_sqlite.dylib', 'uri': ':memory:'}));
4371

72+
-- Connect with additional search paths
73+
SET VARIABLE conn = (SELECT adbc_connect({'driver': 'sqlite', 'uri': ':memory:', 'search_paths': '/opt/adbc/drivers'}));
74+
4475
-- Query data
4576
SELECT * FROM adbc_scan(getvariable('conn')::BIGINT, 'SELECT 1 AS a, 2 AS b');
4677

4778
-- Parameterized query
4879
SELECT * FROM adbc_scan(getvariable('conn')::BIGINT, 'SELECT ? AS value', params := row(42));
4980

81+
-- Query with batch size hint (for network drivers, larger batches reduce round-trips)
82+
SELECT * FROM adbc_scan(getvariable('conn')::BIGINT, 'SELECT * FROM large_table', batch_size := 65536);
83+
5084
-- Execute DDL/DML
5185
SELECT adbc_execute(getvariable('conn')::BIGINT, 'CREATE TABLE test (id INTEGER, name TEXT)');
5286
SELECT adbc_execute(getvariable('conn')::BIGINT, 'INSERT INTO test VALUES (1, ''hello'')');
@@ -103,10 +137,12 @@ make test
103137
# Run debug tests
104138
make test_debug
105139

106-
# Run tests with SQLite driver (requires ADBC_SQLITE_DRIVER env var)
107-
ADBC_SQLITE_DRIVER="/path/to/libadbc_driver_sqlite.dylib" make test
140+
# Run tests with SQLite driver (requires both environment variables)
141+
HAS_ADBC_SQLITE_DRIVER=1 make test
108142
```
109143

144+
**Note:** Tests that use the SQLite ADBC driver require the `HAS_ADBC_SQLITE_DRIVER` environment variable to be set (to any value) in addition to `ADBC_SQLITE_DRIVER` pointing to the driver library path.
145+
110146
Tests are written as [SQLLogicTests](https://duckdb.org/dev/sqllogictest/intro.html) in `test/sql/`.
111147

112148
## Build Outputs

docs/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -408,28 +408,29 @@ Output:
408408

409409
ADBC drivers are available for many databases. Here are some common ones:
410410

411-
| Database | Driver | Notes |
412-
|----------|--------|-------|
413-
| SQLite | `libadbc_driver_sqlite.dylib` | Lightweight, file-based |
414-
| PostgreSQL | `libadbc_driver_postgresql.dylib` | Full-featured RDBMS |
415-
| Snowflake | `libadbc_driver_snowflake.dylib` | Cloud data warehouse |
416-
| Flight SQL | `libadbc_driver_flightsql.dylib` | Arrow Flight SQL servers |
417-
| DuckDB | `libadbc_driver_duckdb.dylib` | Connect to other DuckDB instances |
411+
`bigquery` - An ADBC driver for Google BigQuery developed by the ADBC Driver Foundry
412+
`duckdb` - An ADBC driver for DuckDB developed by the DuckDB Foundation - **but this would be kind of silly to use in DuckDB**.
413+
`flightsql` - An ADBC driver for Apache Arrow Flight SQL developed under the Apache Software Foundation
414+
`mssql` - An ADBC driver for Microsoft SQL Server developed by Columnar
415+
`mysql` - An ADBC Driver for MySQL developed by the ADBC Driver Foundry
416+
`postgresql` - An ADBC driver for PostgreSQL developed under the Apache Software Foundation
417+
`redshift` - An ADBC driver for Amazon Redshift developed by Columnar
418+
`snowflake` - An ADBC driver for Snowflake developed under the Apache Software Foundation
419+
`sqlite` - An ADBC driver for SQLite developed under the Apache Software Foundation
418420

419421
### Installing Drivers
420422

421-
ADBC drivers can be installed from the [Apache Arrow ADBC releases](https://github.com/apache/arrow-adbc/releases) or built from source.
423+
There are a few options for installing drivers:
422424

423-
On macOS with Homebrew:
424-
```bash
425-
brew install apache-arrow-adbc
426-
```
425+
1. [Columnar's `dbc`](https://columnar.tech/dbc/) is a command-line tool that makes installing and managing ADBC drivers easy.
426+
2. ADBC drivers can be installed from the [Apache Arrow ADBC releases](https://github.com/apache/arrow-adbc/releases) or built from source.
427+
3. On macOS with Homebrew: ```brew install apache-arrow-adbc```
427428

428429
## Complete Example
429430

430431
```sql
431432
-- Load the extension
432-
LOAD adbc;
433+
LOAD adbc_scanner;
433434

434435
-- Connect to SQLite
435436
SET VARIABLE sqlite_conn = (SELECT adbc_connect({
@@ -502,7 +503,6 @@ SELECT adbc_connect({'uri': ':memory:'});
502503
- ADBC connections are not automatically closed; always call `adbc_disconnect()` when done
503504
- The `rows_affected` count from `adbc_execute` depends on driver support; some drivers return 0 for all operations
504505
- Parameterized queries in `adbc_scan` require the `params` named parameter syntax
505-
- Connection handles are process-global; be careful with concurrent access from multiple threads
506506

507507
## Building from Source
508508

0 commit comments

Comments
 (0)