Apache Paimon Hive引擎解析

HIve 引擎

Paimon 当前支持 Hive 的 3.1, 2.3, 2.2, 2.1 和 2.1-cdh-6.3 版本。

1.执行引擎

当使用Hive Read数据时,Paimon 支持 MR 和 Tez 引擎, 当使用Hive Write数据时,Paimon支持MR引擎,如果使用 beeline,需要重启hive cluster。

2.安装
Version           Jar
Hive 3.1	        paimon-hive-connector-3.1-0.7.0-incubating.jar
Hive 2.3	        paimon-hive-connector-2.3-0.7.0-incubating.jar
Hive 2.2	        paimon-hive-connector-2.2-0.7.0-incubating.jar
Hive 2.1	        paimon-hive-connector-2.1-0.7.0-incubating.jar
Hive 2.1-cdh-6.3	paimon-hive-connector-2.1-cdh-6.3-0.7.0-incubating.jar

将Jar添加到Hive中有以下方法

  • 在Hive的根目录下创建一个auxlib文件夹,并将paimon-hive-connector-0.7.0-incubating.jar复制到auxlib中。
  • 将jar复制到Hive可访问的路径,然后使用add jar /path/to/paimon-hive-connector-0.7.0-incubating.jar在Hive中启用paimon支持,注意,不建议使用这种方法,如果使用MR引擎运行Join语句,可能报错org.apache.hive.com.esotericsoftware.kryo.kryoexception: unable to find class

注意

  • 如果使用HDFS,请确保设置了环境变量HADOOP_HOMEHADOOP_CONF_DIR
  • 如果使用hive cbo优化器,可能会导致一些不正确的查询结果,例如使用not null谓词查询struct类型,可以通过set hive.cbo.enable=false;命令禁用cbo优化器。
3.Flink SQL: 使用 Paimon Hive Catalog

使用paimon Hive catalog,可以通过Flink create,drop,select 和 insert 到 paimon 表中,这些操作直接影响对应的Hive metastore,以这种方式创建的表可以直接从Hive访问。

步骤一

准备Flink Hive Connector Bundled Jar。

步骤二

在Flink SQL Client中执行以下Flink SQL脚本,以定义Paimon Hive catalog并创建Table。

-- Flink SQL CLI
-- Define paimon Hive catalog

CREATE CATALOG my_hive WITH (
  'type' = 'paimon',
  'metastore' = 'hive',
  -- 'uri' = 'thrift://<hive-metastore-host-name>:<port>', default use 'hive.metastore.uris' in HiveConf
  -- 'hive-conf-dir' = '...', this is recommended in the kerberos environment
  -- 'hadoop-conf-dir' = '...', this is recommended in the kerberos environment
  -- 'warehouse' = 'hdfs:///path/to/table/store/warehouse', default use 'hive.metastore.warehouse.dir' in HiveConf
);

-- Use paimon Hive catalog

USE CATALOG my_hive;

-- Create a table in paimon Hive catalog (use "default" database by default)

CREATE TABLE test_table (
  a int,
  b string
);

-- Insert records into test table

INSERT INTO test_table VALUES (1, 'Table'), (2, 'Store');

-- Read records from test table

SELECT * FROM test_table;

/*
+---+-------+
| a |     b |
+---+-------+
| 1 | Table |
| 2 | Store |
+---+-------+
*/
4.Hive SQL: 访问已经在 Hive metastore 中的 Paimon Tables

在Hive CLI中运行以下Hive SQL访问创建的表。

-- Assume that paimon-hive-connector-<hive-version>-0.7.0-incubating.jar is already in auxlib directory.
-- List tables in Hive
-- (you might need to switch to "default" database if you're not there by default)

SHOW TABLES;

/*
OK
test_table
*/

-- Read records from test_table

SELECT a, b FROM test_table ORDER BY a;

/*
OK
1	Table
2	Store
*/

-- Insert records into test table
-- Note tez engine does not support hive write, only the hive engine is supported.

INSERT INTO test_table VALUES (3, 'Paimon');

SELECT a, b FROM test_table ORDER BY a;

/*
OK
1	Table
2	Store
3	Paimon
*/

-- time travel

SET paimon.scan.snapshot-id=1;
SELECT a, b FROM test_table ORDER BY a;
/*
OK
1	Table
2	Store
3	Paimon
*/
SET paimon.scan.snapshot-id=null;
5.Hive SQL: 创建新的 Paimon Tables

在Hive CLI中运行以下Hive SQL创建新的paimon表。

-- Assume that paimon-hive-connector-0.7.0-incubating.jar is already in auxlib directory.
-- Let's create a new paimon table.

SET hive.metastore.warehouse.dir=warehouse_path;

CREATE TABLE hive_test_table(
    a INT COMMENT 'The a field',
    b STRING COMMENT 'The b field'
)
STORED BY 'org.apache.paimon.hive.PaimonStorageHandler';
6.Hive SQL: 通过外部表访问 Paimon 的表

在Hive中将paimon表注册为外部表,在Hive CLI中运行以下Hive SQL来访问。

-- Assume that paimon-hive-connector-0.7.0-incubating.jar is already in auxlib directory.
-- Let's use the test_table created in the above section.
-- To create an external table, you don't need to specify any column or table properties.
-- Pointing the location to the path of table is enough.

CREATE EXTERNAL TABLE external_test_table
STORED BY 'org.apache.paimon.hive.PaimonStorageHandler'
LOCATION '/path/to/table/store/warehouse/default.db/test_table';
    
-- In addition to the way setting location above, you can also place the location setting in TBProperties
-- to avoid Hive accessing Paimon's location through its own file system when creating tables.
-- This method is effective in scenarios using Object storage,such as s3.

CREATE EXTERNAL TABLE external_test_table
STORED BY 'org.apache.paimon.hive.PaimonStorageHandler'
TBLPROPERTIES (
 'paimon_location' ='s3://xxxxx/path/to/table/store/warehouse/default.db/test_table'
);

-- Read records from external_test_table

SELECT a, b FROM external_test_table ORDER BY a;

/*
OK
1	Table
2	Store
*/

-- Insert records into test table

INSERT INTO external_test_table VALUES (3, 'Paimon');

SELECT a, b FROM external_test_table ORDER BY a;

/*
OK
1	Table
2	Store
3	Paimon
*/
7.Hive 和 Paimon 的类型映射

列出了Hive和Paimon之间所有支持的类型转换,Hive的所有数据类型都可以在org.apache.hadoop.hive.serde2.typeinfo中找到。

Hive Data TypePaimon Data TypeAtomic Type
StructTypeInfoRowTypefalse
MapTypeInfoMapTypefalse
ListTypeInfoArrayTypefalse
PrimitiveTypeInfo("boolean")BooleanTypetrue
PrimitiveTypeInfo("tinyint")TinyIntTypetrue
PrimitiveTypeInfo("smallint")SmallIntTypetrue
PrimitiveTypeInfo("int")IntTypetrue
PrimitiveTypeInfo("bigint")BigIntTypetrue
PrimitiveTypeInfo("float")FloatTypetrue
PrimitiveTypeInfo("double")DoubleTypetrue
CharTypeInfo(length)CharType(length)true
PrimitiveTypeInfo("string")VarCharType(VarCharType.MAX_LENGTH)true
VarcharTypeInfo(length)VarCharType(length), length is less than VarCharType.MAX_LENGTHtrue
PrimitiveTypeInfo("date")DateTypetrue
PrimitiveTypeInfo("timestamp")TimestampTypetrue
DecimalTypeInfo(precision, scale)DecimalType(precision, scale)true
PrimitiveTypeInfo("binary")VarBinaryType, BinaryTypetrue
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
为什么要学习这门课程?·新一代流式数据湖技术组件深入讲解,帮助你快速构造数据湖知识体系。·为构建湖仓一体架构提供底层技术支撑。本课程将从原理、架构、底层存储细节、性能优化、管理等层面对Paimon流式数据湖组件进行详细讲解,原理+实战,帮助你快速上手使用数据湖技术。讲师介绍华为HCIP认证大数据高级工程师北京猎豹移动大数据技术专家中科院大数据研究院大数据技术专家51CTO企业IT学院优秀讲师电子工业出版社2022年度优秀作者出版书籍:《Flink入门与实战》、《大数据技术及架构图解实战派》。本课程提供配套课件、软件、试题、以及源码。课程内容介绍:1、什么是Apache Paimon2、Paimon的整体架构3、Paimon的核心特点4、Paimon支持的生态5、基于Flink SQL操作Paimon6、基于Flink DataStream API 操作Paimon7、Paimon中的内部表和外部表8、Paimon中的分区表和临时表9、Paimon中的Primary Key表(主键表)10、Paimon中的Append Only表(仅追加表)11、Changelog Producers原理及案例实战12、Merge Engines原理及案例实战13、Paimon中的Catalog详解14、Paimon中的Table详解15、PaimonHive Catalog的使用16、动态修改Paimon表属性17、查询Paimon系统表18、批量读取Paimon表19、流式读取Paimon表20、流式读取高级特性Consumer ID21、Paimon CDC数据摄取功能22、CDC之MySQL数据同步到Paimon23、CDC之Kafka数据同步到Paimon24、CDC高级特性之Schema模式演变25、CDC高级特性之计算列26、CDC高级特性之特殊的数据类型映射27、CDC高级特性之中文乱码28、Hive引擎集成Paimon29、在Hive配置Paimon依赖30、在Hive中读写Paimon表31、在Hive中创建Paimon表32、HivePaimon数据类型映射关系33、Paimon底层文件基本概念34、Paimon底层文件布局35、Paimon底层文件操作详解36、Flink流式写入Paimon表过程分析37、读写性能优化详细分析38、Paimon中快照、分区、小文件的管理39、管理标签(自动管理+手工管理)40、管理Bucket(创建+删除+回滚)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫猫爱吃小鱼粮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值