Skip to content

Commit eeefdd3

Browse files
authored
snapshot caching + incremental loading (#300)
**Support incremental snapshot loading** When a Delta table is read multiple times within a session, leverage kernel functionality to load only incremental changes when moving forward in time (e.g. from v5002 -> v5003). Previously, loading v5003 immediately after loading v5002 would still require reading metadata for version [0-5002] first. With this change DuckDB Delta and delta-kernel will begin with cached metadata and only read and apply new log entries atop that cache. Incremental/cached loading is not currently supported for backward time travel, and falls back to a fresh load. **Also included** - delta-kernel-rs bumped to v0.21.0 (required for increment load API), includes some FFI changes around ffi::Handle wrappers, EngineError and OptionalValue support - build changes avoid downloading 8GB of unused test data in cargo build - delta kernel logging: allow `SET delta_kernel_logging = false`; the underlying kernel event trace will remain active, but duckdb-delta will drop inbound events if false - several test setup/cleanup guards where delta kernel logging state was lingering between tests **Variant encoding** variant_legacy_encoding is now unconditionally set to true at extension load time, enabling backwards-compatible parsing of Variant columns written as STRUCT(value, metadata). **Test notes** - test/sql/main/writing/incremental_snapshot.test — verifies that v0→v1→v2 incremental loads don't re-read earlier log files, and backward time travel correctly builds fresh - test/sql/main/writing/transaction_multi_insert.test — multi-INSERT within a single transaction
1 parent 80283e8 commit eeefdd3

27 files changed

Lines changed: 469 additions & 125 deletions

.github/workflows/MainDistributionPipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jobs:
1919
with:
2020
# Main config
2121
extension_name: &ext_name delta
22-
duckdb_version: &duckdb_ref v1.5.1
23-
ci_tools_version: &ci_tools_ref v1.5.0
22+
duckdb_version: &duckdb_ref v1.5.2
23+
ci_tools_version: &ci_tools_ref v1.5-variegata
2424
enable_rust: true
2525
rust_logs: true
2626
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_rtools;windows_amd64_mingw;linux_amd64_musl'

benchmark/micro/snapshot_performance/delta_scan.benchmark

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require delta
1010
require parquet
1111

1212
run
13-
SELECT COUNT(*) FROM delta_scan('./data/generated/delta_rs_tpch_sf1_100_splits/lineitem/delta_lake')
13+
SELECT COUNT(*) FROM delta_scan('./data/generated/tpch_sf1_90commits/lineitem/delta_lake')
1414

1515
result I
16-
6001215
16+
6001215

benchmark/micro/snapshot_performance/delta_scan_filter.benchmark

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require delta
1010
require parquet
1111

1212
run
13-
SELECT COUNT(*) FROM delta_scan('./data/generated/delta_rs_tpch_sf1_100_splits/lineitem/delta_lake') where l_orderkey is not null
13+
SELECT COUNT(*) FROM delta_scan('./data/generated/tpch_sf1_90commits/lineitem/delta_lake') where l_orderkey is not null
1414

1515
result I
16-
6001215
16+
6001215

benchmark/micro/snapshot_performance/snapshot_no_pin.benchmark

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ require delta
1010
require parquet
1111

1212
load
13-
ATTACH './data/generated/delta_rs_tpch_sf1_100_splits/lineitem/delta_lake' as lineitem_no_pin (TYPE delta);
13+
ATTACH './data/generated/tpch_sf1_90commits/lineitem/delta_lake' as lineitem_no_pin (TYPE delta);
1414

1515
run
1616
SELECT COUNT(*) FROM lineitem_no_pin
1717

1818
result I
19-
6001215
19+
6001215

benchmark/micro/snapshot_performance/snapshot_no_pin_filter.benchmark

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ require delta
1010
require parquet
1111

1212
load
13-
ATTACH './data/generated/delta_rs_tpch_sf1_100_splits/lineitem/delta_lake' as lineitem_no_pin (TYPE delta);
13+
ATTACH './data/generated/tpch_sf1_90commits/lineitem/delta_lake' as lineitem_no_pin (TYPE delta);
1414

1515
run
1616
SELECT COUNT(*) FROM lineitem_no_pin where l_orderkey is not null
1717

1818
result I
19-
6001215
19+
6001215

benchmark/micro/snapshot_performance/snapshot_pin.benchmark

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ require delta
1010
require parquet
1111

1212
load
13-
ATTACH './data/generated/delta_rs_tpch_sf1_100_splits/lineitem/delta_lake' as lineitem_pin (TYPE delta, PIN_SNAPSHOT);
13+
ATTACH './data/generated/tpch_sf1_90commits/lineitem/delta_lake' as lineitem_pin (TYPE delta, PIN_SNAPSHOT);
1414

1515
run
1616
SELECT COUNT(*) FROM lineitem_pin
1717

1818
result I
19-
6001215
19+
6001215

benchmark/micro/snapshot_performance/snapshot_pin_filter.benchmark

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ require delta
1010
require parquet
1111

1212
load
13-
ATTACH './data/generated/delta_rs_tpch_sf1_100_splits/lineitem/delta_lake' as lineitem_pin (TYPE delta, PIN_SNAPSHOT);
13+
ATTACH './data/generated/tpch_sf1_90commits/lineitem/delta_lake' as lineitem_pin (TYPE delta, PIN_SNAPSHOT);
1414

1515
run
1616
SELECT COUNT(*) FROM lineitem_pin where l_orderkey is not null
1717

1818
result I
19-
6001215
19+
6001215

scripts/data_generator/delta_rs_generator/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def generate_test_data_delta_rs_multi(base_path, path, init, tables, splits = 1)
3232

3333
# Then we write the parquet files
3434
for table in tables:
35-
total_count = con.sql(f"select count(*) from ({table['query']})").fetchall()[0][0]
35+
query = table['query']
36+
total_count = con.sql(f"select count(*) from ({query})").fetchall()[0][0]
3637
# At least 1 tuple per file
3738
if total_count < splits:
3839
splits = total_count

scripts/data_generator/generate_test_data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@
9191
for table in ["customer","lineitem","nation","orders","part","partsupp","region","supplier"]:
9292
con.query(f"create table duckdb_out.{table} as from {table}")
9393

94+
# TPC-H sf with 100 commits
95+
init = "call dbgen(sf=1);"
96+
tables = ["customer","lineitem","nation","orders","part","partsupp","region","supplier"]
97+
queries = [f"from {x}" for x in tables]
98+
tables = [{'name': x[0], 'query':x[1]} for x in zip(tables,queries)]
99+
generate_test_data_delta_rs_multi(BASE_PATH, "tpch_sf1_90commits", init, tables, 90)
100+
94101
################################################
95102
### TPC-DS
96103
################################################

src/delta_extension.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "duckdb/main/extension_helper.hpp"
1515
#include "duckdb/storage/storage_extension.hpp"
1616
#include "duckdb/main/config.hpp"
17+
#include "duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp"
1718

1819
namespace duckdb {
1920

@@ -106,6 +107,11 @@ static void LoadInternal(ExtensionLoader &loader) {
106107
auto &config = DBConfig::GetConfig(loader.GetDatabaseInstance());
107108
StorageExtension::Register(config, "delta", make_shared_ptr<DeltaStorageExtension>());
108109

110+
// NOTE: variant_legacy_encoding now refers to __delta_only_variant_encoding_enabled which is strictly internal
111+
// and used to signal parquet variant legacy support. It's not fundamentally optional, and thus controlled here
112+
// only.
113+
config.options.variant_legacy_encoding = true;
114+
109115
config.AddExtensionOption("delta_scan_explain_files_filtered",
110116
"Adds the filtered files to the explain output. Warning: this may impact performance of "
111117
"delta scan during explain analyze queries.",

0 commit comments

Comments
 (0)