iceberg FlinkSQL 特性
版本
iceberg 1.2.0
flink 1.16.0
建表与限制
创建一个带有主键的FlinkSQL表
CREATE TABLE `hive_catalog`.`default`.`sample_with_key` (id BIGINT COMMENT 'unique id',data STRING,primary key (id) not enforced
);
截止 iceberg 1.2.0 FlinkSQL 不支持隐式分区,不支持计算列,watermark
FlinkSQL 在hive中创建的表默认是外部表
修改表和删除表
ALTER TABLE `hive_catalog`.`default`.`sample` SET ('write.format.default'='avro');ALTER TABLE `hive_catalog`.`default`.`sample` RENAME TO `hive_catalog`.`default`.`new_sample`;
drop table new_sample;
因为是默认创建的外部表,删除后在hdfs还存在data和metadata目录,但是数据被清空了
插入表和upsert问题
iceberg v2 版本的表在创建了主键的前提下支持upsert操作
CREATE TABLE `hive_catalog`.`default`.`sample_test_upsert` (`id` INT COMMENT 'unique id',`data` STRING NOT NULL,PRIMARY KEY(`id`) NOT ENFORCED
) with ('format-version'='2', 'write.upsert.enabled'='true');
在upsert模型下,分区字段必须是主键
upsert模式下存在的问题是,性能不好
新增两条数据
INSERT INTO `hive_catalog`.`default`.`sample_test_upsert` VALUES (1, 'a');
INSERT INTO `hive_catalog`.`default`.`sample_test_upsert` VALUES (2, 'b');
修改主键为2的数据
INSERT INTO `hive_catalog`.`default`.`sample_test_upsert` VALUES (2, 'c');
结果是主键为2的数据的data字段的字从b更新为了c