From 09dc001430dab2fef1d36d463538cfe403606e22 Mon Sep 17 00:00:00 2001 From: KnightChess <981159963@qq.com> Date: Tue, 28 Jun 2022 09:44:41 +0800 Subject: [PATCH] [HUDI-4325] fix spark sql procedure cause ParseException with semicolon (#5982) * [HUDI-4325] fix saprk sql procedure cause ParseException with semicolon --- .../hudi/spark/sql/parser/HoodieSqlCommon.g4 | 2 +- .../procedure/TestCallCommandParser.scala | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hudi-spark-datasource/hudi-spark/src/main/antlr4/org/apache/hudi/spark/sql/parser/HoodieSqlCommon.g4 b/hudi-spark-datasource/hudi-spark/src/main/antlr4/org/apache/hudi/spark/sql/parser/HoodieSqlCommon.g4 index 65e17bfb4..8643170f8 100644 --- a/hudi-spark-datasource/hudi-spark/src/main/antlr4/org/apache/hudi/spark/sql/parser/HoodieSqlCommon.g4 +++ b/hudi-spark-datasource/hudi-spark/src/main/antlr4/org/apache/hudi/spark/sql/parser/HoodieSqlCommon.g4 @@ -42,7 +42,7 @@ } singleStatement - : statement EOF + : statement ';'* EOF ; statement diff --git a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/procedure/TestCallCommandParser.scala b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/procedure/TestCallCommandParser.scala index 668fb5449..ec824fc5c 100644 --- a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/procedure/TestCallCommandParser.scala +++ b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/procedure/TestCallCommandParser.scala @@ -85,6 +85,26 @@ class TestCallCommandParser extends HoodieSparkSqlTestBase { checkParseExceptionContain("CALL cat.system radish kebab")("mismatched input 'CALL' expecting") } + test("Test Call Produce with semicolon") { + val call = parser.parsePlan("CALL system.func(c1 => 1, c2 => '2', c3 => true)").asInstanceOf[CallCommand] + assertResult(ImmutableList.of("system", "func"))(JavaConverters.seqAsJavaListConverter(call.name).asJava) + + assertResult(3)(call.args.size) + + checkArg(call, 0, "c1", 1, DataTypes.IntegerType) + checkArg(call, 1, "c2", "2", DataTypes.StringType) + checkArg(call, 2, "c3", true, DataTypes.BooleanType) + + val call2 = parser.parsePlan("CALL system.func2(c1 => 1, c2 => '2', c3 => true);").asInstanceOf[CallCommand] + assertResult(ImmutableList.of("system", "func2"))(JavaConverters.seqAsJavaListConverter(call2.name).asJava) + + assertResult(3)(call2.args.size) + + checkArg(call2, 0, "c1", 1, DataTypes.IntegerType) + checkArg(call2, 1, "c2", "2", DataTypes.StringType) + checkArg(call2, 2, "c3", true, DataTypes.BooleanType) + } + protected def checkParseExceptionContain(sql: String)(errorMsg: String): Unit = { var hasException = false try {