fhueske commented on a change in pull request #6606: [FLINK-10163] [sql-client] 
Support views in SQL Client
URL: https://github.com/apache/flink/pull/6606#discussion_r212622912
 
 

 ##########
 File path: 
flink-libraries/flink-sql-client/src/main/java/org/apache/flink/table/client/cli/SqlCommandParser.java
 ##########
 @@ -30,86 +35,124 @@ private SqlCommandParser() {
        }
 
        public static Optional<SqlCommandCall> parse(String stmt) {
-               String trimmed = stmt.trim();
+               // normalize
+               stmt = stmt.trim();
                // remove ';' at the end because many people type it intuitively
-               if (trimmed.endsWith(";")) {
-                       trimmed = trimmed.substring(0, trimmed.length() - 1);
+               if (stmt.endsWith(";")) {
+                       stmt = stmt.substring(0, stmt.length() - 1).trim();
                }
+
+               // parse
                for (SqlCommand cmd : SqlCommand.values()) {
-                       int pos = 0;
-                       int tokenCount = 0;
-                       for (String token : trimmed.split("\\s")) {
-                               pos += token.length() + 1; // include space 
character
-                               // check for content
-                               if (token.length() > 0) {
-                                       // match
-                                       if (tokenCount < cmd.tokens.length && 
token.equalsIgnoreCase(cmd.tokens[tokenCount])) {
-                                               if (tokenCount == 
cmd.tokens.length - 1) {
-                                                       final SqlCommandCall 
call = new SqlCommandCall(
-                                                               cmd,
-                                                               
splitOperands(cmd, trimmed, trimmed.substring(Math.min(pos, trimmed.length())))
-                                                       );
-                                                       return 
Optional.of(call);
-                                               }
-                                       } else {
-                                               // next sql command
-                                               break;
-                                       }
-                                       tokenCount++; // check next token
+                       final Pattern pattern = 
Pattern.compile(cmd.matchingRegex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
 
 Review comment:
   Pattern compilation is quite heavy. Can we do this just once and not for 
every entered command?
   
   Maybe store the compiled pattern in the enum?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to