Community研究與資料分析github.com

建立與操作 Iceberg 資料表

設計與操作 Apache Iceberg 資料表——包含分割與隱藏分割、分割/綱要演進、快照與時間旅行、壓縮與小檔案清理,以及在 Spark、Flink、Trino 或 Snowflake 上的 MERGE/upsert 操作。適用於建立或維護 Iceberg 資料表、選擇分割方式、演進分割/綱要,或修復小檔案與中繼資料膨脹問題。

建立與操作 Iceberg 資料表 是什麼?

此技能專為開發者與 AI 代理者設計,提供在湖倉架構中建立與維護 Apache Iceberg 資料表的完整指引。它涵蓋了關鍵操作,例如透過隱藏分割轉換(如 `days(ts)`、`bucket(N, id)`)進行分割設計,使查詢能自動進行分割剪枝,無需使用者手動加入衍生分割欄位。此外,技能詳細說明如何透過 `MERGE INTO` 實現冪等寫入、使用 `rewrite_data_files` 壓縮小檔案、設定快照過期與孤兒檔案清理,以及透過欄位 ID 自由演進分割/綱要,無需資料重寫。此技能支援 Spark、Flink、Trino 與 Snowflake 平台,並包含多個 SQL 範例與常見陷阱提示,適合用於建立、調校或排程 Iceberg 資料表維護任務。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Unknown-333/awesome-data-engineering-skills/tree/main/skills/building-iceberg-tables

Installed? Explore more 研究與資料分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

建立 Iceberg 資料表

使用時機

  • 在湖倉上建立或維護 Apache Iceberg 資料表。
  • 選擇分割方式,或演進分割/綱要而無需重寫資料。
  • 管理快照、時間旅行、壓縮與小檔案。
  • 不要用於 Delta 專屬工作(請使用 engineering-databricks-pipelines)。

工作流程

- [ ] 根據查詢篩選欄位進行分割;使用隱藏分割轉換
- [ ] 使用 MERGE 進行冪等 upsert
- [ ] 排程壓縮(rewrite_data_files)以修復小檔案
- [ ] 過期舊快照並移除孤兒檔案,以控制中繼資料/儲存空間
- [ ] 透過欄位 ID 演進分割/綱要(無需資料重寫)
  1. 根據篩選欄位進行分割,使用隱藏分割轉換 (days(ts)、bucket(N, id)),讓查詢能自動進行分割剪枝,無需使用者手動加入衍生分割欄位。
  2. 冪等寫入,透過以商業鍵為條件的 MERGE INTO。
  3. 定期壓縮——串流/小批次寫入會產生大量小檔案;rewrite_data_files 可恢復讀取效能。
  4. 維護中繼資料——過期舊快照並移除孤兒檔案,否則快照歷史與儲存空間會無限增長。
  5. 自由演進——Iceberg 透過 ID 追蹤欄位/分割,因此新增/刪除/重新命名,甚至分割規格變更都無需資料重寫。

模式

建立時使用隱藏分割 + MERGE upsert:

CREATE TABLE lake.db.orders (order_id BIGINT, customer_id BIGINT, amount DECIMAL, ordered_at TIMESTAMP)
USING iceberg PARTITIONED BY (days(ordered_at));

MERGE INTO lake.db.orders t USING staging s ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

維護(Spark 程序):

CALL lake.system.rewrite_data_files('db.orders');       -- 壓縮小檔案
CALL lake.system.expire_snapshots('db.orders', TIMESTAMP '2026-08-01 00:00:00');
CALL lake.system.remove_orphan_files(table => 'db.orders');

時間旅行——讀取先前的快照以進行稽核或復原: SELECT * FROM lake.db.orders VERSION AS OF <snapshot_id>。

分割演進——ALTER TABLE ... ADD PARTITION FIELD bucket(16, customer_id) 僅套用於新資料;舊資料仍然有效。

常見陷阱

  • 串流資料表未進行壓縮——小檔案爆炸會嚴重拖慢讀取速度。
  • 從未過期快照——中繼資料和儲存空間無限制增長;應在時間旅行保留期限內設定過期。
  • 過度分割(例如對低資料量按小時分割)——產生過多微小分割區;應根據資料量調整粒度。
  • 加入明確的衍生分割欄位——違背隱藏分割的本意;請使用轉換函式。
  • 直接覆蓋而非 MERGE——失去冪等性;請按鍵值使用 MERGE。
  • 移除孤兒檔案時時間窗口過短——可能刪除仍在寫入中的檔案;請使用安全截止時間。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

Unknown-333/authoring-airflow-dags

Write production-grade Apache Airflow DAGs using the TaskFlow API — idempotent tasks, correct scheduling and catchup, retries/SLAs, connections/variables, and avoiding top-level code. Use when creating or reviewing Airflow DAGs, scheduling pipelines, wiring task dependencies, configuring retries/backfills, or fixing non-idempotent tasks.

Unknown-333/building-dagster-assets

Build Dagster pipelines using software-defined assets — asset dependencies, partitions, resources and IO managers, asset checks, and schedules/sensors. Use when creating Dagster assets or jobs, modeling data as assets, adding partitions or backfills, wiring resources/IO managers, or migrating from task-based orchestration to assets.

Unknown-333/building-dbt-models

Build well-structured dbt models — staging/intermediate/marts layers, ref() and source(), materializations, and incremental models with the right strategy. Use when creating or refactoring dbt models, choosing table vs view vs incremental, structuring a dbt project, or writing incremental logic.

Unknown-333/building-feature-pipelines

Build ML feature pipelines and feature stores — point-in-time-correct joins to avoid label leakage, offline/online parity, feature freshness and backfills, and materialization with tools like Feast. Use when engineering features for ML, preventing train/serve skew or data leakage, building a feature store, or backfilling historical features for training.

Unknown-333/building-ingestion-pipelines

Build batch and incremental data ingestion (extract-load) pipelines — full vs incremental extraction, change data capture (CDC), watermarks and high-water marks, API pagination and rate limits, and choosing managed EL tools (Fivetran, Airbyte) vs custom code. Use when ingesting data from databases, APIs, files, or SaaS into a warehouse/lake, or designing incremental extraction and CDC.

Unknown-333/building-kafka-consumers

Build reliable Apache Kafka consumers and producers — consumer groups and partition assignment, offset commit strategy, at-least-once vs exactly-once, idempotent/transactional producers, rebalancing, and dead-letter handling. Use when writing Kafka consumers/producers, configuring offset commits or consumer groups, tuning throughput, or handling rebalances and poison messages.

Unknown-333/debugging-data-pipelines

Systematically root-cause data pipeline failures and data incidents — job errors, wrong or missing data, duplicates, and freshness misses — by tracing lineage upstream, isolating the failing stage, reconciling against source, and planning a safe fix and backfill. Use when a pipeline fails, numbers look wrong, data is missing or duplicated, a dashboard is stale, or a stakeholder reports a data discrepancy.

Unknown-333/designing-backfills-and-replays

Plan and run safe data backfills and replays — idempotent reprocessing of historical windows, partition-by-partition execution, isolating backfill compute from production, verifying results, and avoiding double-counting or changed history. Use when backfilling a new or fixed model, reprocessing after a bug, replaying events, or loading history for a new pipeline without corrupting existing data.

Unknown-333/designing-data-contracts

Define and enforce data contracts between producers and consumers — explicit schema, semantics, ownership, SLAs, and versioning — to prevent silent upstream changes from breaking downstream pipelines. Use when a producer schema change could break consumers, defining an interface between teams/services and the warehouse, or adding schema enforcement at ingestion.

相關技能