---
name: "delta-lake-acid-time-travel"
description: "Build reliable data lakehouses with ACID transactions, schema enforcement, and time travel."
metadata:
  author: "Delta Lake"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "query delta lake time travel"
  - "run delta lake optimize zorder"
  - "merge into delta table"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Delta Lake ACID Transactions & Time Travel Queries

Manages Delta Lake tables: executing MERGE INTO (upserts), querying historical snapshot versions (AS OF), compacting small files with OPTIMIZE ZORDER BY, and vacuuming stale parquet files safely.

## When to Invoke
Invoke this skill whenever you need to:
- query delta lake time travel
- run delta lake optimize zorder
- merge into delta table

## Execution SOP & Rules
1. Query historical versions: spark.read.format('delta').option('versionAsOf', 5).load('/data/table').
2. Perform upsert: DeltaTable.forPath(spark, '/data/table').alias('t').merge(updates.alias('s'), 't.id = s.id').whenMatchedUpdateAll().whenNotMatchedInsertAll().execute().
3. Compact small files: spark.sql('OPTIMIZE delta.`/data/table` ZORDER BY (customer_id, date)').
4. Prune old commit snapshots: spark.sql('VACUUM delta.`/data/table` RETAIN 168 HOURS').

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
