wenlong88 commented on a change in pull request #18363:
URL: https://github.com/apache/flink/pull/18363#discussion_r806434085



##########
File path: 
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/delegation/ParserImpl.java
##########
@@ -95,12 +105,24 @@ public ParserImpl(
         }
 
         // parse the sql query
-        SqlNode parsed = parser.parse(statement);
-
-        Operation operation =
-                SqlToOperationConverter.convert(planner, catalogManager, 
parsed)
-                        .orElseThrow(() -> new TableException("Unsupported 
query: " + statement));
-        return Collections.singletonList(operation);
+        try {
+            // use parseSqlList here because we need to support statement end 
with ';' in sql
+            // client.
+            SqlNodeList sqlNodeList = parser.parseSqlList(statement);
+            List<SqlNode> parsed = sqlNodeList.getList();
+            Preconditions.checkArgument(parsed.size() == 1, "only single 
statement supported");
+            return Collections.singletonList(
+                    SqlToOperationConverter.convert(planner, catalogManager, 
parsed.get(0))
+                            .orElseThrow(
+                                    () -> new TableException("Unsupported 
query: " + statement)));
+        } catch (SqlParserException parserException) {
+            if 
(config.getConfiguration().getBoolean(TABLE_PARSER_ALLOW_PARTIAL_PARSE)
+                    && parserException.getMessage().contains("Encountered 
\"<EOF>\"")) {
+                return Collections.singletonList(new 
StagingOperation(statement, parserException));
+            } else {
+                throw parserException;
+            }

Review comment:
       thanks for the advise, I am also thinking about how to get rid of the 
internal config based on the Godfreyhe 's comment. I like the idea adding a new 
function, but I would like to keep the StagingOperation instead of a union 
type, because it make it easier to transporting the result between different 
components in parser/client. 
   
   I am afraid that we can only check based on string, because the calcite 
parser only format the message to describe the error, there is no sub exception.
   
   WDYT?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to