Skip to content
atgreenPublic

About

A zero-dependency Common Lisp implementation of Apache Arrow (columnar format + IPC).

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

cl-arrow

A zero-dependency Common Lisp implementation of the Apache Arrow columnar format and IPC serialization.

No external systems are required — not even a test framework. The library depends only on ANSI Common Lisp. Interoperability is validated against pyarrow (see interop/), but pyarrow is never a dependency.

Installation

With ocicl:

ocicl install cl-arrow

Or clone this repository somewhere ASDF can find it. Either way, because cl-arrow has no dependencies, nothing else needs to be installed:

(asdf:load-system :cl-arrow)

What's implemented

In-memory columnar format

  • Full logical type system: null, bool, all int/uint widths, half/single/double float, utf8/binary and their large variants, fixed-size-binary, date, time, timestamp, duration, decimal (128/256), list, large-list, fixed-size-list, struct, map, union, and dictionary.
  • array-data physical container (validity bitmap, offsets, data, children, dictionary) with LSB-first validity bitmaps and little-endian buffers.
  • Element accessors (array-ref), per-type builders (build-array, make-builder), and record-batch / chunked-array / arrow-table.
  • A portable, dependency-free IEEE-754 float codec.

IPC serialization

  • A hand-written FlatBuffers reader/writer (no FlatBuffers dependency).
  • The streaming format and the random-access file format, read and write.
  • Dictionary encoding end to end (DictionaryBatch messages, stream replacement), for low-cardinality/factor columns.
  • Incremental streaming: emit the schema once then push record batches one at a time (O(batch) memory) to a byte stream or an octet callback; read them back a message at a time.
  • Verified round-trip with pyarrow in both directions (file + stream), incl. dictionaries, nulls, NaN/±Inf, and timestamps/dates.

Loading without a build system

For injecting into a bare inferior Lisp (no ASDF/Quicklisp), generate a single concatenated source file and LOAD it:

make bundle          # writes cl-arrow-bundle.lisp
(load "cl-arrow-bundle.lisp")   ; defines the CL-ARROW (nickname ARROW) package

The library is ANSI Common Lisp with zero implementation internals. The bundle is verified to load and encode/decode on SBCL, ECL, and ABCL.

Convenience for bridges (e.g. columns → Perspective)

;; One call: generic columns -> a complete IPC stream (octet-vector).
(columns->ipc-stream
  (list (list "region" *utf8*    #("West" "East" "NA") :na "NA" :na-test #'equal)
        (list "units"  *int64*   #(120 200 0))
        (list "score"  *float64* #(9.5d0 :nan 9.0d0))
        (list "factor" (dictionary-type *int32* *utf8*) #("a" "b" "a"))))

Null handling is explicit: pass :valid (a boolean mask) or :na (a missing marker, compared with :na-test, default eql). With :na, nil is an ordinary value — so boolean false is never mistaken for null. Non-finite floats travel as the keyword sentinels :+inf / :-inf / :nan.

Incremental streaming:

(let ((w (open-stream-writer schema sink)))   ; sink: byte stream or (lambda (octets) ...)
  (stream-write-batch w batch1)
  (stream-write-batch w batch2)
  (stream-finish w))

Usage

(asdf:load-system :cl-arrow)
(in-package :cl-arrow)

(let* ((schema (make-schema (list (make-field "id" *int64*)
                                  (make-field "name" *utf8*))))
       (batch  (make-record-batch schema
                 (list (build-array *int64* '(1 2 3 nil 5))
                       (build-array *utf8*  '("a" "b" nil "d" "e"))))))
  ;; write / read an Arrow file
  (write-arrow-file "/tmp/t.arrow" schema (list batch))
  (multiple-value-bind (schema2 batches) (read-arrow-file "/tmp/t.arrow")
    (array-ref (batch-column (first batches) 1) 0)))  ; => "a"

Tests

sbcl --non-interactive --load tests/run.lisp

Optional pyarrow interop check:

PYTHON=/usr/bin/python3.14 ./interop/run.sh

License

Distributed under the terms of the MIT license.

Copyright © 2026 Anthony Green.

About

A zero-dependency Common Lisp implementation of Apache Arrow (columnar format + IPC).

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages