Quickstart¶
Here we’ll briefly tour using ADBC with the DataFusion driver.
Installation¶
Add a dependency on adbc_core
and adbc_datafusion
:
cargo add adbc_core adbc_datafusion
Loading DataFusion¶
Create a driver instance, then a database handle, and then finally a connection. (This is a bit redundant for something like DataFusion, but the intent is that the database handle can hold shared state that multiple connections can share.)
// These traits must be in scope
use adbc_core::{Connection, Database, Driver, Statement};
let mut driver = adbc_datafusion::DataFusionDriver {};
let db = driver.new_database().expect("Failed to create database handle");
let mut conn = db.new_connection().expect("Failed to create connection");
Running Queries¶
To run queries, we can create a statement and set a query:
let mut stmt = conn.new_statement().expect("Failed to create statement");
stmt.set_sql_query("SELECT 1").expect("Failed to set SQL query");
We can then execute the query to get an Arrow RecordBatchReader
:
let reader = stmt.execute().expect("Failed to execute statement");
for batch in reader {
let batch = batch.expect("Failed to read batch");
println!("{:?}", batch);
}