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

参考

相关推荐
清平乐的技术专栏36 分钟前
【Flink学习】(六)Flink 三大时间语义 + 水位线 Watermark
大数据·学习·flink
清平乐的技术专栏36 分钟前
【Flink学习】(一)初识 Flink,大数据实时计算核心认知
大数据·flink
大大大大晴天3 小时前
告别混淆!一文讲透 Flink State Backend 与 Checkpoint Storage
flink
IvorySQL3 小时前
用生成列提升 JSONB 查询效率:PostgreSQL 三种索引方案实测对比
数据库·postgresql
docsz3 小时前
Ambari3.0集成Flink 2.2+Paimon1.4
大数据·flink
清平乐的技术专栏4 小时前
【Flink学习】(七)Flink 状态编程入门,有状态实时计算
大数据·学习·flink
丷丩4 小时前
Postgresql基础实践教程
数据库·postgresql
IvorySQL4 小时前
IvorySQL & PostgreSQL 国内镜像服务上线——更快拉取,更稳体验
数据库·postgresql
清平乐的技术专栏4 小时前
【Flink学习】(七)Flink 四大窗口机制,实时时间段统计
大数据·学习·flink
清平乐的技术专栏4 小时前
【Flink学习】(九)Flink 容错机制 Checkpoint 与 Savepoint
大数据·学习·flink