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 ballista support an optional feature to datafusion-cli #1816

Merged
merged 3 commits into from
Feb 15, 2022
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: 9 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion datafusion-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
43 changes: 35 additions & 8 deletions datafusion-cli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand All @@ -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!()
}
}