在 Snowflake 中创建 Apache Iceberg™ 表¶
在Snowflake中为不同的 目录选项 创建 Apache Iceberg™ 表。您可以使用 CREATE ICEBERG TABLE 命令创建 Iceberg 表。
备注
要创建 Iceberg 表,您必须有一个正在运行的仓库,该仓库被指定为会话的当前仓库。如果在创建 Iceberg 表时未指定正在运行的仓库,则可能会发生错误。有关更多信息,请参阅 使用仓库。
要创建与 Snowflake Open Catalog 配合使用的 Iceberg 表,请参阅 在 Snowflake 中将 Apache Iceberg™ 表与 Snowflake Open Catalog 结合使用。
Snowflake 管理的¶
To create an Iceberg table with Snowflake as the catalog, you specify an external volume and a base location (directory on the external volume) where Snowflake can write table data and metadata.
You can use one of the following storage options:
Your cloud storage: Create an external volume and reference it from the table. For instructions, see 配置外部卷.
Snowflake-provided storage: Set
EXTERNAL_VOLUME = 'SNOWFLAKE_MANAGED'(or rely on defaults when the catalog is Snowflake). You don't create a separate external volume object for that path. For more information, see 适用于 Apache Iceberg™ 表的 Snowflake Storage.
要定义表列,可以使用 Iceberg 数据类型。有关更多信息,请参阅 Apache Iceberg™ 表的数据类型。
The following example creates an Iceberg table with Snowflake as the Iceberg catalog, and uses the value of the column named int_col
to partition the table:
备注
或者,使用变体语法。有关更多信息,请参阅 CREATE TABLE ...AS SELECT 和 CREATE ICEBERG TABLE ...LIKE。
创建使用 Snowflake 作为目录的表后,您可以执行以下操作:
有关更多信息,请参阅 管理 Apache Iceberg™ 表。
外部目录¶
要创建使用外部目录或根本不使用目录的 Iceberg 表,必须指定 外部卷 和 目录集成。如果使用外部 Iceberg 目录,可能还需要指定其他参数。例如,使用 AWS Glue 作为目录时,必须指定目录表名称。
创建使用外部目录的 Iceberg 表时,Snowflake 会执行初始元数据刷新。您还可以使用 ALTER ICEBERG TABLE ... REFRESH 命令手动刷新表元数据,以将元数据与最近的表更改同步。有关更多信息,请参阅 刷新表元数据。
备注
CREATE ICEBERG TABLE 命令支持不同外部目录的不同选项。本节中的示例仅指定了部分可用选项。要查看完整的语法,请参阅以下页面:
您还可以通过使用 ALTER ICEBERG TABLE 为外部管理的表配置数据治理(例如,掩码或行访问策略)。
对象存储中的 Iceberg 文件¶
以下示例从外部云存储中的 Iceberg 元数据创建 Iceberg 表,并指定外部卷 (METADATA_FILE_PATH) 上表元数据的相对路径。
Delta files in object storage (Delta Direct)¶
Delta Direct is the Snowflake documentation name for this workflow: you store Delta Lake data in external object storage,
configure a catalog integration with TABLE_FORMAT = DELTA, and create an Iceberg table that points at the Delta log and
Parquet files. For full syntax, prerequisites, and usage notes, see CREATE ICEBERG TABLE(对象存储中的 Delta 文件).
以下示例命令根据对象存储中的 Delta 表文件创建 Iceberg 表,并 自动刷新。
该示例指定与 Delta 表文件的云位置关联的外部卷、为 Delta <label-tables_iceberg_create_cat_int_delta> 配置的目录集成`以及所需 :code:`BASE_LOCATION 参数的值。
如果 Delta 表使用分区架构,Snowflake 会自动通过 Delta 日志解释该架构。
Apache Iceberg™ REST 目录¶
以下示例创建了一个使用远程 Iceberg REST 目录 的表。
有关按用例划分的更多示例,请参阅以下主题: