Skip to content

An analytical engine for the JVM

Your Java objects become typed columns in DuckDB. You ask questions of them in SQL — aggregates, groupings, pivots, window functions, joins — and get answers back as Java values, without rebuilding a single object. A million objects cost four megabytes of heap instead of eight hundred.

19×faster grouping than an on-heap collection
862 MB → 4 MBJava heap, 1M objects
3×faster aggregates than the heap
33 s → 6 msjoin across collections

DuckDB is an analytical engine, and the JVM has never really had one. Its JDBC driver makes you treat it as a remote database: one boxed value per call, no way to map an object to columns, no write path for its own nested types. quackjvm is the layer that makes it what it actually is — an in-process columnar engine you can put Java objects into and ask real questions of.

// Objects in.
writer.write(connection, cars.stream().map(layout::toRow).iterator(), true);

// Questions out. None of these rebuild an object.
double total = db.query("SELECT sum(price) FROM car WHERE make = ?", "Ford").scalar(Double.class);
List<Stats> by = db.query("SELECT make, count(*), avg(price) FROM car GROUP BY 1").records(Stats.class);
db.query("PIVOT car ON colour USING count(*) GROUP BY make").forEachRow(System.out::println);

Install

<dependency>
    <groupId>io.github.bdarwin</groupId>
    <artifactId>quackjvm-core</artifactId>
    <version>1.8.0</version>
</dependency>
implementation 'io.github.bdarwin:quackjvm-core:1.8.0'

Add quackjvm-cqengine instead if you use CQEngine; it brings the core with it. Java 17 or later.

The shortest possible version

A record becomes a table. Nothing else is required — no framework, no mapping code.

record Reading(int sensorId, String site, double celsius, LocalDate day) {}

ColumnarLayout<Reading> layout = ColumnarLayout.ofRecord(Reading.class);   // columns from the record

TableWriter writer = new TableWriter("reading", layout.toColumnDefs(), true,
        TableWriter.DEFAULT_APPENDER_THRESHOLD);
writer.createTable(connection, true);
writer.write(connection, readings.stream().map(layout::toRow).iterator(), true);

double average = Rows.of(connection.duplicate(),
        "SELECT avg(celsius) FROM reading WHERE site = ?", "kitchen").scalar(Double.class);

record SiteStats(String site, long readings, double avgCelsius) {}
List<SiteStats> stats = Rows.of(connection.duplicate(),
        "SELECT site, count(*), avg(celsius) FROM reading GROUP BY 1").records(SiteStats.class);

Rows gives you scalar, list, records, count, forEachRow and stream, and picks the read path for you — plain JDBC for a single value, Arrow columnar batches for anything wide. It needs only a Connection, so it reads Parquet and CSV just as happily:

long rows = Rows.of(connection.duplicate(), "SELECT count(*) FROM 'data/*.parquet'").scalar(Long.class);
Already using CQEngine? One line changes.
// before
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<>();

// after - same queries, 300x smaller heap
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<>(
        DuckDBPersistence.onPrimaryKey(Car.CAR_ID));

Your query code does not change, and you can drop into SQL over the same data whenever the object API runs out. See Querying and Migrating.

The modules

  • quackjvm-core


    DuckDB for the JVM, depending on nothing but the JDBC driver. Java-object-to-column mapping, an Arrow read path 10× faster than reading rows through JDBC, bulk loading at 2.4 µs per object, connection pooling, and typed SQL results.

    Storing objects

  • quackjvm-cqengine (optional)


    One plugin built on the core, for people already using CQEngine. It swaps their persistence in one line and adds two things CQEngine cannot do — a collection costing almost no heap, and joins across collections. Everything above still works underneath it.

    Using the plugin

  • quackjvm-agent (optional)


    For SQL and data the application does not write itself — an AI agent, a user, another service: guarded read-only queries, a catalog that describes the database, live Java collections and Java functions in SQL, and vector similarity.

    Guarding queries

Where to go next

  • Getting started

    Install it, store your first objects, run your first query. Start here.

  • Storing objects

    BLOB or columnar, what each costs, which types are supported, how layouts work.

  • Querying

    Every query form, what is pushed into SQL and what is not, and how to tell.

  • Joins across collections

    The thing CQEngine cannot do: existsIn, joined pairs, and arbitrary SQL.

  • Aggregates and projections

    Answering questions without rebuilding objects — the biggest performance lever here.

  • Writing data

    add, addAll, BULK_IMPORT, and the streaming bulk writer.

  • Tuning

    Memory limits, caches, optimize(), ART indexes, Arrow, concurrency.

  • Troubleshooting

    Every error message you are likely to see, and what it means.

  • Migrating

    Coming from on-heap CQEngine, or from its SQLite persistence.

  • API reference

    Class by class.

Design notes

Buffered writing — where the remaining write latency goes, whether quackjvm-core should expose commit() and flush(), and what an implicit buffer would cost the CQEngine plugin. Proposed, not implemented.

What the JDBC driver does not give you

Measured against duckdb_jdbc 2.0.0 (and 1.5.5 before it), and the reason this project exists:

capability JDBC driver quackjvm
reading results one boxed value per call; DuckDBVector is package-private so the columnar chunk already in your JVM is unreachable Arrow columnar batches — 1M rows x 4 columns: 602 ms to 60 ms
owning connections you open, duplicate, pass and close them; one shared between threads queues — a quick query waited 1,136 ms behind a slow one — and lets one thread roll back another's write Quack: one object owns them. Every call borrows one and gives it back, a transaction holds one start to end, and no connection is in sight unless you ask for one
storing Java objects write your own row mapping ColumnarLayout maps records, beans or explicit accessors to typed columns
bulk loading Appender: a row at a time, every value appended by hand TableWriter with chunked staging, 2.4 µs per object
precomputing a query CREATE TABLE AS, and a refresh that breaks readers Materialization, refreshed without a window where the table is missing
LIST / STRUCT / MAP / ARRAY writable through the appender since 1.5, but every value mapped by hand a record's own types become the columns — List<String> to VARCHAR[], a nested record to a STRUCT, Map<K,V> to MAP, float[] to FLOAT[768] — written and read back, no Arrow needed, 59 MB/s
Java UDFs and table functions shipped in 1.5 — raw, one callback interface quackjvm-agent: LiveTables.register(connection, "car", cars, layout): a collection queried and joined as a table, projection pushed down, 1M objects joined to 200k stored rows in 44.6 ms with no load step; Udfs.register(...) for a Java method in SQL, nulls decided, 8.8 ns a row
running SQL you did not write nothing — and worse: preparing "DROP TABLE t; SELECT 1" executes the DROP quackjvm-agent: GuardedQuery + QueryPolicy: DuckDB's own parser decides what is a query, one statement only, row and byte caps, a timeout that cancels, optional Hardening — check costs 0.61 ms
vector similarity array_cosine_similarity and friends are built in, but you write the query, the cast and the ordering VectorSearch.on(...).topK(query, 10, filter, params): exact top-10 over a million 128-dimension vectors in 35.3 ms, no extension, HNSW used when vss is installed

The honest trade

There are two halves to this and most comparisons only show one.

What it costs

Point queries are a memory trade, not a speed one

On-heap CQEngine wins every small single-collection query, and it is not close — between 50× and 360×. No amount of tuning changes that, and the reason is structural: DuckDB sequentially scans a table even for an equality on its primary key. It does not use the index. A one-row lookup on a million rows costs 205 µs with a primary key, 235 µs with no key, and 203 µs with an explicit ART index. It is an analytical engine, and a pointer dereference beats it every time.

1,000,000 objects, three indexed attributes, JDK 25 / Apple Silicon, DuckDB 2.0, memory_limit=256MB. Memory is process RSS, because DuckDB and SQLite both keep their data in native memory that Runtime.totalMemory() cannot see. Most of DuckDB's is allocator retention rather than data: DuckDB itself accounts for about 45 MB of it (see Migrating).

CQEngine on-heap CQEngine SQLite quackjvm (columnar)
process memory 1,303 MB 97 MB 401 MB
Java heap 862 MB 3 MB 4 MB
on disk – 225 MB 49 MB
loading 1M objects 2.5 s 11.7 s 3.4 s
point lookup by key 7.3 µs 552 µs 379 µs
narrow range 37 µs 1.2 ms 3.0 ms
count matches 2.4 µs 7.0 ms 869 µs
query returning 2% 1.2 ms 96.1 ms 16.4 ms
iterate everything 212 ms 750 ms 332 ms
single add() 4.7 µs 980 µs 1.1 ms
bulk write per object 2.5 µs – 2.4 µs
join 200k to 50k 0.229 s – 0.015 s

What it buys

The table above asks the heap's questions. Ask a database's questions and it inverts — because the expensive part of an object store is rebuilding objects, and none of these need one rebuilt:

1M cars, 200k matching on-heap quackjvm
sum a column over 200k matches 6.8 ms 2.2 ms 3× faster
group by make: count and average price 67.5 ms 3.6 ms 19× faster
pivot: makes across years not possible 9.7 ms –
median price not possible* 16.4 ms –
approximate distinct models not possible 2.0 ms –
join across two collections 0.229 s 0.015 s 15× faster

* possible, but only by materialising all 1,000,000 objects and sorting them in Java.

And the whole of SQL comes with it: window functions, QUALIFY, CTEs, UNION, reading a Parquet or CSV file and joining it against your collection without an import step.

The clearest case is a dashboard: several people looking at the same group-bys and pivots. Four panels over 2,000,000 rows, on-heap against quackjvm — 12 panels/s becomes 611, and 123 ms becomes 1.4 ms. See Many people, the same panels.

The rule underneath both tables: rebuilding objects is what costs. Materialising those same 200,000 cars and summing them in Java takes quackjvm 85 ms; asking DuckDB for the sum takes 2.2 ms. If your workload fetches objects one at a time, stay on the heap. If it asks questions about many objects, this is 3–20× faster and can express things the heap cannot.

Read the full comparison See it on GitHub