Apache Iceberg™ 表的元数据与保留

Snowflake 根据您使用的目录类型(Snowflake 或外部)为 Apache Iceberg™ 表处理元数据。

备注

任何类型的 Iceberg 表都不支持使用 history.expire.min-snapshots-to-keep 表属性 (https://iceberg.apache.org/docs/1.2.1/configuration/#table-behavior-properties) 指定默认的最小快照数。

将 Snowflake 用作目录的表

Snowflake 管理此类表的元数据生命周期,并根据表数据和快照的保留期删除旧元数据、清单列表和清单文件。

要设置表数据和快照的保留期,请在账户、数据库、架构或表级别设置 DATA_RETENTION_TIME_IN_DAYS 参数。

创建

Snowflake 定期为 Apache Iceberg 规范第 2 版生成元数据,并将元数据写入外部卷的文件。每个新的元数据文件都包含自上次创建 Snowflake 生成的元数据文件以来所有的 DML 或者 DDL 变更。

您还可以使用 SYSTEM$GET_ICEBERG_TABLE_INFORMATION 函数按需创建元数据。有关说明,请参阅 生成 DML 变更的快照

有关查找元数据文件的信息,请参阅 数据和元数据目录

查看元数据创建历史记录

要访问元数据生成尝试的完整历史记录,请查看账户的查询历史记录并过滤结果。在 SQL 文本中搜索 SYSTEM$GET_ICEBERG_TABLE_INFORMATION 函数名称。

Snowflake 内部使用相同的 SYSTEM$GET_ICEBERG_TABLE_INFORMATION 函数生成表元数据。在查询历史记录中,Snowflake 所做的尝试出现在名为 SYSTEM 的用户名下。查询历史记录中的 STATUS 列指示元数据是否成功生成。

有关查看选项,请参阅 使用 Query History 监控查询活动

删除

当发生以下事件时,Snowflake 会从您的外部云存储中删除 Iceberg 元数据:

  • 删除表之后。

  • Iceberg 元数据引用已过期的快照或表数据。

数据保留期到期后并不会立即删除。因此,元数据存储可能会导致您的云存储提供商产生比数据表生命周期更长的费用。

警告

Snowflake 不支持 Snowflake 管理的 Iceberg 表的 故障安全,因为表数据位于您管理的外部云存储中。要保护 Iceberg 表数据,您需要通过云提供商配置数据保护和恢复。

删除表之后

删除表时,可以使用 UNDROP ICEBERG TABLE 命令在数据保留期内将其恢复。

保留期到期时,Snowflake 会从外部卷位置删除其已写入的任何表元数据和快照。删除是异步进行的,保留期过后可能需要几天时间才能完成。

备注

对于 转换表,Snowflake 仅删除表转换 生成的元数据。

快照过期后

数据保留期过后,Snowflake 会删除与过期快照相关的 Iceberg 元数据文件。删除通常会在快照过期后 7-14 天内进行。

只有之前的表快照才会过期。Snowflake 不会从外部云存储中删除指示表的最新(当前)状态的元数据文件。

使用外部目录的表

对于使用外部目录的表,Snowflake 会使用 DATA_RETENTION_TIME_IN_DAYS 参数的值来设置 Snowflake Time Travel 和取消删除表的保留期。当保留期到期时,Snowflake 不会 从外部云存储中删除 Iceberg 元数据或快照。

Snowflake 在表级别将 DATA_RETENTION_TIME_IN_DAYS 设置为以下值中的较小值:

  • 当前元数据文件中的 history.expire.max-snapshot-age-ms 值。Snowflake 会将值转换为天数(四舍五入)。

  • 以下值取决于您的 Snowflake 账户版本

    • Standard Edition:1 天。

    • Enterprise Edition(或更高版本):5 天。

您无法手动更改 Snowflake 中的 DATA_RETENTION_TIME_IN_DAYS 值。要更改值,必须更新元数据文件中的 history.expire.max-snapshot-age-ms,然后 刷新表

您可以使用以下表函数检索有关注册到外部管理的 Iceberg 表的文件的信息或最近的快照刷新历史记录:

基于 Delta 的表

备注

如果您想对基于 Delta 的 Iceberg 表使用元数据写入,则您的账户不得禁用 2025_01 行为变更捆绑包

对于从 Delta 表文件创建的 Iceberg 表,如果您为外部卷配置写入权限,Snowflake 会自动将 Iceberg 元数据写入外部存储(请参阅 ALLOW_WRITES)。有关写入位置的更多信息,请参阅 数据和元数据目录

为防止 Snowflake 写入 Iceberg 元数据,只要没有 Snowflake 管理的 Iceberg 表使用相同的外部卷,您就可以在外部卷上将 ALLOW_WRITES 参数设置为 FALSE。

Iceberg partitioning

"Hidden" partitioning (https://iceberg.apache.org/docs/latest/partitioning/#icebergs-hidden-partitioning) for Apache Iceberg™ is metadata-based and adaptable. Iceberg produces partition values based on transforms that you define when you create a table. When they read from a partitioned table, Iceberg engines use the partition values defined in your table metadata to efficiently identify relevant data.

Snowflake supports the following partitioning use cases:

To create a partitioned Iceberg table, include the PARTITION BY clause with one or more partition transforms (https://iceberg.apache.org/spec/#partition-transforms) in your regular CREATE ICEBERG TABLE statement. For an example, see 在目录链接的数据库中创建 Iceberg 表.

Partitioning support matrix

The following table shows which features and actions are supported for each type of partitioned Iceberg table, and indicates compliance with version 2 of the Apache Iceberg specification.

备注

  • Version 3 of the Apache Iceberg specification isn't supported when using partitioning.

  • CLD stands for catalog-linked database.

Snowflake managed

Externally managed (CLD)

Externally managed (non-CLD)

Iceberg spec V2 compatibility

Comment

COPY commands with the ON_ERROR = ABORT_STATEMENT option

COPY INTO <table>

Limited support

Limited support

Limited support

Limited support

See 使用说明.

CREATE ICEBERG TABLE ... AS SELECT (CTAS)

Cloning

See usage notes:

CREATE ICEBERG TABLE … LIKE

See usage notes:

Deletion vectors

N/A

Clustering

Partition evolution

Limited support

Limited support

Limited support

We support partition evolution if it is done with an external engine.

Partition transforms

For the supported partition transforms, see:

Positional deletes

Snowpipe

Limited support

Limited support

Limited support

Limited support

  • Currently in Public Preview.

  • See the usage notes for COPY INTO <table>.

Snowpipe Streaming

Sorting within partitions

TARGET_FILE_SIZE

Partitioning considerations

Consider the following before you use partitioned writes for Iceberg tables:

  • If you use an external engine to add, drop, or replace a partition field in an externally managed table, Snowflake writes data according to the latest partition specification.

  • The GET_DDL function doesn't include the PARTITION BY clause in its output.

  • The sum of the sizes of the outputs for all partition transforms can't exceed 1024 bytes for a single row.

  • Because partition evolution isn't supported for Snowflake-managed tables, you must drop the table and create a new one with partitioning.

  • The DAY(), MONTH(), YEAR() partition transform parameters, which you specify within the PARTITION BY clause under table properties, are part of the Iceberg specification. For multiple days, months, or years, the partition expression parameter returns a partition for each calendar day, month, or year. For example, when the DAY() transform is used on a timestamp column that has 2 months of data, 61 partitions are created.

    In contrast, the DAY(), MONTH(), YEAR() functions in Snowflake are part of the SQL standard. For multiple days, months, or years, these functions extract the corresponding day, month, or year part from a date or timestamp. For example, when the DAY() function is used on a timestamp column that has multiple months of data, this function returns a day of the month ranging from 1 to 31.

Time Travel

通过 Snowflake Time Travel,您可以使用 Snowflake 查询表的历史数据。

当您 将 Snowflake 管理的表与 Snowflake Open Catalog 同步 或使用 Snowflake 目录 SDK 时,还可以使用第三方计算引擎在 Snowflake 管理的表上执行 Time Travel 查询。

您可以查询数据保留期内提交的任何快照。要指定数据保留期限,请设置 DATA_RETENTION_TIME_IN_DAYS 对象参数。

当您删除表数据或删除表时,Snowflake 会在表保留期到期后删除对象。这可能会导致您的云存储提供商产生比数据表生命周期更长的费用。

语言: 中文