用途
该技能使智能体能够原生使用 Apache Iceberg 分支来建模、实现和编排 Write-Audit-Publish(WAP)模式。
其背景是:在企业数据湖仓中,ETL 过程直接写入生产表(main 分支)存在极大的数据损坏风险。Apache Iceberg 通过类 Git 的分支能力原生解决这一问题。技能要求智能体以 WAP 模式替代传统的暂存表(staging tables)做法。
主要能力与使用方式
WAP 模式流程
技能不再创建 _stg 表,而是指导用户使用 Iceberg 分支,分为五步:
第 1 步:创建分支 创建指向 main 当前状态的分支。
ALTER TABLE prod.sales.transactions CREATE BRANCH etl_job_123;
第 2 步:配置 Spark 写入分支 必须显式告知 Spark 写入指定分支。
# PySpark Example
spark.conf.set("spark.wap.branch", "etl_job_123")
# Now any INSERT or MERGE INTO statement goes to the branch
df.writeTo("prod.sales.transactions").append()
第 3 步:审计 / 数据质量检查 从分支读取数据,验证行数、空值和约束。
SELECT count(*) FROM prod.sales.transactions VERSION AS OF 'etl_job_123';
-- Trigger Soda or Great Expectations on this branch
第 4 步:发布(快速前进 Fast-Forward) 审计通过后,将分支发布回 main。
CALL catalog.system.fast_forward('prod.sales.transactions', 'main', 'etl_job_123');
第 5 步:清理
ALTER TABLE prod.sales.transactions DROP BRANCH etl_job_123;
隐藏分区(Hidden Partitioning)
Iceberg 使用隐藏分区。如果用户试图手动提取年份或月份来进行分区,技能给出了对比示例:
❌ 错误做法:
df.withColumn("year", year("ts")).write.partitionBy("year")
✅ 正确做法:
CREATE TABLE ... PARTITIONED BY (years(ts))
技能要求向用户解释:Iceberg 会自动处理分区提取,无需显式创建分区列。
输出格式
技能规定的输出为「Iceberg WAP 实施指南」,结构如下:
Write-Audit-Publish (WAP) Plan: [Table Name]
1. Branch Creation
Run: ALTER TABLE ... CREATE BRANCH ...
2. Spark Write Configuration
Ensure your SparkSession has: spark.wap.branch=[branch_name]
3. Audit Queries
- Run:
SELECT ... VERSION AS OF '[branch_name]' - Expected: 0 Nulls.
4. Publish Command
Run: CALL catalog.system.fast_forward(...)
适用场景与限制
适用场景为企业数据湖仓中需要避免直接写入生产表的 ETL 流程,通过分支隔离写入、审计与发布。技能涉及的工具包括 Apache Iceberg、Spark、Soda 或 Great Expectations。关于支持平台、版本要求、收费情况、性能效果等,资料中暂未提供。