danny0405 commented on a change in pull request #12188:
URL: https://github.com/apache/flink/pull/12188#discussion_r426150317



##########
File path: 
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/cli/SqlCommandParser.java
##########
@@ -34,29 +58,131 @@ private SqlCommandParser() {
                // private
        }
 
-       public static Optional<SqlCommandCall> parse(String stmt) {
+       public static Optional<SqlCommandCall> parse(Function<String, 
List<Operation>> sqlParserFunction, String stmt) {
                // normalize
                stmt = stmt.trim();
                // remove ';' at the end
                if (stmt.endsWith(";")) {
                        stmt = stmt.substring(0, stmt.length() - 1).trim();
                }
 
-               // parse
+               // parse statement via sql parser first
+               Optional<SqlCommandCall> callOpt = 
parseBySqlParser(sqlParserFunction, stmt);
+               if (callOpt.isPresent()) {
+                       return callOpt;
+               }
+
+               // parse statement via regex match
                for (SqlCommand cmd : SqlCommand.values()) {
-                       final Matcher matcher = cmd.pattern.matcher(stmt);
-                       if (matcher.matches()) {
-                               final String[] groups = new 
String[matcher.groupCount()];
-                               for (int i = 0; i < groups.length; i++) {
-                                       groups[i] = matcher.group(i + 1);
+                       if (cmd.hasRegexPattern()) {
+                               final Matcher matcher = 
cmd.pattern.matcher(stmt);
+                               if (matcher.matches()) {
+                                       final String[] groups = new 
String[matcher.groupCount()];
+                                       for (int i = 0; i < groups.length; i++) 
{
+                                               groups[i] = matcher.group(i + 
1);
+                                       }
+                                       return 
cmd.operandConverter.apply(groups)
+                                                       .map((operands) -> {
+                                                               String[] 
newOperands = operands;
+                                                               if (cmd == 
SqlCommand.EXPLAIN) {
+                                                                       // 
convert `explain xx` to `explain plan for xx`

Review comment:
       After a offline discussion, we have a TODO to refactor the commands in 
SQL-CLI to keep them more in line with TableEnv, so it's not a big deal 
currently.




----------------------------------------------------------------
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.

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


Reply via email to