This is an automated email from the ASF dual-hosted git repository. ron pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit e737400814e9f8d2b376a8533f93ae6a96857798 Author: Feng Jin <jinfeng1...@gmail.com> AuthorDate: Sun Jan 19 20:48:17 2025 +0800 [FLINK-37133][table] Fix ScriptExecutor to properly split scripts without trailing semicolon --- .../service/application/ScriptExecutor.java | 1 + .../service/application/ScriptExecutorITCase.java | 17 +++++++++++++++ .../src/test/resources/application/no_semicolon.q | 25 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/application/ScriptExecutor.java b/flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/application/ScriptExecutor.java index 804036f88871..d63e43b07897 100644 --- a/flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/application/ScriptExecutor.java +++ b/flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/application/ScriptExecutor.java @@ -194,6 +194,7 @@ public class ScriptExecutor { return true; } } + position = script.length(); statement = currentSqlBuilder.toString(); if (!StringUtils.isNullOrWhitespaceOnly(statement)) { diff --git a/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/application/ScriptExecutorITCase.java b/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/application/ScriptExecutorITCase.java index 0895665b58b6..0103c6ec81f6 100644 --- a/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/application/ScriptExecutorITCase.java +++ b/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/application/ScriptExecutorITCase.java @@ -126,6 +126,23 @@ public class ScriptExecutorITCase extends AbstractSqlGatewayStatementITCaseBase + "+------+------+------+-----+--------+-----------+"); } + @Test + void testParseStatementWithoutSemicolon() throws Exception { + assertThat(runScript("no_semicolon.q")) + .contains( + "+------+------+------+-----+--------+-----------+" + + System.lineSeparator() + + "| name | type | null | key | extras | watermark |" + + System.lineSeparator() + + "+------+------+------+-----+--------+-----------+" + + System.lineSeparator() + + "| a | INT | TRUE | | | |" + + System.lineSeparator() + + "| b | INT | TRUE | | | |" + + System.lineSeparator() + + "+------+------+------+-----+--------+-----------+"); + } + @Test void testParseErrorPositionIsCorrect() throws Exception { assertThat(runScript("error.q")) diff --git a/flink-table/flink-sql-gateway/src/test/resources/application/no_semicolon.q b/flink-table/flink-sql-gateway/src/test/resources/application/no_semicolon.q new file mode 100644 index 000000000000..2fba801e5b7a --- /dev/null +++ b/flink-table/flink-sql-gateway/src/test/resources/application/no_semicolon.q @@ -0,0 +1,25 @@ +-- begin-statement-set.q - BEGIN STATEMENT SET, END +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to you under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +CREATE TABLE src( + a INT, + b INT +) WITH ( + 'connector' = 'datagen' +); -- This is another comment + +DESCRIBE src