Apache DataFusion Ballista Distributed Query Engine

Clone this repo:
  1. ab9e19e chore(deps): bump bytes from 1.11.0 to 1.11.1 (#1443) by dependabot[bot] · 6 hours ago main
  2. 05014c2 chore(deps): bump criterion from 0.8.1 to 0.8.2 (#1442) by dependabot[bot] · 10 hours ago
  3. c09853e chore(deps): bump clap from 4.5.56 to 4.5.57 (#1441) by dependabot[bot] · 18 hours ago
  4. b6e3747 chore(deps): bump aws-config from 1.8.12 to 1.8.13 (#1440) by dependabot[bot] · 19 hours ago
  5. 68bee68 chore(deps): bump bytes from 1.11.0 to 1.11.1 in /python (#1439) by dependabot[bot] · 2 days ago

Ballista: Making DataFusion Applications Distributed

Apache licensed

Ballista is a distributed query execution engine that enhances Apache DataFusion by enabling the parallelized execution of workloads across multiple nodes in a distributed environment.

Existing DataFusion application:

use datafusion::prelude::*;

#[tokio::main]
async fn main() -> datafusion::error::Result<()> {
  let ctx = SessionContext::new();

  // register the table
  ctx.register_csv("example", "tests/data/example.csv", CsvReadOptions::new())
      .await?;

  // create a plan to run a SQL query
  let df = ctx
      .sql("SELECT a, MIN(b) FROM example WHERE a <= b GROUP BY a LIMIT 100")
      .await?;

  // execute and print results
  df.show().await?;
  Ok(())
}

can be distributed with few lines of code changed:

[!IMPORTANT]
There is a gap between DataFusion and Ballista, which may bring incompatibilities. The community is actively working to close the gap

use ballista::prelude::*;
use datafusion::prelude::*;

#[tokio::main]
async fn main() -> datafusion::error::Result<()> {
    // create SessionContext with ballista support
    // standalone context will start all required
    // ballista infrastructure in the background as well
    let ctx = SessionContext::standalone().await?;

    // everything else remains the same

    // register the table
    ctx.register_csv("example", "tests/data/example.csv", CsvReadOptions::new())
        .await?;

    // create a plan to run a SQL query
    let df = ctx
        .sql("SELECT a, MIN(b) FROM example WHERE a <= b GROUP BY a LIMIT 100")
        .await?;

    // execute and print results
    df.show().await?;
    Ok(())
}

For documentation or more examples, please refer to the Ballista User Guide.

Architecture

A Ballista cluster consists of one or more scheduler processes and one or more executor processes. These processes can be run as native binaries and are also available as Docker Images, which can be easily deployed with Docker Compose or Kubernetes.

The following diagram shows the interaction between clients and the scheduler for submitting jobs, and the interaction between the executor(s) and the scheduler for fetching tasks and reporting task status.

Ballista Cluster Diagram

See the architecture guide for more details.

Performance

We run some simple benchmarks comparing Ballista with Apache Spark to track progress with performance optimizations. These are benchmarks derived from TPC-H and not official TPC-H benchmarks. These results are from running individual queries at scale factor 100 (100 GB) on a single node with a single executor and 8 concurrent tasks.

Overall Speedup

The overall speedup is 2.9x

benchmarks

Per Query Comparison

benchmarks

Relative Speedup

benchmarks

Absolute Speedup

benchmarks

Getting Started

The easiest way to get started is to run one of the standalone or distributed examples. After that, refer to the Getting Started Guide.

Cargo Features

Ballista uses Cargo features to enable optional functionality. Below are the available features for each crate.

ballista (client)

FeatureDefaultDescription
standaloneYesEnables standalone mode with in-process scheduler and executor

ballista-core

FeatureDefaultDescription
arrow-ipc-optimizationsYesEnables Arrow IPC optimizations for better shuffle performance
spark-compatNoEnables Spark compatibility mode via datafusion-spark
build-binaryNoRequired for building binary executables (AWS S3 support, CLI parsing)
force_hash_collisionsNoTesting-only: forces all values to hash to same value

ballista-scheduler

FeatureDefaultDescription
build-binaryYesBuilds the scheduler binary with CLI and logging
substraitYesEnables Substrait plan support
prometheus-metricsNoEnables Prometheus metrics collection
graphviz-supportNoEnables execution graph visualization
spark-compatNoEnables Spark compatibility mode
keda-scalerNoKubernetes Event Driven Autoscaling integration
rest-apiNoEnables REST API endpoints
disable-stage-plan-cacheNoDisables caching of stage execution plans

ballista-executor

FeatureDefaultDescription
arrow-ipc-optimizationsYesEnables Arrow IPC optimizations
build-binaryYesBuilds the executor binary with CLI and logging
mimallocYesUses mimalloc memory allocator for better performance
spark-compatNoEnables Spark compatibility mode

Usage Examples

# Build with standalone support (default)
cargo build -p ballista

# Build with Substrait support
cargo build -p ballista-scheduler --features substrait

# Build with Spark compatibility
cargo build -p ballista-executor --features spark-compat

Project Status

Ballista supports a wide range of SQL, including CTEs, Joins, and subqueries and can execute complex queries at scale, but still there is a gap between DataFusion and Ballista which we want to bridge in near future.

Refer to the DataFusion SQL Reference for more information on supported SQL.

Contribution Guide

Please see the Contribution Guide for information about contributing to Ballista.