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
Iceberg:
from iceberg import Catalog
var table = Catalog.rest("https://polaris.example/api/catalog").load("db.events")
var rows = table.scan().filter('["=", "region", "eu"]').select(["id", "amount"]).to_table() Metadata, manifests, scan planning, Parquet decode, deletes and deletion vectors, S3 IO and the REST catalog — all of it Mojo. More
Object storage:
from objectstore import FileIOResolver
def main() raises:
var io = FileIOResolver()
var loc = "file:///tmp/objectstore-demo/data/part-0.bin"
io.write(loc, "hello, object store".as_bytes()) # makes the directories
var f = io.new_input(loc)
print(f.length(), "bytes")
var tail = f.read_range(-5, 5) # the last 5 bytes One resolver for file://, http(s)://, s3://, gs:// and abfss://, with ranged reads and SigV4 signing. 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.