作者:闻乃松
Iceberg作为一种表格式管理规范,其数据分为元数据和表数据。元数据和表数据独立存储,元数据目前支持存储在本地文件系统、HMS、Hadoop、JDBC数据库、AWS Glue和自定义存储。表数据支持本地文件系统、HDFS、S3、MinIO、OBS、OSS等。元数据存储基于HMS比较广泛,在这篇文章中,表数据存储基于MinIO、元数据存储主要基于HMS。实际上,基于HMS存储的元数据也只是很少的信息存储在HMS中,主体元数据还是存储在外部系统,如HDFS、MinIO等,所以这里也不得不提基于Hadoop存储的方式。
Iceberg的元数据管理通过Catalog类型指定,我们主要关注hive、hadoop和location_based_table这三种。
如果不指定任何Catalog类型,直接创建表会怎么样呢?
add jar /Users/deepexi/.m2/repository/org/apache/iceberg/iceberg-hive-runtime/0.13.2/iceberg-hive-runtime-0.13.2.jar;
SET hive.vectorized.execution.enabled=false;
CREATE TABLE default.sample_local_hive_table_1( id bigint, name string )
PARTITIONED BY( dept string )
STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler';
创建Iceberg表需要借助HiveIcebergStorageHandler来实现,此时只会在本地HMS(hive-site.xml中配置) 中存储元数据,元数据表table_params显示,当前表的存储位置使用了本地HMS (hive-site.xml中配置)的文件存储路径:
这符合创建Hive表的常规动作。来看看,如果指定hive的Catalog,并配置远程的HMS,会怎么样?
注册hive类型的Catalog
这里注册了一个远端的HMS地址:
SET iceberg.catalog.another_hive.type=hive;
SET iceberg.catalog.another_hive.uri=thrift://10.201.0.202:49153;
SET iceberg.catalog.another_hive.warehouse=s3a://faas-ethan/warehouse/;
SET hive.vectorized.execution.enabled=false;
在当前HiveCli创建Hive Iceberg 表,同时指定location 存储位置,使用上面注册的hive类型的Catalog:
CREATE TABLE default.sample_hive_table_1( id bigint, name string )
PARTITIONED BY( dept string )
STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' location 's3a://faas-ethan/warehouse/default/sample_hive_table_1'
TBLPROPERTIES ('iceberg.catalog'='another_hive');