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
Note
If you get a compiler error (E0308, mismatched types) and a note about
multiple versions of the arrow crates in the dependency graph when you
run cargo build, you can downgrade crate versions so you only have
one version of the arrow crates in your workspace:
cargo update -p arrow-array@57.0.0 -p arrow-schema@57.0.0 --precise 56.2.0
Note the exact versions in the command above may need to be changed.
Use cargo tree to find the versions affecting your workspace. See
the Version Incompatibility Hazards
in the Cargo documentation for more information.
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);
}