/fabric-data-engineering:lakehouse-optimize <lakehouse-name> [--tables <table1,table2>] [--zorder <col1,col2>] [--vacuum-days <days>] [--report]from fabric-data-engineering
Optimizes a Microsoft Fabric lakehouse by compacting small files, applying Z-ordering, vacuuming old versions, analyzing statistics, and generating a health score report.
Ships in fabric-data-engineering. Installing the plugin adds it to Claude Code.
Run comprehensive optimization on a lakehouse: compact small files, apply Z-ordering, vacuum old versions, analyze file health, and generate a maintenance report.
<lakehouse-name> — Target lakehouse. Ask if not provided.--tables — Comma-separated table names to optimize. Default: all tables.--zorder — Columns for Z-ORDER (applied to all tables, or per-table with table:col1,col2 syntax).--vacuum-days — Retention period for VACUUM (minimum 7). Default: 14.--report — Generate a detailed health report after optimization.Before optimizing, assess each table:
def assess_table(table_name):
detail = spark.sql(f"DESCRIBE DETAIL {table_name}").collect()[0]
return {
"table": table_name,
"num_files": detail["numFiles"],
"size_bytes": detail["sizeInBytes"],
"size_gb": round(detail["sizeInBytes"] / (1024**3), 3),
"avg_file_size_mb": round(detail["sizeInBytes"] / max(detail["numFiles"], 1) / (1024**2), 1),
"partitions": detail["partitionColumns"],
"recommendations": []
}
Generate recommendations:
For each table:
Step 1: OPTIMIZE (compact small files)
OPTIMIZE <table_name>;
-- With Z-ORDER if specified:
OPTIMIZE <table_name> ZORDER BY (<columns>);
Step 2: VACUUM (remove old versions)
VACUUM <table_name> RETAIN <vacuum_days> DAYS;
Step 3: ANALYZE (update statistics)
ANALYZE TABLE <table_name> COMPUTE STATISTICS FOR ALL COLUMNS;
Re-assess each table and compare before/after:
Generate a comprehensive report:
## Lakehouse Health Report: <lakehouse-name>
Generated: <timestamp>
### Overall Health Score: <score>/100
| Table | Files Before | Files After | Size (GB) | Avg File (MB) | Z-Ordered | Score |
|-------|-------------|-------------|-----------|---------------|-----------|-------|
| orders | 1,247 | 48 | 12.3 | 262 | ✓ date,region | 95/100 |
| customers | 89 | 12 | 1.8 | 153 | ✗ | 80/100 |
### Recommendations
- [ ] Add Z-ORDER on customers(customer_type, region) — frequent filter columns
- [ ] Schedule weekly maintenance notebook
- [ ] Consider partitioning orders by order_date (12.3 GB)
### Storage Summary
- Total size: 14.1 GB across 2 tables
- Storage freed by VACUUM: 2.3 GB
- File count reduced: 1,336 → 60 (95.5% reduction)
Create a reusable maintenance notebook that can be scheduled:
_metadata.maintenance_log tableShow:
What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
11 commands in this plugin
/delta-table-manageCreate, optimize, vacuum, and manage Delta Lake tables in a Fabric lakehouse/fabric-eng-setupSet up the Fabric Data Engineering plugin — verify Fabric capacity, create workspace, configure lakehouse access/lakehouse-createCreate a Fabric lakehouse with medallion folder structure and SQL analytics endpointnpx claudepluginhub thelobbi/claude-m --plugin fabric-data-engineeringOther plugins' commands for the same job