Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,24 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
var bracketedCommentLevel = 0
var escape = false
var beginIndex = 0
var includingStatement = false
var leavingBracketedComment = false
var isStatement = false
val ret = new JArrayList[String]

def insideBracketedComment: Boolean = bracketedCommentLevel > 0
def insideComment: Boolean = insideSimpleComment || insideBracketedComment
def statementBegin(index: Int): Boolean = includingStatement || (!insideComment &&
def statementInProgress(index: Int): Boolean = isStatement || (!insideComment &&
index > beginIndex && !s"${line.charAt(index)}".trim.isEmpty)
Comment thread
turboFei marked this conversation as resolved.

for (index <- 0 until line.length) {
// judge and reduce bracketed comment level if the flag of leaving bracketed comment is true,
// because that the last character of bracketed comment is still inside the comment and we can
// only mark it and reduce bracketed comment level in next loop
Comment thread
turboFei marked this conversation as resolved.
Outdated
if (leavingBracketedComment) {
bracketedCommentLevel -= 1
leavingBracketedComment = false
}

if (line.charAt(index) == '\'' && !insideComment) {
// take a look to see if it is escaped
// See the comment above about SPARK-31595
Expand Down Expand Up @@ -568,12 +577,12 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
if (insideSingleQuote || insideDoubleQuote || insideComment) {
// do not split
} else {
if (includingStatement) {
if (isStatement) {
// split, do not include ; itself
ret.add(line.substring(beginIndex, index))
}
beginIndex = index + 1
includingStatement = false
isStatement = false
}
} else if (line.charAt(index) == '\n') {
// with a new line the inline simple comment should end.
Expand All @@ -585,7 +594,7 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
if (insideSingleQuote || insideDoubleQuote) {
// Ignores '/' in any case of quotes
} else if (insideBracketedComment && line.charAt(index - 1) == '*' ) {
bracketedCommentLevel -= 1
Comment thread
turboFei marked this conversation as resolved.
leavingBracketedComment = true
Comment thread
turboFei marked this conversation as resolved.
} else if (hasNext && !insideBracketedComment && line.charAt(index + 1) == '*') {
bracketedCommentLevel += 1
}
Expand All @@ -597,9 +606,9 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
escape = true
}

includingStatement = statementBegin(index)
isStatement = statementInProgress(index)
}
if (includingStatement) {
if (isStatement) {
ret.add(line.substring(beginIndex))
}
ret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging {
"/* SELECT 'test';*/ SELECT 'test';" -> "test",
";;/* SELECT 'test';*/ SELECT 'test';" -> "test",
"/* SELECT 'test';*/;; SELECT 'test';" -> "test",
"SELECT 'test'; -- SELECT 'test';" -> "",
"SELECT 'test'; /* SELECT 'test';*/;" -> "",
"SELECT 'test'; -- SELECT 'test';" -> "test",
"SELECT 'test'; /* SELECT 'test';*/;" -> "test",
Comment thread
turboFei marked this conversation as resolved.
"/*$meta chars{^\\;}*/ SELECT 'test';" -> "test",
"/*\nmulti-line\n*/ SELECT 'test';" -> "test",
"/*/* multi-level bracketed*/ SELECT 'test';" -> "test"
Expand Down