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 extensionINSTALL adbc FROM community;LOAD adbc;-- Read from an ADBC database (SQLite) with read_adbc given an ADBC connection profile URI and a SQL queryD SELECT * FROM read_adbc('profile://mydb', 'SELECT * FROM games');┌───────┬────────────┬─────────────────────┬─────────┬─────────┬─────────────┬─────────────┬────────────┐│ id │ name │ inventor │ year │ min_age │ min_players │ max_players │ list_price ││ int64 │ varchar │ varchar │ varchar │ int64 │ int64 │ int64 │ varchar │├───────┼────────────┼─────────────────────┼─────────┼─────────┼─────────────┼─────────────┼────────────┤│ 1 │ Monopoly │ Elizabeth Magie │ 1903 │ 8 │ 2 │ 6 │ 19.99 ││ 2 │ Scrabble │ Alfred Mosher Butts │ 1938 │ 8 │ 2 │ 4 │ 17.99 ││ 3 │ Clue │ Anthony E. Pratt │ 1944 │ 8 │ 2 │ 6 │ 9.99 ││ 4 │ Candy Land │ Eleanor Abbott │ 1948 │ 3 │ 2 │ 4 │ 7.99 ││ 5 │ Risk │ Albert Lamorisse │ 1957 │ 10 │ 2 │ 5 │ 29.99 │└───────┴────────────┴─────────────────────┴─────────┴─────────┴─────────────┴─────────────┴────────────┘-- Create a table function macro to avoid retyping the connection profile URI each timeD CREATE MACRO read_mydb(query) AS TABLE SELECT * FROM read_adbc('profile://mydb', query);-- Create a persistent connection to the ADBC database via ATTACHD 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 schemaD USE mydb.main;-- Display all tables in the attached ADBC databaseD SHOW ALL TABLES;┌──────────┬─────────┬─────────┬───────────────────────────────┬────────────────────────────────┬───────────┐│ database │ schema │ name │ column_names │ column_types │ temporary ││ varchar │ varchar │ varchar │ varchar[] │ 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 │ varchar │ varchar │ varchar │ int64 │ int64 │ int64 │ varchar │├───────┼────────────┼─────────────────────┼─────────┼─────────┼─────────────┼─────────────┼────────────┤│ 1 │ Monopoly │ Elizabeth Magie │ 1903 │ 8 │ 2 │ 6 │ 19.99 ││ 2 │ Scrabble │ Alfred Mosher Butts │ 1938 │ 8 │ 2 │ 4 │ 17.99 ││ 3 │ Clue │ Anthony E. Pratt │ 1944 │ 8 │ 2 │ 6 │ 9.99 ││ 4 │ Candy Land │ Eleanor Abbott │ 1948 │ 3 │ 2 │ 4 │ 7.99 ││ 5 │ Risk │ Albert Lamorisse │ 1957 │ 10 │ 2 │ 5 │ 29.99 │└───────┴────────────┴─────────────────────┴─────────┴─────────┴─────────────┴─────────────┴────────────┘-- Insert into the ADBC databaseD 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 │ varchar │ varchar │ varchar │ int64 │ int64 │ int64 │ varchar │├───────┼────────────┼──────────────────────┼─────────┼─────────┼─────────────┼─────────────┼────────────┤│ 1 │ Monopoly │ Elizabeth Magie │ 1903 │ 8 │ 2 │ 6 │ 19.99 ││ 2 │ Scrabble │ Alfred Mosher Butts │ 1938 │ 8 │ 2 │ 4 │ 17.99 ││ 3 │ Clue │ Anthony E. Pratt │ 1944 │ 8 │ 2 │ 6 │ 9.99 ││ 4 │ Candy Land │ Eleanor Abbott │ 1948 │ 3 │ 2 │ 4 │ 7.99 ││ 5 │ Risk │ Albert Lamorisse │ 1957 │ 10 │ 2 │ 5 │ 29.99 ││ 6 │ Battleship │ Clifford Von Wickler │ 1931 │ 7 │ 2 │ 2 │ 12.99 │└───────┴────────────┴──────────────────────┴─────────┴─────────┴─────────────┴─────────────┴────────────┘-- Create a local table in DuckDB of the inventors of each gameD CREATE TABLE memory.inventors AS (SELECT id, inventor FROM games);-- Create a new table in the attached ADBC database (SQLite) of the inventorsD 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_executeD CALL adbc_execute('profile://mydb', 'DROP TABLE games');┌─────────┐│ Success ││ boolean │├─────────┤│ true │└─────────┘-- Clear local metadata cache after remote schema changesD 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:
- 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.
- Interoperabilität mit einem großen und wachsenden Ökosystem Arrow-kompatibler Systeme.
Wesentliche Fähigkeiten
- Unterstützt Katalogabfragen sowie
SELECT-,INSERT-,COPY- undCREATE 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,COPYund CTAS, sodass der Speicherbedarf auch bei Datenmengen über dem Hauptspeicher gering bleibt (einstellbar überadbc_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_writeserlaubt. 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 | [] |