当前位置:   article > 正文

Flink-Paimon 案例_flink paimon 本地

flink paimon 本地
Flink-Paimon 案例
1、下载 Flink Jar 包并解压
tar -xzf flink-*.tgz
  • 1
2、下载 Paimon Jar 包放进 Flink 的 lib 中
cp paimon-flink-*.jar <FLINK_HOME>/lib/
  • 1
3、如果运行在 Hadoop 环境,则向 lib 中添加依赖
cp flink-shaded-hadoop-2-uber-*.jar <FLINK_HOME>/lib/
  • 1
4、修改 flink-conf.yaml 配置,并启动 Flink 本地集群
-- 修改配置
taskmanager.numberOfTaskSlots: 2

-- 启动集群
<FLINK_HOME>/bin/start-cluster.sh
  • 1
  • 2
  • 3
  • 4
  • 5
5、启动 Flink SQL client
<FLINK_HOME>/bin/sql-client.sh
  • 1
6、创建 Paimon Catalog 和 Table
CREATE CATALOG my_catalog WITH (
    'type'='paimon',
    'warehouse'='file:/tmp/paimon'
);

USE CATALOG my_catalog;

-- create a word count table
CREATE TABLE word_count (
    word STRING PRIMARY KEY NOT ENFORCED,
    cnt BIGINT
);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

使用 FlinkGenericCatalog

CREATE CATALOG my_catalog WITH (
    'type'='paimon-generic',
    'hive-conf-dir'='...',
    'hadoop-conf-dir'='...'
);

USE CATALOG my_catalog;

-- create a word count table
CREATE TABLE word_count (
    word STRING PRIMARY KEY NOT ENFORCED,
    cnt BIGINT
) WITH (
    'connector'='paimon'
);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
7、写数据
-- create a word data generator table
CREATE TEMPORARY TABLE word_table (
    word STRING
) WITH (
    'connector' = 'datagen',
    'fields.word.length' = '1'
);

-- paimon requires checkpoint interval in streaming mode
SET 'execution.checkpointing.interval' = '10 s';

-- write streaming data to dynamic table
INSERT INTO word_count SELECT word, COUNT(*) FROM word_table GROUP BY word;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
8、OLAP 查询
-- use tableau result mode
SET 'sql-client.execution.result-mode' = 'tableau';

-- switch to batch mode
RESET 'execution.checkpointing.interval';
SET 'execution.runtime-mode' = 'batch';

-- olap query the table
SELECT * FROM word_count;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
9、Streaming 查询
-- switch to streaming mode
SET 'execution.runtime-mode' = 'streaming';

-- track the changes of table and calculate the count interval statistics
SELECT `interval`, COUNT(*) AS interval_cnt FROM
    (SELECT cnt / 10000 AS `interval` FROM word_count) GROUP BY `interval`;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
10、退出
-- exit sql-client
EXIT;

-- 停止本地集群
./bin/stop-cluster.sh
  • 1
  • 2
  • 3
  • 4
  • 5
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/946811
推荐阅读
相关标签
  

闽ICP备14008679号