New to Kestra?
Use blueprints to kickstart your first workflows.
Automate Iceberg maintenance with Trino and Kestra. Compact small files, expire snapshots older than 7 days, and get Discord confirmations weekly.
Iceberg tables degrade quietly. Streaming and micro-batch writes pile up small files that slow every scan, and each write adds a snapshot that keeps old data files alive on storage. This blueprint runs the two standard countermeasures through io.kestra.plugin.jdbc.trino.Query on a weekly schedule: ALTER TABLE ... EXECUTE optimize to compact small files, and ALTER TABLE ... EXECUTE expire_snapshots to drop snapshots older than seven days. Both statements run with fetchType: NONE since they return no result set, and Discord confirms every run.
optimize_table (io.kestra.plugin.jdbc.trino.Query, fetchType: NONE) runs ALTER TABLE iceberg.analytics.events EXECUTE optimize, rewriting small data files into larger ones sized for efficient scans.expire_snapshots runs ALTER TABLE iceberg.analytics.events EXECUTE expire_snapshots(retention_threshold => '7d'), removing snapshot metadata and the data files only those snapshots reference. Time travel remains available within the seven-day window.notify posts a Discord confirmation naming the table, and the errors block posts a distinct alert when either step fails.Schedule trigger runs the flow every Sunday at 03:00, outside business hours.Maintenance SQL is easy to write and easy to forget. Kestra turns it into an operated process: a schedule that survives restarts, per-step execution history showing exactly when each table was last compacted, retries for transient cluster errors, and notifications on both success and failure. Adding the next table is a copy of two tasks, not a new cron entry on a forgotten VM.
iceberg catalog and a table matching iceberg.analytics.events, or adjust the table name in both statements.TRINO_URL: JDBC URL, e.g. jdbc:trino://host:443/iceberg/analytics (use https on 443 in production; password authentication requires TLS).TRINO_USERNAME: Trino username.TRINO_PASSWORD: Trino password.DISCORD_WEBHOOK_URL: Discord incoming webhook URL.iceberg.analytics.events with your catalog, schema, and table in both statements.disabled: false on the weekly trigger.remove_orphan_files as a third task for tables where failed writes leave unreferenced files.io.kestra.plugin.core.flow.Loop.retention_threshold per table to match your time travel and rollback requirements.WHERE clause to optimize to compact only recent partitions on very large tables.