Skip to content

Commit 8e4c50d

Browse files
committed
[feat](iceberg) Support publish_changes for iceberg table
1 parent f33d206 commit 8e4c50d

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

docs/lakehouse/catalogs/iceberg-catalog.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,51 @@ EXECUTE set_current_snapshot ("ref" = "v1.0");
21992199
3. If the specified snapshot ID or reference does not exist, the operation will fail
22002200
4. If the current snapshot is already the target snapshot, the operation returns directly without creating a new snapshot
22012201

2202+
### publish_changes
2203+
2204+
The `publish_changes` operation is used in the WAP (Write-Audit-Publish) mode to publish a snapshot with the specified `wap.id` as the current table state.
2205+
It locates the snapshot whose `wap.id` matches the given `wap_id` and cherry-picks it onto the current table, making the staged data visible to all read operations.
2206+
2207+
**Syntax:**
2208+
2209+
```sql
2210+
ALTER TABLE [catalog.][database.]table_name
2211+
EXECUTE publish_changes("wap_id" = "<wap_id>")
2212+
```
2213+
2214+
**Parameters:**
2215+
2216+
**Parameters:**
2217+
2218+
| Parameter Name | Type | Required | Description |
2219+
| -------------- | ---- | -------- | ----------- |
2220+
| `wap_id` | STRING | Yes | The WAP snapshot ID to be published |
2221+
2222+
**Return Value:**
2223+
2224+
Executing `publish_changes` returns a result set with the following 2 columns:
2225+
2226+
| Column Name | Type | Description |
2227+
| ----------- | ---- | ----------- |
2228+
| `previous_snapshot_id` | STRING | The ID of the current snapshot before the publish operation (NULL if none) |
2229+
| `current_snapshot_id` | STRING | The ID of the new snapshot created and set as current after publishing |
2230+
2231+
**Examples:**
2232+
2233+
```sql
2234+
-- Publish the snapshot whose WAP ID is test_wap_001
2235+
ALTER TABLE iceberg_db.iceberg_table
2236+
EXECUTE publish_changes("wap_id" = "test_wap_001");
2237+
```
2238+
2239+
**Notes:**
2240+
2241+
1. This operation does not support a WHERE clause, nor PARTITION/PARTITIONS clauses
2242+
2. It is only meaningful for Iceberg tables with write.wap.enabled = true and WAP snapshots generated via wap.id
2243+
3. If no snapshot is found for the specified wap_id, the operation fails and throws an error
2244+
4. After publishing, the new snapshot becomes the current snapshot
2245+
5. If there is no snapshot before publishing, previous_snapshot_id may be NULL
2246+
22022247
## Iceberg Table Optimization
22032248

22042249
### View Data File Distribution

i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/lakehouse/catalogs/iceberg-catalog.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,49 @@ EXECUTE set_current_snapshot ("ref" = "v1.0");
22102210
3. 如果指定的快照 ID 或引用不存在,操作会失败
22112211
4. 如果当前快照已经是目标快照,操作会直接返回,不会创建新快照
22122212

2213+
### publish_changes
2214+
2215+
`publish_changes` 操作用于在 WAP(Write-Audit-Publish)模式下,将带有指定 `wap.id` 的快照发布为当前表状态。
2216+
它会找到与给定 `wap_id` 匹配的快照,并通过 *cherrypick* 的方式将其合并到当前表中,使这批暂存数据对所有读取操作可见。
2217+
2218+
**语法:**
2219+
2220+
```sql
2221+
ALTER TABLE [catalog.][database.]table_name
2222+
EXECUTE publish_changes("wap_id" = "<wap_id>")
2223+
```
2224+
2225+
**参数说明:**
2226+
2227+
| 参数名称 | 类型 | 必填 | 描述 |
2228+
| -------- | ---- | ---- | ---- |
2229+
| `wap_id` | STRING || 要发布的 WAP 快照 ID |
2230+
2231+
**返回值:**
2232+
2233+
执行 `publish_changes` 操作会返回一个结果集,包含以下 2 列:
2234+
2235+
| 列名 | 类型 | 描述 |
2236+
| ---- | ---- | ---- |
2237+
| `previous_snapshot_id` | STRING | 发布操作前当前快照的 ID(如果不存在则为 NULL) |
2238+
| `current_snapshot_id` | STRING | 发布操作后新创建并设置为当前快照的 ID |
2239+
2240+
**示例:**
2241+
2242+
```sql
2243+
-- 发布 WAP ID 为 test_wap_001 的快照
2244+
ALTER TABLE iceberg_db.iceberg_table
2245+
EXECUTE publish_changes("wap_id" = "test_wap_001");
2246+
```
2247+
2248+
**注意事项:**
2249+
2250+
1. 该操作不支持WHERE条件,也不支持分区(PARTITION/PARTITIONS)子句
2251+
2. 仅对启用了write.wap.enabled = true并通过wap.id产生 WAP 快照的 Iceberg 表有意义
2252+
3. 如果找不到与指定wap_id对应的快照,操作会失败并抛出错误
2253+
4. 发布后,新快照将成为当前快照
2254+
5. 如果在发布前表还没有任何快照,则previous_snapshot_id可能为 NULL
2255+
22132256
## Iceberg 表优化
22142257

22152258
### 查看数据文件分布

versioned_docs/version-4.x/lakehouse/catalogs/iceberg-catalog.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,51 @@ EXECUTE set_current_snapshot ("ref" = "v1.0");
21992199
3. If the specified snapshot ID or reference does not exist, the operation will fail
22002200
4. If the current snapshot is already the target snapshot, the operation returns directly without creating a new snapshot
22012201

2202+
### publish_changes
2203+
2204+
The `publish_changes` operation is used in the WAP (Write-Audit-Publish) mode to publish a snapshot with the specified `wap.id` as the current table state.
2205+
It locates the snapshot whose `wap.id` matches the given `wap_id` and cherry-picks it onto the current table, making the staged data visible to all read operations.
2206+
2207+
**Syntax:**
2208+
2209+
```sql
2210+
ALTER TABLE [catalog.][database.]table_name
2211+
EXECUTE publish_changes("wap_id" = "<wap_id>")
2212+
```
2213+
2214+
**Parameters:**
2215+
2216+
**Parameters:**
2217+
2218+
| Parameter Name | Type | Required | Description |
2219+
| -------------- | ---- | -------- | ----------- |
2220+
| `wap_id` | STRING | Yes | The WAP snapshot ID to be published |
2221+
2222+
**Return Value:**
2223+
2224+
Executing `publish_changes` returns a result set with the following 2 columns:
2225+
2226+
| Column Name | Type | Description |
2227+
| ----------- | ---- | ----------- |
2228+
| `previous_snapshot_id` | STRING | The ID of the current snapshot before the publish operation (NULL if none) |
2229+
| `current_snapshot_id` | STRING | The ID of the new snapshot created and set as current after publishing |
2230+
2231+
**Examples:**
2232+
2233+
```sql
2234+
-- Publish the snapshot whose WAP ID is test_wap_001
2235+
ALTER TABLE iceberg_db.iceberg_table
2236+
EXECUTE publish_changes("wap_id" = "test_wap_001");
2237+
```
2238+
2239+
**Notes:**
2240+
2241+
1. This operation does not support a WHERE clause, nor PARTITION/PARTITIONS clauses
2242+
2. It is only meaningful for Iceberg tables with write.wap.enabled = true and WAP snapshots generated via wap.id
2243+
3. If no snapshot is found for the specified wap_id, the operation fails and throws an error
2244+
4. After publishing, the new snapshot becomes the current snapshot
2245+
5. If there is no snapshot before publishing, previous_snapshot_id may be NULL
2246+
22022247
## Iceberg Table Optimization
22032248

22042249
### View Data File Distribution

0 commit comments

Comments
 (0)