adbc

Verbindet DuckDB mit jeder Datenbank, die über einen Arrow Database Connectivity (ADBC)-Treiber verfügt.

Maintainer: columnar-tech

Installation und Laden

INSTALL adbc FROM community;
LOAD adbc;

Beispiel

-- Install and load the ADBC extension
INSTALL adbc FROM community;
LOAD adbc;
-- Read from an ADBC database (SQLite) with read_adbc given an ADBC connection profile URI and a SQL query
D SELECT * FROM read_adbc('profile://mydb', 'SELECT * FROM games');
┌───────┬────────────┬─────────────────────┬─────────┬─────────┬─────────────┬─────────────┬────────────┐
│ id │ name │ inventor │ year │ min_age │ min_players │ max_players │ list_price │
│ int64 │ varcharvarcharvarchar │ int64 │ int64 │ int64 │ varchar
├───────┼────────────┼─────────────────────┼─────────┼─────────┼─────────────┼─────────────┼────────────┤
1 │ Monopoly │ Elizabeth Magie │ 190382619.99
2 │ Scrabble │ Alfred Mosher Butts │ 193882417.99
3 │ Clue │ Anthony E. Pratt │ 19448269.99
4 │ Candy Land │ Eleanor Abbott │ 19483247.99
5 │ Risk │ Albert Lamorisse │ 1957102529.99
└───────┴────────────┴─────────────────────┴─────────┴─────────┴─────────────┴─────────────┴────────────┘
-- Create a table function macro to avoid retyping the connection profile URI each time
D CREATE MACRO read_mydb(query) AS TABLE SELECT * FROM read_adbc('profile://mydb', query);
-- Create a persistent connection to the ADBC database via ATTACH
D ATTACH 'profile://mydb' AS mydb (TYPE adbc);
-- Alternatively, ATTACH with a custom delimiter (i.e., SELECT * FROM [schema].[table] for SQL Server)
D ATTACH 'profile://mydb' AS otherdb (TYPE adbc, DELIMITER '[]');
-- Set the default schema
D USE mydb.main;
-- Display all tables in the attached ADBC database
D SHOW ALL TABLES;
┌──────────┬─────────┬─────────┬───────────────────────────────┬────────────────────────────────┬───────────┐
databaseschemaname │ column_names │ column_types │ temporary │
varcharvarcharvarcharvarchar[] │ varchar[] │ boolean
├──────────┼─────────┼─────────┼───────────────────────────────┼────────────────────────────────┼───────────┤
│ mydb │ main │ games │ [id, name, inventor, year, │ [BIGINT, VARCHAR, VARCHAR, │ false │
│ │ │ │ min_age, min_players, │ VARCHAR, BIGINT, BIGINT, │ │
│ │ │ │ max_players, list_price] │ BIGINT, VARCHAR] │ │
└──────────┴─────────┴─────────┴───────────────────────────────┴────────────────────────────────┴───────────┘
-- Read directly from the attached ADBC table (no projection or predicate pushdown, use read_adbc for that)
D SELECT * FROM games;
┌───────┬────────────┬─────────────────────┬─────────┬─────────┬─────────────┬─────────────┬────────────┐
│ id │ name │ inventor │ year │ min_age │ min_players │ max_players │ list_price │
│ int64 │ varcharvarcharvarchar │ int64 │ int64 │ int64 │ varchar
├───────┼────────────┼─────────────────────┼─────────┼─────────┼─────────────┼─────────────┼────────────┤
1 │ Monopoly │ Elizabeth Magie │ 190382619.99
2 │ Scrabble │ Alfred Mosher Butts │ 193882417.99
3 │ Clue │ Anthony E. Pratt │ 19448269.99
4 │ Candy Land │ Eleanor Abbott │ 19483247.99
5 │ Risk │ Albert Lamorisse │ 1957102529.99
└───────┴────────────┴─────────────────────┴─────────┴─────────┴─────────────┴─────────────┴────────────┘
-- Insert into the ADBC database
D INSERT INTO games (SELECT 6, 'Battleship', 'Clifford Von Wickler', 1931, 7, 2, 2, 12.99);
D SELECT * FROM games;
┌───────┬────────────┬──────────────────────┬─────────┬─────────┬─────────────┬─────────────┬────────────┐
│ id │ name │ inventor │ year │ min_age │ min_players │ max_players │ list_price │
│ int64 │ varcharvarcharvarchar │ int64 │ int64 │ int64 │ varchar
├───────┼────────────┼──────────────────────┼─────────┼─────────┼─────────────┼─────────────┼────────────┤
1 │ Monopoly │ Elizabeth Magie │ 190382619.99
2 │ Scrabble │ Alfred Mosher Butts │ 193882417.99
3 │ Clue │ Anthony E. Pratt │ 19448269.99
4 │ Candy Land │ Eleanor Abbott │ 19483247.99
5 │ Risk │ Albert Lamorisse │ 1957102529.99
6 │ Battleship │ Clifford Von Wickler │ 193172212.99
└───────┴────────────┴──────────────────────┴─────────┴─────────┴─────────────┴─────────────┴────────────┘
-- Create a local table in DuckDB of the inventors of each game
D CREATE TABLE memory.inventors AS (SELECT id, inventor FROM games);
-- Create a new table in the attached ADBC database (SQLite) of the inventors
D CREATE TABLE game_inventors(id, inventor) AS (SELECT * FROM memory.inventors);
D SELECT * FROM game_inventors;
┌───────┬──────────────────────┐
│ id │ inventor │
│ int64 │ varchar
├───────┼──────────────────────┤
1 │ Elizabeth Magie │
2 │ Alfred Mosher Butts │
3 │ Anthony E. Pratt │
4 │ Eleanor Abbott │
5 │ Albert Lamorisse │
6 │ Clifford Von Wickler │
└───────┴──────────────────────┘
-- Execute arbitrary DDL via adbc_execute
D CALL adbc_execute('profile://mydb', 'DROP TABLE games');
┌─────────┐
│ Success │
boolean
├─────────┤
│ true │
└─────────┘
-- Clear local metadata cache after remote schema changes
D CALL adbc_clear_cache();

Über adbc

Nutzen Sie DuckDB (v1.4.5+ oder v1.5.4+), um Snowflake, Databricks, BigQuery, PostgreSQL, MySQL oder jedes andere System mit einem ADBC-Treiber abzufragen. ADBC (Arrow Database Connectivity) ist eine universelle Datenzugriffs-API auf Basis von Apache Arrow, einem effizienten spaltenorientierten Datenformat, das fast jedes Datensystem nativ unterstützt. Durch die Nutzung von Arrow ermöglicht ADBC:

  1. Sehr schnellen (Zero-Copy-)Datentransfer zwischen spaltenorientierten analytischen Datenbanken, ohne die langsamen Spalten-zu-Zeilen- und Zeilen-zu-Spalten-Umwandlungen älterer zeilenbasierter APIs wie ODBC oder JDBC.
  2. Interoperabilität mit einem großen und wachsenden Ökosystem Arrow-kompatibler Systeme.

Wesentliche Fähigkeiten

  • Unterstützt Katalogabfragen sowie SELECT-, INSERT-, COPY- und CREATE TABLE AS-Anweisungen (CTAS) direkt auf angehängten Datenbanken.
  • Unterstützt benutzerdefinierte Trennzeichen mit ATTACH (z. B. DELIMITER '[]') für Systeme mit abweichenden Tabellen-/Schema-Trennzeichen.
  • Unterstützt eingebautes Connection Pooling für jede angehängte Datenbank (einstellbar über adbc_connection_pool_size)
  • Unterstützt streamingbasiertes Bulk-Ingest für INSERT, COPY und CTAS, sodass der Speicherbedarf auch bei Datenmengen über dem Hauptspeicher gering bleibt (einstellbar über adbc_insert_buffer_size).

Bekannte Einschränkungen

  • Arbeitet ausschließlich im Autocommit-Modus.
  • Predicate- und Projection-Pushdowns erfolgen für angehängte Tabellen nicht automatisch; verwenden Sie direkte read_adbc()-Abfragen, um Projektionen und Prädikate an entfernte ADBC-Datenbanken durchzureichen.
  • Gleichzeitige ADBC-Operationen innerhalb eines Prozesses werden nicht unterstützt. Das Mischen von ADBC-Lese- und Schreibvorgängen in derselben SQL-Anweisung ist standardmäßig ebenfalls eingeschränkt, sofern nicht ausdrücklich über adbc_mix_reads_writes erlaubt. Weitere Informationen finden Sie in der Dokumentation.

Hinzugefügte Funktionen

function_name function_type description comment examples
adbc_clear_cache table NULL NULL
adbc_execute table NULL NULL
read_adbc table NULL NULL

Überladene Funktionen

Diese Erweiterung fügt keine Funktionsüberladungen hinzu.

Hinzugefügte Typen

Diese Erweiterung fügt keine Typen hinzu.

Hinzugefügte Einstellungen

name description input_type scope aliases
adbc_connection_pool_size The number of connections (default 50) to pool (cache) before the catalog creates ephemeral connections to serve requests. BIGINT GLOBAL []
adbc_insert_buffer_size The number of chunks (default 1000) to buffer in memory before inserting via ADBC. BIGINT GLOBAL []
adbc_materialize_insert_rows Whether input rows for INSERTs are materialized before inserting via ADBC. BOOLEAN GLOBAL []
adbc_mix_reads_writes Whether ADBC reads and writes can be mixed within the same SQL statement (default false). BOOLEAN GLOBAL []