Iceberg客户端使用 Flink操作Iceberg Iceberg支持Flink的DataStream API和Table API。在Flink中创建Iceberg表时,建议使用Flink SQL客户端,因为这样使用更加便捷。 在/usr/local路径下部署完Flink后,需要先启动一个独立的Flink集群。 plaintext /usr/local/flink/bin/startcluster.sh 检测Flink的lib文件夹,确保存在icebergflinkruntimexxx.jar。然后执行如下命令,启动Flink SQL客户端。 plaintext /usr/local/flink/bin/sqlclient.sh 然后输入如下参数,使得Flink SQL 作业可以提交到Yarn上执行。 plaintext SET 'execution.target' 'yarnperjob'; SET execution.checkpointing.interval 30s; 1、创建catalog Flink支持使用Flink SQL创建catalog,可以创建Hive类型的catalog。 参考如下示例,注册一个名为hivetest的Hive类型catalog,其中Hive的部署路径为/usr/local/hive,因此示例中'hiveconfdir'值为/usr/local/hive/conf。 plaintext CREATE CATALOG hivetest WITH ( 'type''iceberg', 'catalogtype''hive', 'hiveconfdir''/usr/local/hive/conf' ); 2、创建表 参考如下示例,基于hivetest catalog,创建一个名为test的Iceberg分区表。 plaintext CREATE TABLE hivetest.default.test (id bigint, name string, category string) PARTITIONED BY (category); 3、写入数据 在Iceberg表被创建后,使用INSERT INTO语法执行数据的写入操作。 plaintext INSERT INTO hivetest.default.test VALUES (1, 'john', 't1'), (2, 'Tony', 't2'), (3, 'lady', 't3'); 4、读取数据 在往Iceberg表中写入一定数量的数据后,使用SELECT查询语法执行数据的读取操作。 plaintext SELECT from hivetest.default.test;