Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the datafusion-federation dependency optional #145

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ datafusion-expr = { version = "42.0.0", optional = true }
datafusion-physical-expr = { version = "42.0.0", optional = true }
datafusion-physical-plan = { version = "42.0.0", optional = true }
datafusion-proto = { version = "42.0.0", optional = true }
datafusion-federation = { version = "0.3.0", features = ["sql"] }
datafusion-federation = { version = "0.3.0", features = ["sql"], optional = true }
duckdb = { version = "1.1.1", features = [
"bundled",
"r2d2",
Expand Down Expand Up @@ -105,8 +105,10 @@ flight = [
"dep:serde",
"dep:tonic",
]
duckdb-federation = ["duckdb"]
sqlite-federation = ["sqlite"]
postgres-federation = ["postgres"]
federation = ["dep:datafusion-federation"]
duckdb-federation = ["duckdb", "federation"]
sqlite-federation = ["sqlite", "federation"]
postgres-federation = ["postgres", "federation"]
mysql-federation = ["mysql", "federation"]


1 change: 1 addition & 0 deletions src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl MySQLTableFactory {
.context(UnableToConstructSQLTableSnafu)?,
);

#[cfg(feature = "mysql-federation")]
let table_provider = Arc::new(
table_provider
.create_federated_table_provider()
Expand Down
1 change: 1 addition & 0 deletions src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl PostgresTableFactory {
.map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)?,
);

#[cfg(feature = "postgres-federation")]
let table_provider = Arc::new(
table_provider
.create_federated_table_provider()
Expand Down
1 change: 1 addition & 0 deletions src/sql/sql_provider_datafusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use datafusion::{
sql::{unparser::Unparser, TableReference},
};

#[cfg(feature = "federation")]
pub mod federation;

#[derive(Debug, Snafu)]
Expand Down
3 changes: 3 additions & 0 deletions tests/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use datafusion::execution::context::SessionContext;
use datafusion::logical_expr::CreateExternalTable;
use datafusion::physical_plan::collect;
use datafusion::physical_plan::memory::MemoryExec;
#[cfg(feature = "postgres-federation")]
use datafusion_federation::schema_cast::record_convert::try_cast_to;

use datafusion_table_providers::{
Expand Down Expand Up @@ -76,13 +77,15 @@ async fn arrow_postgres_round_trip(
record_batch[0].columns()
);

#[cfg(feature = "postgres-federation")]
let casted_result =
try_cast_to(record_batch[0].clone(), source_schema).expect("Failed to cast record batch");

// Check results
assert_eq!(record_batch.len(), 1);
assert_eq!(record_batch[0].num_rows(), arrow_record.num_rows());
assert_eq!(record_batch[0].num_columns(), arrow_record.num_columns());
#[cfg(feature = "postgres-federation")]
assert_eq!(arrow_record, casted_result);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::arrow_record_batch_gen::*;
use arrow::array::RecordBatch;
use arrow::datatypes::SchemaRef;
use datafusion::execution::context::SessionContext;
#[cfg(feature = "sqlite-federation")]
use datafusion_federation::schema_cast::record_convert::try_cast_to;
use datafusion_table_providers::sql::arrow_sql_gen::statement::{
CreateTableBuilder, InsertBuilder,
Expand Down Expand Up @@ -68,6 +69,7 @@ async fn arrow_sqlite_round_trip(

let record_batch = df.collect().await.expect("RecordBatch should be collected");

#[cfg(feature = "sqlite-federation")]
let casted_record = try_cast_to(record_batch[0].clone(), source_schema).unwrap();

tracing::debug!("Original Arrow Record Batch: {:?}", arrow_record.columns());
Expand All @@ -80,6 +82,7 @@ async fn arrow_sqlite_round_trip(
assert_eq!(record_batch.len(), 1);
assert_eq!(record_batch[0].num_rows(), arrow_record.num_rows());
assert_eq!(record_batch[0].num_columns(), arrow_record.num_columns());
#[cfg(feature = "sqlite-federation")]
assert_eq!(casted_record, arrow_record);
}

Expand Down