CREATE ICEBERG TABLE¶
在当前/指定架构中创建或替换 Apache Iceberg™ 表。
语法¶
本节概述了 所有 类型的 Iceberg 表的语法。创建 Iceberg 表的语法差异很大,具体取决于您是将 Snowflake 用作 Iceberg 目录还是外部 Iceberg 目录。
要查看特定用例的语法、参数说明、使用说明和示例,请参阅以下页面:
使用 Snowflake 作为 Iceberg 目录
外部 Iceberg 目录
使用 Snowflake 作为 Iceberg 目录¶
CREATE [ OR REPLACE ] ICEBERG TABLE [ IF NOT EXISTS ] <table_name> (
-- Column definition
<col_name> <col_type>
[ inlineConstraint ]
[ NOT NULL ]
[ { DEFAULT <expr>
| { AUTOINCREMENT | IDENTITY }
[ { ( <start_num> , <step_num> )
| START <num> INCREMENT <num>
} ]
} ]
[ [ WITH ] MASKING POLICY <policy_name> [ USING ( <col_name> , <cond_col1> , ... ) ] ]
[ [ WITH ] PROJECTION POLICY <policy_name> ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
[ COMMENT '<string_literal>' ]
-- Additional column definitions
[ , <col_name> <col_type> [ ... ] ]
-- Out-of-line constraints
[ , outoflineConstraint [ ... ] ]
)
[ CLUSTER BY ( <expr> [ , <expr> , ... ] ) ]
[ EXTERNAL_VOLUME = '<external_volume_name>' ]
[ CATALOG = 'SNOWFLAKE' ]
BASE_LOCATION = '<directory_for_table_files>'
[ CATALOG_SYNC = '<open_catalog_integration_name>']
[ STORAGE_SERIALIZATION_POLICY = { COMPATIBLE | OPTIMIZED } ]
[ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
[ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
[ CHANGE_TRACKING = { TRUE | FALSE } ]
[ COPY GRANTS ]
[ COMMENT = '<string_literal>' ]
[ [ WITH ] ROW ACCESS POLICY <policy_name> ON ( <col_name> [ , <col_name> ... ] ) ]
[ [ WITH ] AGGREGATION POLICY <policy_name> ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
其中:
inlineConstraint ::= [ CONSTRAINT <constraint_name> ] { UNIQUE | PRIMARY KEY | [ FOREIGN KEY ] REFERENCES <ref_table_name> [ ( <ref_col_name> ) ] } [ <constraint_properties> ]有关其他内联约束的详细信息,请参阅 CREATE | ALTER TABLE ...CONSTRAINT。
outoflineConstraint ::= [ CONSTRAINT <constraint_name> ] { UNIQUE [ ( <col_name> [ , <col_name> , ... ] ) ] | PRIMARY KEY [ ( <col_name> [ , <col_name> , ... ] ) ] | [ FOREIGN KEY ] [ ( <col_name> [ , <col_name> , ... ] ) ] REFERENCES <ref_table_name> [ ( <ref_col_name> [ , <ref_col_name> , ... ] ) ] } [ <constraint_properties> ]备注
Snowflake 表示定义为 PRIMARY KEY 的列,作为 Iceberg 元数据中的标识符字段。这些列的 IDs 在元数据中填充为 标识符字段 IDs (https://iceberg.apache.org/spec/#identifier-field-ids)。
Snowflake 不对 Iceberg 表的 PRIMARY KEY 列强制执行 NOT NULL 和 UNIQUE 约束条件。
有关其他行外约束的详细信息,请参阅 CREATE | ALTER TABLE ...CONSTRAINT。
有关更多信息,请参阅 CREATE ICEBERG TABLE(使用 Snowflake 作为 Iceberg 目录)。
CREATE ICEBERG TABLE ...AS SELECT(也称为 CTAS)
CREATE [ OR REPLACE ] ICEBERG TABLE <table_name> [ ( <col_name> [ <col_type> ] , <col_name> [ <col_type> ] , ... ) ] [ CLUSTER BY ( <expr> [ , <expr> , ... ] ) ] [ EXTERNAL_VOLUME = '<external_volume_name>' ] [ CATALOG = 'SNOWFLAKE' ] BASE_LOCATION = '<relative_path_from_external_volume>' [ COPY GRANTS ] [ ... ] AS SELECT <query>
有关更多信息,请参阅 CREATE ICEBERG TABLE ...AS SELECT。
CREATE ICEBERG TABLE ...LIKE
CREATE [ OR REPLACE ] ICEBERG TABLE <table_name> LIKE <source_table> [ CLUSTER BY ( <expr> [ , <expr> , ... ] ) ] [ COPY GRANTS ] [ ... ]
有关更多信息,请参阅 CREATE ICEBERG TABLE ... LIKE。
外部 Iceberg 目录¶
AWS Glue
CREATE [ OR REPLACE ] ICEBERG TABLE [ IF NOT EXISTS ] <table_name>
[ EXTERNAL_VOLUME = '<external_volume_name>' ]
[ CATALOG = '<catalog_integration_name>' ]
CATALOG_TABLE_NAME = '<catalog_table_name>'
[ CATALOG_NAMESPACE = '<catalog_namespace>' ]
[ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
[ AUTO_REFRESH = { TRUE | FALSE } ]
[ COMMENT = '<string_literal>' ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
有关更多信息,请参阅 CREATE ICEBERG TABLE(使用 AWS Glue 作为 Iceberg 目录)。
对象存储中的 Iceberg 文件
CREATE [ OR REPLACE ] ICEBERG TABLE [ IF NOT EXISTS ] <table_name>
[ EXTERNAL_VOLUME = '<external_volume_name>' ]
[ CATALOG = '<catalog_integration_name>' ]
METADATA_FILE_PATH = '<metadata_file_path>'
[ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
[ COMMENT = '<string_literal>' ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
有关更多信息,请参阅 CREATE ICEBERG TABLE(对象存储中的 Iceberg 文件)。
Delta 文件
CREATE [ OR REPLACE ] ICEBERG TABLE [ IF NOT EXISTS ] <table_name>
[ EXTERNAL_VOLUME = '<external_volume_name>' ]
[ CATALOG = '<catalog_integration_name>' ]
BASE_LOCATION = '<relative_path_from_external_volume>'
[ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
[ COMMENT = '<string_literal>' ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
有关更多信息,请参阅 CREATE ICEBERG TABLE(对象存储中的 Delta 文件)。
Iceberg REST API 或 Snowflake Open Catalog
CREATE [ OR REPLACE ] ICEBERG TABLE [ IF NOT EXISTS ] <table_name>
[ EXTERNAL_VOLUME = '<external_volume_name>' ]
[ CATALOG = '<catalog_integration_name>' ]
CATALOG_TABLE_NAME = '<rest_catalog_table_name>'
[ CATALOG_NAMESPACE = '<catalog_namespace>' ]
[ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
[ AUTO_REFRESH = { TRUE | FALSE } ]
[ COMMENT = '<string_literal>' ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
有关更多信息,请参阅 CREATE ICEBERG TABLE(Iceberg REST 目录)。