Data libraries
in Mojo

Parquet, Iceberg, Arrow, Avro, Thrift and the compression codecs, written in Mojo and published as tins on mojoshelf. No Python or JVM in the path.

Native formats

Parquet, Iceberg, Avro and Thrift are implemented in Mojo, and reads come back as Arrow arrays. Iceberg reads and writes: scan planning, deletes and deletion vectors, appends, overwrites and schema changes, through a filesystem, REST or SQL catalog. Beside them are objectstore for local files, HTTP and S3, postgres and sqlite clients and threads, and a packaged build of upstream's flare for networking and HTTP. Snappy, deflate and the hashes are Mojo too; libzstd, liblz4, libbrotli and libcurl are linked.

Measured against pyarrow

Reading a 1M-row Parquet file on one core takes 3.77 ms, against 8.0 ms for pyarrow on one thread. With four workers it takes 1.96 ms, against 2.57 ms for pyarrow on all ten CPUs. Avro decodes manifest-shaped records 10.7× faster than fastavro. It loses too: pyarrow is about 1.17× faster on nested and mixed data, and about 1.1× ahead on an Iceberg scan. The performance page has the numbers and how they were taken.

Checked against an outside implementation

Each of magmalake's own tins has a correctness oracle, an outside implementation it has to agree with in CI, and its page says which. They are Apache-2.0 and tested on stable Mojo 1.2.0 and the current nightly, on macOS and Linux.

Installed from mojoshelf

Each tin is a pixi package on mojoshelf, added with one command that brings its dependencies with it. Take only the ones you need. mojoshelf's guide installs the shelf command.

pixi init app -c https://conda.modular.com/max -c conda-forge && cd app
sed -i.bak 's/^\[workspace\]/[workspace]\npreview = ["pixi-build"]/' pixi.toml
pixi add "mojo-compiler==1.2.0"
pixi shelf add parquet-full-mojo    # Parquet with every codec

The companion of Morca

magmalake is the companion of Morca, which builds data pipelines on these tins. Dista, which runs Mojo functions across a cluster, is part of Morca. Both are used to build mojourney.dev, the census of Mojo on GitHub.

In code

Three of the tins

Parquet:

from parquet import OP_GE, OP_LT, ParquetReader, Predicate, ScalarValue

def main() raises:
    var r = ParquetReader.open("prune.parquet")
    r.select_columns(["k"])
    var preds: List[Predicate] = [
        Predicate("k", OP_GE, ScalarValue.of_int(250)),
        Predicate("k", OP_LT, ScalarValue.of_int(260)),
    ]
    print(r.prune_row_groups(preds), "row groups left")
    var t = r.read_table()
    var k = t.column_i64(0)                 # (values, validity)

Footer, page headers, levels and values decoded in Mojo; the rows come back as Arrow arrays. More

The tins

Every tin, layer by layer

Each box links to the tin's page: what it is, how to install it, what proves it and how fast it is. The tins page says more about how they fit together.

Each box is a tin with its own page, its own tests and its own release cadence, and each layer uses only the ones below it; the number beside its name is the version on mojoshelf. Outside the diagram there is only libzstd, liblz4, libbrotli, libcurl, libpq, SQLite, the Restate Rust SDK and the system pthreads, plus OpenSSL and simdjson under the republished packages. A box marked from source works today but isn't on mojoshelf yet. Beside the stack are a second Iceberg implementation kept only to check the native one, and three upstream libraries republished so the tins can depend on them.