前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FlinkSQL 平台

FlinkSQL 平台

作者头像
shengjk1
发布2021-01-26 16:08:37
1.1K0
发布2021-01-26 16:08:37
举报
文章被收录于专栏:码字搬砖码字搬砖

1.背景

由于公司内部需求较多,并不想每次都写一个 streaming 程序,故而开始搭建 flinksql 平台,基于 jdk1.8,flink1.12.x

2.效果

传一个 sql 文件给 jar 包,然后 sql 文件内的 sql 将自动执行

3. jar 包 vs web 界面

调研了基于 web 的 zeppline

  1. zeppline 设计的初衷其实是为了交互式分析
  2. 基于 zeppline rest api 与现有的监控不兼容,需要修改现有监控的代码
  3. 虽然带有 web 界面的对用户很是友好,对于分析人员来说,是一个不错的选择,但对于开发人员来说,真正的线上长时间的运行程序,开发成 HA 的 server 还是有必要的

基于以上 3 点最终选择 jar 作为最终的方式

4. 使用

  1. 将 sql 写入 xxx.sql 文件中,如
代码语言:javascript
复制
CREATE TEMPORARY FUNCTION MillisecondsToDateStr AS 'io.github.shengjk.udf.MillisecondsToDateStr' LANGUAGE JAVA;


-- ExecutionCheckpointingOptions
set execution.checkpointing.mode=EXACTLY_ONCE;
set execution.checkpointing.timeout=30 min;--  30min
set execution.checkpointing.interval=1 min ; -- 1min
set execution.checkpointing.externalized-checkpoint-retention=RETAIN_ON_CANCELLATION;

-- ExecutionConfigOptions
set table.exec.state.ttl=1 day;  -- 1 day
set table.exec.mini-batch.enabled=true; -- enable mini-batch optimization
set table.exec.mini-batch.allow-latency=1 s; -- 1s
set table.exec.mini-batch.size=1000;
set table.exec.sink.not-null-enforcer=drop;

-- -- dadadadadada
CREATE TABLE orders
(
   status      int,
   courier_id  bigint,
   id          bigint,
   finish_time BIGINT
)
WITH (
   'connector' = 'kafka','topic' = 'canal_monitor_order',
   'properties.bootstrap.servers' = 'localhost:9092','properties.group.id' = 'testGroup',
   'format' = 'ss-canal-json','ss-canal-json.table.include' = 'orders','scan.startup.mode' = 'earliest-offset');

-- flink.partition-discovery.interval-millis;
CREATE TABLE infos
(
   info_index int,
   order_id   bigint
)
WITH (
   'connector' = 'kafka','topic' = 'canal_monitor_order',
   'properties.bootstrap.servers' = 'localhost:9092','properties.group.id' = 'testGroup',
   'format' = 'ss-canal-json','ss-canal-json.table.include' = 'infos','scan.startup.mode' = 'earliest-offset');


CREATE TABLE redisCache
(
   finishOrders BIGINT,
   courier_id   BIGINT,
   dayStr       String
)
WITH (
   'connector' = 'redis',
   'hostPort'='localhost:6400',
   'keyType'='hash',
   'keyTemplate'='test2_${courier_id}',
   'fieldTemplate'='${dayStr}',
   'valueNames'='finishOrders',
   'expireTime'='259200');

create view temp as
select o.courier_id,
      (CASE
           WHEN sum(infosMaxIndex.info_index) is null then 0
           else sum(infosMaxIndex.info_index) end) finishOrders,
      o.status,
      dayStr
from ((select courier_id,
             id,
             last_value(status)                             status,
             MillisecondsToDateStr(finish_time, 'yyyyMMdd') dayStr
      from orders
      where status = 60
      group by courier_id, id, MillisecondsToDateStr(finish_time, 'yyyyMMdd'))) o
        left join (select max(info_index) info_index, order_id
                   from infos
                   group by order_id) infosMaxIndex on o.id = infosMaxIndex.order_id
group by o.courier_id, o.status, dayStr;


INSERT INTO redisCache SELECT finishOrders,courier_id,dayStr FROM temp;
  1. 将 flinksql-platform 打包并上传至服务器
  2. 将必要的 connector jar 放入到相应的目录下
  3. 执行,如
代码语言:javascript
复制
flink-1.12.0/bin/flink  run -p 3 -yt ./flinkjar/  -C file:///home/shengjk/flinkjar/test-udf.jar -C file:///home/shengjk/flinkjar/jedis-2.10.2.jar  -m yarn-cluster -ynm sqlDemo  -c io.github.shengjk.Main ./flinksql-platform-1.0-SNAPSHOT.jar --sqlPath ./xxx.sql

其中 -C 添加 udfJar 等第三方 jar 包 -C 参数apply到了client端生成的JobGraph里,然后提交JobGraph来运行的 -yt 目录 将 udfJar 等第三方 jar 包提交到 TaskManager 上

5. 总括

更详细的内容,请移步 flinksql-platform

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-01-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.背景
  • 2.效果
  • 3. jar 包 vs web 界面
  • 4. 使用
  • 5. 总括
相关产品与服务
大数据
全栈大数据产品,面向海量数据场景,帮助您 “智理无数,心中有数”!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档