Skip to content

Apache DataFusion SQL Query Engine

Make ballista support an optional feature to datafusion-cli (#1816)

Andrew Lamb7a2cbd5500c1
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 046309c714..5919f35125 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -70,12 +70,20 @@ jobs:
env:
CARGO_HOME: "/github/home/.cargo"
CARGO_TARGET_DIR: "/github/home/target/release"
- - name: Check DataFusion Build without default features
+ - name: Check DataFusion builds without default features
run: |
cargo check --no-default-features -p datafusion
env:
CARGO_HOME: "/github/home/.cargo"
CARGO_TARGET_DIR: "/github/home/target"
+ - name: Check DataFusion CLI builds with ballista
+ run: |
+ cargo check -p datafusion-cli
+ cargo check --no-default-features -p datafusion-cli
+ cargo check --features=ballista -p datafusion-cli
+ env:
+ CARGO_HOME: "/github/home/.cargo"
+ CARGO_TARGET_DIR: "/github/home/target"
# test the crate
linux-test:
diff --git a/datafusion-cli/Cargo.toml b/datafusion-cli/Cargo.toml
index 448c854d9d..0f80f28e8f 100644
--- a/datafusion-cli/Cargo.toml
+++ b/datafusion-cli/Cargo.toml
@@ -33,5 +33,5 @@ rustyline = "9.0"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "parking_lot"] }
datafusion = { path = "../datafusion", version = "7.0.0" }
arrow = { version = "9.0.0" }
-ballista = { path = "../ballista/rust/client", version = "0.6.0" }
+ballista = { path = "../ballista/rust/client", version = "0.6.0", optional=true }
env_logger = "0.9"
\ No newline at end of file
diff --git a/datafusion-cli/src/context.rs b/datafusion-cli/src/context.rs
index 6e46b9b044..0b746afa36 100644
--- a/datafusion-cli/src/context.rs
+++ b/datafusion-cli/src/context.rs
@@ -17,8 +17,6 @@
//! Context (remote or local)
-use ballista::context::BallistaContext;
-use ballista::prelude::BallistaConfig;
use datafusion::dataframe::DataFrame;
use datafusion::error::{DataFusionError, Result};
use datafusion::execution::context::{ExecutionConfig, ExecutionContext};
@@ -28,18 +26,14 @@ use std::sync::Arc;
pub enum Context {
/// In-process execution with DataFusion
Local(ExecutionContext),
- /// Distributed execution with Ballista
+ /// Distributed execution with Ballista (if available)
Remote(BallistaContext),
}
impl Context {
/// create a new remote context with given host and port
pub fn new_remote(host: &str, port: u16) -> Result<Context> {
- let config: BallistaConfig = BallistaConfig::new()
- .map_err(|e| DataFusionError::Execution(format!("{:?}", e)))?;
- Ok(Context::Remote(BallistaContext::remote(
- host, port, &config,
- )))
+ Ok(Context::Remote(BallistaContext::try_new(host, port)?))
}
/// create a local context using the given config
@@ -55,3 +49,36 @@ impl Context {
}
}
}
+
+// implement wrappers around the BallistaContext to support running without ballista
+
+#[cfg(feature = "ballista")]
+pub struct BallistaContext(ballista::context::BallistaContext);
+#[cfg(feature = "ballista")]
+impl BallistaContext {
+ pub fn try_new(host: &str, port: u16) -> Result<Self> {
+ use ballista::context::BallistaContext;
+ use ballista::prelude::BallistaConfig;
+ let config: BallistaConfig = BallistaConfig::new()
+ .map_err(|e| DataFusionError::Execution(format!("{:?}", e)))?;
+ Ok(Self(BallistaContext::remote(host, port, &config)))
+ }
+ pub async fn sql(&mut self, sql: &str) -> Result<Arc<dyn DataFrame>> {
+ self.0.sql(sql).await
+ }
+}
+
+#[cfg(not(feature = "ballista"))]
+pub struct BallistaContext();
+#[cfg(not(feature = "ballista"))]
+impl BallistaContext {
+ pub fn try_new(_host: &str, _port: u16) -> Result<Self> {
+ Err(DataFusionError::NotImplemented(
+ "Remote execution not supported. Compile with feature 'ballista' to enable"
+ .to_string(),
+ ))
+ }
+ pub async fn sql(&mut self, _sql: &str) -> Result<Arc<dyn DataFrame>> {
+ unreachable!()
+ }
+}