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中字段改成全小写

参考

相关推荐
想ai抽13 小时前
Flink重启策略有啥用
大数据·flink
qq_2037694913 小时前
debian13安装PostgreSQL并远程连接
数据库·postgresql
武子康15 小时前
大数据-132 Flink SQL 实战入门 | 3 分钟跑通 Table API + SQL 含 toChangelogStream 新写法
大数据·后端·flink
best_virtuoso1 天前
PostgreSQL PostGIS安装与配置,现有数据库启用PostGIS扩展
数据库·postgresql
我变秃了也没变强1 天前
pgsql配置密码复杂度策略
数据库·postgresql
IvorySQL1 天前
在一台机器上搭建一体化 Ceph 存储集群
postgresql·开源
jiedaodezhuti1 天前
Flink性能调优基石:资源配置与内存优化实践
大数据·flink
IvorySQL2 天前
PostgreSQL 18 中国贡献者经验分享:开源参与的四点建议
数据库·postgresql·开源
wudl55662 天前
Flink 1.19 REST API
大数据·flink
武子康2 天前
大数据-131 Flink CEP 实战 24 小时≥5 次交易 & 10 分钟未支付检测 案例附代码
大数据·后端·flink