MERGE INTO stu4_sink_hudiUSING ( SELECT * FROM stu4) sourceON stu4_sink_hudi.id = source.idWHEN MATCHED THEN UPDATE SET stu4_sink_hudi.name = source.name, stu4_sink_hudi.school = source.schoolWHEN NOT MATCHED THEN INSERT (id, name, school) VALUES (source.id, source.name, source.school)WHEN NOT MATCHED BY SOURCE AND stu4_sink_hudi.school='school1' THEN DELETE;[ERROR] Could not execute SQL statement. Reason:org.apache.flink.sql.parser.impl.ParseException: Encountered "WHEN" at line 12, column 1.Was expecting one of: ")" ... 请问一下,Flink1.13.6 MERGE 这语法 有什么问题
根据您提供的 SQL 语句,可以看出其中确实存在语法错误。具体来说,WHEN NOT MATCHED BY SOURCE AND stu4_sink_hudi.school='school1' THEN DELETE
应该放在 WHEN NOT MATCHED THEN
的后面,而不是整个语句的最后。
正确的 SQL 语句应该是这样的:
MERGE INTO stu4_sink_hudi
USING (
SELECT * FROM stu4
) source
ON stu4_sink_hudi.id = source.id
WHEN MATCHED THEN
UPDATE SET stu4_sink_hudi.name = source.name, stu4_sink_hudi.school = source.school
WHEN NOT MATCHED THEN
INSERT (id, name, school) VALUES (source.id, source.name, source.school)
WHEN NOT MATCHED BY SOURCE AND stu4_sink_hudi.school='school1' THEN
DELETE;
在这个语句中,WHEN NOT MATCHED BY SOURCE AND stu4_sink_hudi.school='school1' THEN DELETE
被正确地放置在了 WHEN NOT MATCHED THEN
的后面。
这个问题不是 Flink 版本问题。
这是一个无法通过 Flink SQL 解析器的错误的 SQL 语法。您需要检查语法并根据您使用的数据库系统(MySQL,PostgresSQL,Oracle 等)创建相应的语法。
以下是一个示例 MySQL 的 MERGE 语法:
MERGE INTO stu4_sink_hudi USING stu4 source ON stu4_sink_hudi.id = source.id WHEN MATCHED THEN UPDATE SET stu4_sink_hudi.name = source.name, stu4_sink_hudi.school = source.school WHEN NOT MATCHED THEN INSERT (id, name, school) VALUES (source.id, source.name, source.school) WHEN NOT MATCHED BY SOURCE AND stu4_sink_hudi.school='school1' THEN DELETE; 请注意,不同的数据库系统具有不同的 MERGE 语法,因此您需要按照相应的语法规则在 Flink 中编写 SQL 语句。
语法存在问题,改成这样试试:
MERGE INTO stu4_sink_hudi
USING stu4
ON stu4_sink_hudi.id = stu4.id
WHEN MATCHED THEN UPDATE SET stu4_sink_hudi.name = stu4.name, stu4_sink_hudi.school = stu4.school
WHEN NOT MATCHED THEN INSERT (id, name, school) VALUES (stu4.id, stu4.name, stu4.school)
WHEN NOT MATCHED AND stu4_sink_hudi.school='school1' THEN DELETE;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
实时计算Flink版是阿里云提供的全托管Serverless Flink云服务,基于 Apache Flink 构建的企业级、高性能实时大数据处理系统。提供全托管版 Flink 集群和引擎,提高作业开发运维效率。