Community研究与数据分析github.com

构建 Iceberg 表

设计和管理 Apache Iceberg 表,包括分区与隐藏分区、分区/模式演化、快照与时间旅行、压缩与小文件清理,以及用于湖仓一体表上的 MERGE/upsert 操作。适用于创建或维护 Iceberg 表、选择分区策略、演化模式/分区,或修复小文件与元数据膨胀问题。

构建 Iceberg 表 是什么?

该技能指导开发者设计和运维 Apache Iceberg 表,重点涵盖隐藏分区、模式演化、快照管理、时间旅行、压缩以及小文件清理等核心能力。它基于 Iceberg 的架构特性,如按 ID 追踪列和分区、不重写数据的模式演化,以及通过 hidden partition transforms 实现查询剪枝。技能适用于 Spark、Flink、Trino、Snowflake 等引擎,提供从建表、MERGE 幂等写入、定期压缩调度到快照过期和孤立文件清理的完整工作流。同时指出了常见陷阱,如流式表不做压缩导致小文件爆炸、不设置过期策略使元数据无限增长、过度分区以及误用显式派生分区列等。该技能特别适合在湖仓一体环境中需要利用 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.

相关技能