gatorsmile commented on a change in pull request #23276: [SPARK-26321][SQL] 
Split a SQL in correct way
URL: https://github.com/apache/spark/pull/23276#discussion_r244659180
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/StringUtils.scala
 ##########
 @@ -87,4 +92,93 @@ object StringUtils {
     }
     funcNames.toSeq
   }
+
+  /**
+   * Split the text into one or more SQLs with bracketed comments reserved
+   *
+   * Highlighted Corner Cases: semicolon in double quotes, single quotes or 
inline comments.
+   * Expected Behavior: The blanks will be trimed and a blank line will be 
omitted.
+   *
+   * @param text One or more SQLs separated by semicolons
+   * @return the trimmed SQL array (Array is for Java introp)
+   */
+  def split(text: String): Array[String] = {
+    val D_QUOTE: Char = '"'
+    val S_QUOTE: Char = '\''
+    val Q_QUOTE: Char = '`'
+    val SEMICOLON: Char = ';'
+    val ESCAPE: Char = '\\'
+    val DOT = '.'
+    val SINGLE_COMMENT = "--"
+    val BRACKETED_COMMENT_START = "/*"
+    val BRACKETED_COMMENT_END = "*/"
+    val FORWARD_SLASH = '/'
+
+    // quoteFlag acts as an enum of D_QUOTE, S_QUOTE, DOT
+    // * D_QUOTE: the cursor stands on a doulbe quoted string
+    // * S_QUOTE: the cursor stands on a single quoted string
+    // * DASH: the cursor stands in the SINGLE_COMMENT
+    // * FORWARD_SLASH: the cursor stands in the BRACKETED_COMMENT
+    // * DOT: default value for other cases
+    var quoteFlag: Char = DOT
 
 Review comment:
   can we use enum? The current way mixed the actual flag with the symbol. 

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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to