libbigdata

A pure-Dart library for big-data manipulation: a DataFrame API and an in-memory SQL query engine, inspired by pandas and DuckDB, with native readers and writers for the common columnar and table formats. No native dependencies.

Features

  • DataFrame API: chainable select / filter / orderBy / groupBy / agg / join / withColumn, evaluated on a columnar engine.
  • SQL engine: query DataFrames and files directly, e.g. SELECT * FROM 'data.parquet' WHERE x > 10, and change Delta and Iceberg tables in place with UPDATE, DELETE, INSERT and MERGE.
  • Storage: every reader, writer and table format runs over the local filesystem, memory, or S3-compatible object storage.
  • Formats: CSV, JSON / JSON Lines, Parquet, Arrow IPC (file and stream), Delta Lake, and Apache Iceberg, each read and written, with streaming/batch variants for out-of-core inputs.
  • Parquet codecs: Snappy, GZIP, ZSTD, LZ4 (LZ4_RAW read+write; Hadoop LZ4 read), plus optional page CRC32 integrity checks.

Install

dependencies:
  libbigdata: ^3.0.0
dart pub get

Quick start

DataFrame API

import 'package:libbigdata/libbigdata.dart';

Future<void> main() async {
  switch (await DataFrameIO.readCsv(Location.file('people.csv'))) {
    case Ok(value: final df):
      final adults = await df
          .filter('age >= 18')
          .select(['name', 'age', 'city'])
          .orderBy('age', ascending: false)
          .limit(10)
          .execute();
      if (adults case Ok(:final value)) print(value.toRows());
    case Err(:final error):
      print('could not read people.csv: $error');
  }
}

Grouping, joins, derived columns

final byCity = await df
    .groupBy(['city'])
    .agg({'age': 'avg', 'name': 'count'})
    .execute(); // Result<Table, ErrorDetails>

final joined = await orders
    .join(customers, 'customer_id', type: JoinType.left)
    .withColumn('total', 'price * quantity')
    .execute();

The filter and withColumn strings are SQL scalar expressions, as in a WHERE clause or a SELECT item. See doc/DATAFRAME.md for the details, and use the SQL engine for what the DataFrame API does not cover.

SQL

// Query a file directly, on a shared engine.
switch (await sql("SELECT city, count(*) FROM 'people.csv' GROUP BY city")) {
  case Ok(:final value):
    print(value.toRows());
  case Err(:final error) when error.kind == Kind.invalid:
    print('bad query: ${error.message}');
  case Err(:final error):
    print('query failed: $error');
}

// Or open an engine of your own, register a DataFrame and query it.
if (SqlEngine.open() case Ok(value: final engine)) {
  if (await engine.registerDataFrame('people', df) case Ok()) {
    final top = await engine.sql('SELECT name FROM people WHERE age > 30');
    print(top);
  }
  await engine.dispose();
}

Object storage

Every reader, writer and table format takes a storage:. S3Storage works with Amazon S3 and S3-compatible stores that support conditional writes (If-None-Match), such as SeaweedFS:

final s3 = S3Storage(
  region: 'us-east-1',
  credentials: const Credentials('AKIA...', 'secret'),
  endpoint: Uri.parse('http://localhost:9000'), // omit for AWS
  path: true, // path-style addressing, which most S3-compatible stores need
);
if (Location.parse('s3://lake/events') case Ok(value: final lake)) {
  final version = await DeltaWriter(lake, storage: s3).write(table);
  print(version); // Result<int, ErrorDetails>: the committed version

  // Untrusted SQL reaches only what is mounted.
  final engine = SqlEngine.open(mounts: [Mount(s3, lake)]);
}

Errors

Reads, writes, queries and commits return a Result<T, ErrorDetails>: Ok with the value, or Err with an ErrorDetails whose kind says what went wrong (invalid, missing, corrupt, limit, conflict, ...) and whose message says why. Nothing else escapes these methods; only argument preconditions (such as a batch size of 0) throw. Upgrading from an earlier version? See doc/MIGRATION.md.

Formats

Format Read Write Notes
CSV Yes Yes auto-inference, streaming batches
JSON / JSONL Yes Yes streaming batches (JSON Lines)
Parquet Yes Yes predicate/column pushdown, optional CRC32
Arrow IPC Yes Yes streaming batches
Delta Lake Yes Yes append/overwrite, delete/update/merge, time travel
Iceberg Yes Yes snapshots, time travel, delete/update/merge, partition transforms

For files larger than memory, use the streaming readers (readCsvBatches, readJsonBatches, readArrowBatches), the streaming Parquet writer (writeParquetStream), and SqlEngine.executeStream.

Documentation

Runnable examples live in example/.

Status

API under active development. 3.0 moved every path in the public API to a Location on a Storage, and 2.0 changed every fallible entry point to return a Result; see doc/MIGRATION.md. Contributions and bug reports welcome at github.com/libdbm/libbigdata.

License

BSD 3-Clause. See LICENSE.

Libraries

libbigdata
A pure Dart library for big data manipulation with DataFrame API and SQL query engine.