flink1.20 连接 postgres

sql 复制代码
CREATE CATALOG mypg WITH(
    'type' = 'jdbc',
    'default-database' = 'postgres',
    'username' = 'postgres',
    'password' = '',
    'base-url' = 'jdbc:postgresql://10.50.108.42:5432'
);

create table soc_all (
WATERMARK FOR collectorreceipttime AS collectorreceipttime - INTERVAL '5' SECOND
)
WITH(
    'connector' = 'jdbc',
    'url' = 'jdbc:postgresql://10.50.108.42:5432/postgres',
    'username' = 'postgres',
    'password' = '',
    'driver' = 'org.postgresql.Driver'
)
LIKE `mypg`.`postgres`.`public.soc_local`;

CREATE TABLE sink_pg(
    srcUserName STRING,
    eventTime TIMESTAMP(3),
    ip STRING,
    baseline STRING,
    alert BOOLEAN
)
WITH (
    'connector' = 'jdbc',
    'url' = 'jdbc:postgresql://10.50.108.42:5432/postgres',
    'table-name' = 'alert',
    'username' = 'postgres',
    'password' = '',
    'driver' = 'org.postgresql.Driver'
);


-- 改成全部小写
insert into sink_pg
select
    '' as srcusername,
    ceil(collectorreceipttime  to hour) as eventtime,
    srcaddress as ip,
    '' as baseline,
    false
from soc_all
where collectorreceipttime  >= '2024-10-16'
and collectorreceipttime  < '2024-10-27'
and srcaddress <> ''
limit 100;

踩坑

postgres字段类型 timestamp 默认 timestamp(6),需要转换后才能作为水印字段

sql 复制代码
ALTER TABLE public.soc_local
ALTER COLUMN collectorReceiptTime TYPE TIMESTAMP(3);

postgresql 大小写不敏感

pg 中查询大写字段需要加双引号,但是flink sql 不支持引号,所以用flinksql查询pg大写字段会报错,见参考链接。

py 复制代码
Caused by: java.lang.IllegalArgumentException: open() failed.ERROR: column "collectorreceipttime" does not exist
  Hint: Perhaps you meant to reference the column "soc_local.collectorReceiptTime".

解决方案,把pg中字段改成全小写

参考

相关推荐
IvorySQL5 小时前
从轮询到等待——PostgreSQL WAIT FOR LSN 特性深度解析
数据库·postgresql
IvorySQL7 小时前
PostgreSQL 日报|堆表选择性索引更新(10 月 13 日)
数据库·人工智能·postgresql·开源·区块链
用户36105886261210 小时前
Flink Time 之 AllowedLateness 深度剖析:从本质定义到内部机制与实战最佳实践
大数据·flink
starzy199010 小时前
Flink SlotPool 申请资源源码跟踪:从调度器请求到Task部署的完整链路
大数据·flink
ss27312 小时前
PG实战笔记 | 06 PostgreSQL基础安装部署:Linux/Windows/macOS全攻略
linux·笔记·postgresql
行者-全栈开发12 小时前
【码动四季·秋】基于开源做发行版:MySQL/PostgreSQL 国产化发行版的技术路径与选型实战
postgresql·开源数据库·opengauss·选型·国产化替代
starzy199012 小时前
Flink SlotManager 分配 Slot 源码深度剖析:从请求接收到状态转换的完整链路
大数据·flink
池佳齐13 小时前
【软考高级架构师案例】流计算 vs 批处理,Spark 和 Flink 该怎么选?
大数据·flink·spark
ss27313 小时前
PG实战笔记 | 07 PostgreSQL常见编译项及其作用
数据库·笔记·postgresql
IvorySQL1 天前
PostgreSQL 日报|逻辑解码 DDL 子事务缺陷修复(10 月 12 日)
数据库·postgresql