Skip to content

DuckDB support

From version 1.9, Luna writes its results databases (luna -o) in DuckDB format by default, and the matching destrat reads them. Older SQLite results databases can still be read, and SQLite output is still available with --sqlite.

If you install a binary or wheel

Luna 1.9 binaries and lunapi 1.9 wheels include DuckDB. When lunaR uses a lunapi 1.9 wheel, no separate DuckDB SDK is needed.

DuckDB is an optional dependency when compiling Luna from source. Luna links it statically, so the resulting executables carry the library with them. Both installation routes use DuckDB 2.0.1, pinned to an exact upstream commit, with core functions, JSON and Parquet.

Install the SDK for your processor

Run these commands in your luna-base checkout for version 1.9:

python3 scripts/download_duckdb.py
make -j4

The installer chooses how to obtain the SDK based on your platform:

Platform Default Tools needed
x86-64 Linux (glibc or musl), Intel macOS, Windows MSYS2 UCRT64 Downloads the pinned source and compiles for baseline x86-64 Python 3, Git, CMake, Make, and a C/C++ compiler
ARM64 Linux or Apple Silicon macOS Downloads and assembles the SHA-256-verified upstream ARM64 archives Python 3, curl, and native C/C++ build tools

On Linux and macOS, uname -m shows the running architecture. Intel and AMD 64-bit hosts use the x86-64 route. Apple Silicon and Linux aarch64 hosts use the ARM64 route. The installer can compile with --jobs N (default 4), so set it to the CPU count allocated to your job on a cluster.

The installer creates ./duckdb-sdk and checks the native link plus JSON and Parquet queries. It reuses a verified SDK and caches prebuilt archives in .duckdb-downloads/. For dependencies such as FFTW and LightGBM, see Building Luna from source.

Download an upstream x86-64 archive

On a compatible host, use --upstream-prebuilt to skip the DuckDB source build. The upstream Linux x86-64 libraries require x86-64-v3. Use the default baseline build if CPU support is uncertain. The Intel macOS and MSYS2 UCRT64 archives use their upstream platform targets.

python3 scripts/download_duckdb.py --upstream-prebuilt --prefix duckdb-sdk-upstream
make -j4 DUCKDB=1 DUCKDB_PATH=duckdb-sdk-upstream

Use a separate prefix to keep both SDKs. The installer reuses the installation only when it matches the requested source or archive. Use --cache-dir DIR to store downloaded archives elsewhere.

Build DuckDB from source with a reusable build directory

Use scripts/ci/build_duckdb.py to keep the DuckDB checkout and compiled objects for future builds, or to build on ARM64 with your local toolchain. The script uses the same CPU defaults as Luna's release builds. A local build can help when an upstream archive requires a newer C/C++ runtime than your system provides.

The script needs three locations:

Argument Meaning
--source where to clone the DuckDB source (or an existing DuckDB 2.0.1 checkout)
--build-dir where CMake builds it (several GB)
--prefix where the finished SDK is placed

For example, from the luna-base folder:

python3 scripts/ci/build_duckdb.py \
  --source ../duckdb-src \
  --build-dir ../duckdb-build \
  --prefix duckdb-sdk-src \
  --jobs 4

make -j4 DUCKDB=1 DUCKDB_PATH=duckdb-sdk-src

Notes:

  • if --source does not exist, the script clones DuckDB v2.0.1 into it, and refuses to build if the checkout is not the exact pinned commit
  • keep --source and --build-dir outside the luna-base folder (as above, with ../): they are large and are only needed during the build
  • give --prefix a name other than duckdb-sdk, so that it does not mix with a downloaded SDK; as make only picks up ./duckdb-sdk automatically, pass the source-built SDK with DUCKDB_PATH
  • --jobs sets the number of parallel compile jobs (default 2); compiling DuckDB needs memory, so allow roughly 1--2 GB per job
  • --generator Ninja uses Ninja instead of Make, which is faster if it is installed

Compiling Luna with DuckDB

make arguments Result
none, with ./duckdb-sdk present DuckDB enabled, using ./duckdb-sdk
DUCKDB=1 DUCKDB_PATH=/path/to/sdk DuckDB enabled, using that SDK
DUCKDB=0 DuckDB disabled even if an SDK is present: luna -o writes SQLite
none, and no SDK DuckDB disabled: luna -o writes SQLite, and destrat is the SQLite-only reader

Whenever an SDK is found, destrat reads both formats, and the build also makes destrat-sqlite, the previous SQLite-only reader.

Run ./luna -v and check that it reports a DuckDB version. Then try a small run with your sample list:

./luna s.lst 1 -o out.db -s DESC
./destrat out.db

If you change between these modes (e.g. add an SDK after building without one), make rebuilds the affected files automatically.

Output options

In a DuckDB-enabled build:

Option Writes
-o out.db a new DuckDB database
-o out.db --sqlite a new SQLite database (the pre-1.9 format)
-a out.db appends to an existing database, in that database's own format (a new file is DuckDB, or SQLite with --sqlite)

-o, -a, -d and -t cannot be combined: give one output mode per run. destrat detects the format of a database from the file itself, whatever its extension. By convention, both formats use .db.

HPC and other systems with a memory limit

On Linux, some hosts limit how much virtual memory (address space) a process may reserve, which you can see with ulimit -v. This is common on HPC login nodes. Starting DuckDB on such a host could fail with:

Out of Memory Error: Allocation failure

even though plenty of physical memory is free. The cause is the system memory allocator, which reserves address space for each thread. Luna 1.9 detects such a limit and adjusts for it, so luna, destrat, lunapi and the download script's test should all work there.

If you still see the error, e.g. with another program that uses DuckDB, set MALLOC_ARENA_MAX before starting it:

export MALLOC_ARENA_MAX=8

Alternatively, run the job on a compute node, which usually has no such limit (and is generally where analyses should be run anyway).

CPU and system requirements

The CPU target and the minimum operating-system version are separate requirements. The default x86-64 SDK uses baseline instructions. Intel macOS source builds default to a macOS 10.15 deployment target. On ARM64, the upstream defaults target Apple M1 on macOS and Armv8-A on Linux.

Luna's portable Linux binaries and lunapi Linux wheels target glibc 2.28 or newer. If the upstream archive requires a newer runtime than your system has, build the SDK and Luna locally using the system's supported toolchain.