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

参考

相关推荐
Hello.Reader2 小时前
Flink 内存与资源调优从 Process Memory 到 Fine-Grained Resource Management
大数据·flink
数据知道3 小时前
PostgreSQL 核心原理:如何从日志中定位死锁根源(死锁检测与预防)
数据库·postgresql
程可爱3 小时前
springboot整合mybatis和postgresql
spring boot·postgresql·mybatis
数据知道4 小时前
PostgreSQL 核心原理:读已提交与可重复读的底层实现差异(事务隔离级别)
数据库·postgresql
松涛和鸣5 小时前
DAY67 IMX6 Development Board Configuration from Scratch
数据库·postgresql·sqlserver
l1t5 小时前
一个用postgresql的自定义函数求解数独的程序
数据库·postgresql·数独
IvorySQL5 小时前
改变工作方式的 PostgreSQL 实用模式
数据库·postgresql
王锋(oxwangfeng)6 小时前
Apache Flink 在 Kubernetes 上的高效部署与优化实践
flink·kubernetes·apache
Hello.Reader11 小时前
Apache Flink 网络 Buffer 调优Debloating 的边界、Buffer 生命周期
大数据·flink·apache
Hello.Reader11 小时前
Apache Flink 内存故障排查从 IllegalConfigurationException 到 OOMKilled,一篇把坑踩平的指南
大数据·flink·apache