前言
从 0.12.0 开始支持,通过 catalog 可以管理 flink 创建的表,避免重复建表操作,另外 hms 模式的 catalog 支持自动补全 hive 同步参数。
DFS 模式 Catalog SQL样例:
CREATE CATALOG hoodie_catalog
WITH (
'type'='hudi',
'catalog.path' = '${catalog 的默认路径}',
'mode'='dfs'
);
Hms 模式 Catalog SQL 样例:
CREATE CATALOG hoodie_catalog
WITH (
'type'='hudi',
'catalog.path' = '${catalog 的默认路径}',
'hive.conf.dir' = '${hive-site.xml 所在的目录}',
'mode'='hms' -- 支持 'dfs' 模式通过文件系统管理表属性
);
1)WITH 参数
名称 | Required | 默认值 | 说明 |
---|---|---|---|
catalog.path | true | 默认的 catalog 根路径,用作表路径的自动推导,默认的表路径: c a t a l o g . p a t h / {catalog.path}/ catalog.path/{db_name}/${table_name} | |
default-database | false | default | 默认的 database 名 |
hive.conf.dir | false | hive-site.xml 所在的目录,只在 hms 模式下生效 | |
mode | false | dfs | 支持 hms模式通过 hive 管理元数据 |
table.external | false | false | 是否创建外部表,只在 hms 模式下生效 |
2)使用dfs方式
(1)创建sql-client初始化sql文件
vim /opt/module/flink-1.13.6/conf/sql-client-init.sql
CREATE CATALOG hoodie_catalog
WITH (
'type'='hudi',
'catalog.path' = '/tmp/hudi_catalog',
'mode'='dfs'
);
USE CATALOG hoodie_catalog;
(2)指定sql-client启动时加载sql文件
hadoop fs -mkdir /tmp/hudi_catalog
bin/sql-client.sh embedded -i conf/sql-client-init.sql -s yarn-session
(3)建库建表插入
create database test;
use test;
create table t2(
uuid varchar(20),
name varchar(10),
age int,
ts timestamp(3),
`partition` varchar(20),
primary key (uuid) not enforced
)
with (
'connector' = 'hudi',
'path' = '/tmp/hudi_catalog/default/t2',
'table.type' = 'MERGE_ON_READ'
);
insert into t2 values('1','zs',18,TIMESTAMP '1970-01-01 00:00:01','a');
(4)退出sql-client,重新进入,表信息还在
use test;
show tables;
select * from t2;