最近更新时间:2023.07.12 10:25:15
首次发布时间:2022.09.22 16:55:46
Hive 支持通过内表或外表的方式访问 Iceberg 数据。本文通过示例为您介绍如何使用 E-MapReduce(EMR)上的 Hive 访问 Iceberg 数据。
适合 EMR 1.2.0以后的版本(包括EMR 1.2.0)
已创建 EMR 集群,且安装有 Iceberg 组件。有两种方式可以安装 Iceberg 组件:
对于插入数据操作,要求 Hive 的执行引擎需要为 mr。
使用 SSH 方式登录到集群主节点,详情请参见使用 SSH连接主节点。
在集群主机 Linux Bash 中执行如下进入Hive命令行
hive
也可以参考 Hive组件手册 采用beeline命令,举例:
beeline -u jdbc:hive2://emr-master-1:10000/default -n hive -p <hive用户的密码>
引入 Iceberg 的执行jar
ADD JAR /usr/lib/emr/current/iceberg/lib/iceberg-hive-runtime-0.14.0.jar;
说明
不同 EMR 版本,Iceberg 的版本号可能不同。建议采用如下命令来定位您的 iceberg-hive-runtime-xx.xx.xx.jar 路径:
$ ls /usr/lib/emr/current/iceberg/lib/iceberg-hive-runtime-*.jar
配置 Iceberg 的 Catalog信息
Hive 中支持 Iceberg 的 Catalog type 有 Hive、Hadoop,也可以为空。 type 不同,配置项也不同。可参考 Iceberg参数配置章节。下面以 Hive 类型为例,创建 Catalog 名称为 Iceberg:
SET iceberg.catalog.iceberg.type=hive; SET iceberg.catalog.iceberg.uri=thrift://emr-master-1:9083; SET iceberg.catalog.iceberg.clients=10;
创建表
CREATE DATABASE IF NOT EXISTS iceberg_db; CREATE EXTERNAL TABLE iceberg_db.table_a1(i INT, s STRING) STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler' TBLPROPERTIES ('iceberg.catalog'='iceberg');
插入数据
-- 更改Hive的执行引擎为mr SET hive.execution.engine = mr; INSERT INTO iceberg_db.table_a1 VALUES(0, 'a');
说明
对于 INSERT 操作,只支持 mr 引擎 。
查询
SELECT * FROM iceberg_db.table_a1;
删除表
DROP TABLE IF EXISTS iceberg_db.table_a1;
说明
删除表,也会将表的数据进行删除,但在HDFS上会留存表名的相关空目录