You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Flink的Schema.Builder中设置非空列解决主键可空异常?

你的代码抛出异常的核心原因是:Flink要求主键列必须满足非空约束,但默认情况下DataTypes.BIGINT()定义的列是允许为空的。

只需在列类型后调用.notNull()方法,即可将id列标记为非空,修改后的代码如下:

Schema.Builder schemaBuilder = Schema.newBuilder();
schemaBuilder.column("id", DataTypes.BIGINT().notNull())
        .column("value", DataTypes.STRING())
        .primaryKey("id");

这样设置后,id列的非空约束会生效,就能符合主键的验证要求,避免抛出ValidationException。

内容的提问来源于stack exchange,提问作者Haw Ke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 01:00:58