use std::{collections::HashMap, sync::Arc};
use datafusion::prelude::SessionContext;
use datafusion::sql::TableReference;
use datafusion_table_providers::{
odbc::ODBCTableFactory, sql::db_connection_pool::odbcpool::ODBCPool,
util::secrets::to_secret_map,
};
#[tokio::main]
async fn main() {
let params = to_secret_map(HashMap::from([(
"connection_string".to_owned(),
"driver=SQLite3;database=core/examples/sqlite_example.db;".to_owned(),
)]));
let odbc_pool =
Arc::new(ODBCPool::new(params).expect("unable to create SQLite ODBC connection pool"));
let table_factory = ODBCTableFactory::new(odbc_pool.clone());
let ctx = SessionContext::new();
ctx.register_table(
"companies_v2",
table_factory
.table_provider(TableReference::bare("companies"), None)
.await
.expect("failed to register table provider"),
)
.expect("failed to register table");
let df = ctx
.sql("SELECT * FROM datafusion.public.companies_v2")
.await
.expect("select failed");
df.show().await.expect("show failed");
}