Skip to content

Commit ada4d5c

Browse files
committed
address comment
1 parent a317344 commit ada4d5c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkSQLCLIDriver.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,18 +530,22 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
530530
var bracketedCommentLevel = 0
531531
var escape = false
532532
var beginIndex = 0
533-
var bracketedCommentRightBound = -1
534-
var includingStatement = false
533+
var leavingBracketedComment = false
534+
var isStatement = false
535535
val ret = new JArrayList[String]
536536

537537
def insideBracketedComment: Boolean = bracketedCommentLevel > 0
538538
def insideComment: Boolean = insideSimpleComment || insideBracketedComment
539-
def statementBegin(index: Int): Boolean = includingStatement || (!insideComment &&
539+
def statementInProgress(index: Int): Boolean = isStatement || (!insideComment &&
540540
index > beginIndex && !s"${line.charAt(index)}".trim.isEmpty)
541541

542542
for (index <- 0 until line.length) {
543-
if (index > 0 && index - 1 == bracketedCommentRightBound) {
543+
// judge and reduce bracketed comment level if the flag of leaving bracketed comment is true,
544+
// because that the last character of bracketed comment is still inside the comment and we can
545+
// only mark it and reduce bracketed comment level in next loop
546+
if (leavingBracketedComment) {
544547
bracketedCommentLevel -= 1
548+
leavingBracketedComment = false
545549
}
546550

547551
if (line.charAt(index) == '\'' && !insideComment) {
@@ -573,12 +577,12 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
573577
if (insideSingleQuote || insideDoubleQuote || insideComment) {
574578
// do not split
575579
} else {
576-
if (includingStatement) {
580+
if (isStatement) {
577581
// split, do not include ; itself
578582
ret.add(line.substring(beginIndex, index))
579583
}
580584
beginIndex = index + 1
581-
includingStatement = false
585+
isStatement = false
582586
}
583587
} else if (line.charAt(index) == '\n') {
584588
// with a new line the inline simple comment should end.
@@ -590,7 +594,7 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
590594
if (insideSingleQuote || insideDoubleQuote) {
591595
// Ignores '/' in any case of quotes
592596
} else if (insideBracketedComment && line.charAt(index - 1) == '*' ) {
593-
bracketedCommentRightBound = index
597+
leavingBracketedComment = true
594598
} else if (hasNext && !insideBracketedComment && line.charAt(index + 1) == '*') {
595599
bracketedCommentLevel += 1
596600
}
@@ -602,9 +606,9 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging {
602606
escape = true
603607
}
604608

605-
includingStatement = statementBegin(index)
609+
isStatement = statementInProgress(index)
606610
}
607-
if (includingStatement) {
611+
if (isStatement) {
608612
ret.add(line.substring(beginIndex))
609613
}
610614
ret

0 commit comments

Comments
 (0)