Hudi系列14:Hudi元數據持久化 一. 元數據持久化 二. 實操1(不使用初始化文件) 三. 實操2(使用初始化文件) 參考:

一. 元數據持久化

元數據持久化:
每次退出flink-sql重新登錄後,建表的元數據就不存在,需要重新創建。

從 Hudi 0.12.0開始支持,通過catalog可以管理flink創建的表,避免重複建表操作,另外hms模式的catalog支持自動補全hive同步參數。

二. 實操1(不使用初始化文件)

代碼:

-- 創建catalog
CREATE CATALOG hive_catalog WITH (
    'type' = 'hive',
    'default-database' = 'test',
    'hive-conf-dir' = '/home/apache-hive-3.1.2-bin/conf'
);

-- 進入catalog
use catalog hive_catalog;

--- 創建數據庫供hudi使用
create database hudidb;

use hudidb;

CREATE TABLE my_targetT_200(
  uuid VARCHAR(20) PRIMARY KEY NOT ENFORCED,
  name VARCHAR(10),  
  age INT,
  ts TIMESTAMP(3)
)
WITH (
  'connector' = 'hudi',
  'path' = 'hdfs://hp5:8020/tmp/hudi_data/my_targetT_200',
  'table.type' = 'MERGE_ON_READ' -- this creates a MERGE_ON_READ table, by default is COPY_ON_WRITE
);

測試記錄:

退出後重新進入Flink SQL Client:
代碼:

-- 創建catalog(每次都需要創建和進入目錄)
CREATE CATALOG hive_catalog WITH (
    'type' = 'hive',
    'default-database' = 'test',
    'hive-conf-dir' = '/home/apache-hive-3.1.2-bin/conf'
);

-- 進入catalog
use catalog hive_catalog;

use hudidb;

show tables;

三. 實操2(使用初始化文件)

代碼:

cd /home/flink-1.14.5/conf/

vim sql-client-init.sql
CREATE CATALOG hive_catalog WITH (
    'type' = 'hive',
    'default-database' = 'test',
    'hive-conf-dir' = '/home/apache-hive-3.1.2-bin/conf'
);

use catalog hive_catalog;

使用Flink SQL的時候,加載sql文件

/home/flink-1.14.5/bin/sql-client.sh embedded -s yarn-session -i $FLINK_HOME/conf/sql-client-init.sql

測試記錄:
可以看到每次進入Flink的SQL已經默認進入了指定的目錄。

參考:

  1. https://blog.csdn.net/dkl12/article/details/127621878
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章