Quickstart
From zero to incremental in a few lines.
Choose your engine to build OpenIVM and refresh your first materialized view.
Build
For DuckDB v1.5.4, you need git, CMake ≥ 3.5, a C++ compiler, and optionally Ninja for faster builds.
git clone --recurse-submodules https://github.com/openivm/openivm.git
cd openivm
GEN=ninja make # release build; plain `make` works without ninja
# The built DuckDB CLI already loads OpenIVM
./build/release/duckdb my.dbCreate a view and refresh it
Create a view, change the base table, refresh. Only the new rows are processed.
CREATE TABLE sales (region VARCHAR, product VARCHAR, amount INT);
INSERT INTO sales VALUES ('US', 'Widget', 100), ('EU', 'Gadget', 200);
SELECT * FROM sales ORDER BY region;
-- EU | Gadget | 200
-- US | Widget | 100
CREATE MATERIALIZED VIEW regional_totals AS
SELECT region, SUM(amount) AS total, COUNT(*) AS cnt
FROM sales GROUP BY region;
SELECT * FROM regional_totals ORDER BY region;
-- EU | 200 | 1
-- US | 100 | 1
-- Changes are captured as deltas automatically
INSERT INTO sales VALUES ('US', 'Bolt', 50), ('JP', 'Gear', 300);
DELETE FROM sales WHERE product = 'Gadget';
SELECT * FROM sales ORDER BY region, product;
-- JP | Gear | 300
-- US | Bolt | 50
-- US | Widget | 100
PRAGMA refresh('regional_totals');
SELECT * FROM regional_totals ORDER BY region;
-- JP | 300 | 1
-- US | 150 | 2 (EU is gone: its only row was deleted)Views with REFRESH EVERY are maintained by a background daemon, which only sees settings made with SET GLOBAL.
-- Refresh in the background every 5 minutes
CREATE MATERIALIZED VIEW regional_totals REFRESH EVERY '5 minutes' AS
SELECT region, SUM(amount) AS total, COUNT(*) AS cnt
FROM sales GROUP BY region;
PRAGMA refresh_status('regional_totals'); -- interval, last / next refresh
-- The daemon reads global settings
SET GLOBAL openivm_adaptive_backoff = true; -- back off when a refresh outlasts its interval
-- Let a cost model pick incremental vs full per refresh (experimental)
SET GLOBAL openivm_adaptive_refresh = true;
PRAGMA refresh_cost('regional_totals'); -- incremental vs recompute estimateOver DuckLake, deltas come from native snapshots, with no duplicated storage.
INSTALL ducklake;
LOAD ducklake;
ATTACH ':memory:' AS dl (TYPE ducklake);
CREATE TABLE dl.orders (id INT, product VARCHAR, region VARCHAR, amount INT);
-- Views stack into pipelines; DuckLake snapshots provide the deltas
CREATE MATERIALIZED VIEW dl.product_totals REFRESH EVERY '5 minutes' AS
SELECT product, SUM(amount) AS total, COUNT(*) AS cnt
FROM dl.orders GROUP BY product;
CREATE MATERIALIZED VIEW dl.top_products REFRESH EVERY '10 minutes' AS
SELECT product, total FROM dl.product_totals WHERE total > 1000;
-- Refreshing product_totals also refreshes top_products
SET openivm_cascade_refresh = 'downstream'; -- or 'upstream', 'both', 'off'OpenIVM is a compiler: you can read exactly what it runs.
-- Write every compiled statement to disk
SET openivm_files_path = '/tmp/openivm';
CREATE MATERIALIZED VIEW regional_totals AS
SELECT region, SUM(amount) AS total FROM sales GROUP BY region;
PRAGMA refresh('regional_totals');
-- /tmp/openivm/openivm_compiled_queries_regional_totals.sql (DDL at CREATE time)
-- /tmp/openivm/openivm_upsert_queries_regional_totals.sql (the refresh SQL)
-- Peek at pending changes
SELECT * FROM openivm_delta_sales;From rows to a refreshed view.
Same rows as the first example above.
salesTABLE| region | product | amount |
|---|---|---|
| US | Widget | 100 |
| EU | Gadget | 200 |
regional_totalsVIEW| region | total | cnt |
|---|---|---|
| EU | 200 | 1 |
| US | 100 | 1 |
salesTABLE| region | product | amount |
|---|---|---|
| US | Bolt | 50 |
| JP | Gear | 300 |
| EU | Gadget | 200 |
regional_totalsVIEW| region | total | cnt |
|---|---|---|
| JP | 300 | 1 |
| US | 150 | 2 |
● inserted / changed ● deleted · refresh updates the materialized view
Reference
| Pragma | What it does |
|---|---|
| PRAGMA refresh('v') | Refresh a materialized view |
| PRAGMA refresh_status('v') | Refresh interval, last / next refresh, status |
| PRAGMA refresh_cost('v') | Incremental vs full recompute cost estimate |
| PRAGMA refresh_history('v') | Past refreshes (feeds the learned cost model) |
| Setting | Default | Description |
|---|---|---|
| openivm_refresh_mode | incremental | Set to 'full' to force full recompute; any other value refreshes incrementally |
| openivm_cascade_refresh | downstream | Pipeline cascade: 'off', 'upstream', 'downstream', 'both' |
| openivm_adaptive_refresh | false | Pick incremental vs full per refresh with a cost model (experimental) |
| openivm_disable_daemon | false | Turn off background REFRESH EVERY maintenance |
| openivm_files_path | — | Directory for compiled SQL files |
| openivm_input_dialect | duckdb | Dialect of view bodies, e.g. 'spark' |
Build the extension JAR
Start with Git, Bash and Docker. These commands create the project's devcontainer and build the Spark 3.5 assembly inside it.
git clone https://github.com/openivm/openivm-spark.git
cd openivm-spark
./contrib/bootstrap-dev-env.sh
npx --no-install nx run devcontainer:up
npx --no-install nx run devcontainer:exec -- \
npx --no-install nx run spark-ext:assembly --configuration=spark-3.5The JAR is written under spark-ext/ivm-extension/target/spark-3.5-antlr-4.9.3/scala-2.12/. For Spark 4.1 use the spark-4.1 build configuration instead; the runtime versions and JAR path differ. See the build guide.
Start a local Spark session
In VS Code, use Dev Containers: Attach to Running Container, open /workspaces/openivm-spark, and open a terminal. The image provides Java 17 and matching OpenIVM native binaries; its OPENIVM_CLI_PATH and OPENIVM_EXTENSION_PATH point to them. Install Spark 3.5.1 for this terminal:
curl -fL https://archive.apache.org/dist/spark/spark-3.5.1/spark-3.5.1-bin-hadoop3.tgz -o /tmp/spark-3.5.1-bin-hadoop3.tgz
tar -xzf /tmp/spark-3.5.1-bin-hadoop3.tgz -C /tmp
export PATH="/tmp/spark-3.5.1-bin-hadoop3/bin:$PATH"Then, from the repository root, start the Spark SQL CLI with Delta Lake and OpenIVM enabled:
JAVA_MODULE_OPTIONS="--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED \
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens=java.base/java.io=ALL-UNNAMED \
--add-opens=java.base/java.net=ALL-UNNAMED \
--add-opens=java.base/java.nio=ALL-UNNAMED \
--add-opens=java.base/java.util=ALL-UNNAMED \
--add-opens=java.base/java.util.concurrent=ALL-UNNAMED \
--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED \
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens=java.base/sun.nio.cs=ALL-UNNAMED \
--add-opens=java.base/sun.security.action=ALL-UNNAMED \
--add-opens=java.base/sun.util.calendar=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED"
spark-sql \
--master 'local[1]' \
--packages io.delta:delta-spark_2.12:3.2.0 \
--jars spark-ext/ivm-extension/target/spark-3.5-antlr-4.9.3/scala-2.12/ivmExtension-0.1.0-SNAPSHOT-assembly.jar \
--conf spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension,org.openivm.spark.OpenIvmSparkExtensions \
--conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog \
--conf spark.openivm.enabled=true \
--conf spark.driver.extraJavaOptions="$JAVA_MODULE_OPTIONS" \
--conf spark.executor.extraJavaOptions="$JAVA_MODULE_OPTIONS"The Delta package supplies Delta Lake 3.2.0; the two extensions and Delta catalog must be configured before the Spark session starts. The explicit Java module options come from the project's .sbtopts. See activation and Spark downloads.
Create a view and refresh it
Paste this SQL into spark-sql. It creates a Delta table and view, inserts more rows, then explicitly refreshes the view. Start with names that do not already exist.
CREATE TABLE sales_i1 (region STRING, amount INT) USING DELTA;
INSERT INTO sales_i1 VALUES ('east', 100), ('west', 200);
SELECT * FROM sales_i1 ORDER BY region;
-- east | 100
-- west | 200
CREATE MATERIALIZED VIEW mv_i1 AS
SELECT region, SUM(amount) AS total, COUNT(*) AS cnt
FROM sales_i1 GROUP BY region;
SELECT region, total, cnt FROM mv_i1 ORDER BY region;
-- east | 100 | 1
-- west | 200 | 1
INSERT INTO sales_i1 VALUES ('north', 300), ('east', 50);
SELECT * FROM sales_i1 ORDER BY region, amount;
-- east | 50
-- east | 100
-- north | 300
-- west | 200
REFRESH MATERIALIZED VIEW mv_i1;
SELECT region, total, cnt FROM mv_i1 ORDER BY region;
-- east | 150 | 2
-- north | 300 | 1
-- west | 200 | 1From rows to a refreshed view.
Same rows as the first example above.
sales_i1TABLE| region | amount |
|---|---|
| east | 100 |
| west | 200 |
mv_i1VIEW| region | total | cnt |
|---|---|---|
| east | 100 | 1 |
| west | 200 | 1 |
sales_i1TABLE| region | amount |
|---|---|
| north | 300 |
| east | 50 |
mv_i1VIEW| region | total | cnt |
|---|---|---|
| east | 150 | 2 |
| north | 300 | 1 |
| west | 200 | 1 |
● inserted / changed ● deleted · refresh updates the materialized view
After refresh, east totals 150 in two rows, north totals 300, and west totals 200. See materialized view documentation.
Reference
Selected Spark configuration settings. Set session startup options with --conf; links go to their definitions on the main branch.
| Setting | Default | Description |
|---|---|---|
spark.openivm.enabled | false | Enable OpenIVM for this Spark session. |
spark.openivm.statePath | warehouse dir | Local directory for RocksDB state; defaults to spark.sql.warehouse.dir. |
spark.openivm.stateSync.uri | unset | Mirror local state to a Hadoop filesystem URI for durability. |
spark.openivm.catalog.backend | rocksdb | Choose rocksdb or delta for the OpenIVM metadata catalog. |
spark.openivm.changeFeed.mode | intercept | Choose how base-table changes are captured; Delta CDF is also supported. |
spark.openivm.delta.enableDeletionVectors | true | Use Delta deletion vectors on materialized-view backing tables. |
spark.openivm.delta.optimizeWrite | false | Enable Delta optimized writes on materialized-view backing tables. |
spark.openivm.profile.refresh | false | Capture per-step refresh profiles. |
spark.openivm.queryLog.enabled | false | Capture CREATE and REFRESH SQL in the OpenIVM query log. |
spark.openivm.metrics.enabled | true | Register and update Spark-native OpenIVM metrics. |
Microsoft Fabric Spark
An OpenIVM quickstart for Microsoft Fabric Spark 3.5/4.X+ is on its way.