-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31595][SQL] Spark sql should allow unescaped quote mark in quoted string #28393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -507,6 +507,9 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging { | |
| } | ||
|
|
||
| // Adapted splitSemiColon from Hive 2.3's CliDriver.splitSemiColon. | ||
| // Note: [SPARK-31595] if there is a `'` in a double quoted string, or a `"` in a single quoted | ||
| // string, the origin implementation from Hive will not drop the trailing semicolon as expected, | ||
| // hence we refined this function a little bit. | ||
| private def splitSemiColon(line: String): JList[String] = { | ||
| var insideSingleQuote = false | ||
| var insideDoubleQuote = false | ||
|
|
@@ -519,13 +522,15 @@ private[hive] class SparkSQLCLIDriver extends CliDriver with Logging { | |
| for (index <- 0 until line.length) { | ||
| if (line.charAt(index) == '\'' && !insideComment) { | ||
| // take a look to see if it is escaped | ||
| if (!escape) { | ||
| // See the comment above about SPARK-31595 | ||
| if (!escape && !insideDoubleQuote) { | ||
| // flip the boolean variable | ||
| insideSingleQuote = !insideSingleQuote | ||
| } | ||
| } else if (line.charAt(index) == '\"' && !insideComment) { | ||
| // take a look to see if it is escaped | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adrian-wang Same. |
||
| if (!escape) { | ||
| // See the comment above about SPARK-31595 | ||
| if (!escape && !insideSingleQuote) { | ||
| // flip the boolean variable | ||
| insideDoubleQuote = !insideDoubleQuote | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,4 +500,13 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE | |
| | ;""".stripMargin -> "testcomment" | ||
| ) | ||
| } | ||
|
|
||
| test("SPARK-31595 Should allow unescaped quote mark in quoted string") { | ||
| runCliWithin(1.minute)( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explicitly set false at
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this has nothing to do with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ur, I got it. I think the option is misleading... Could you remove it from the PR descritpion?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done that, thanks! |
||
| "SELECT '\"legal string a';select 1 + 234;".stripMargin -> "235" | ||
| ) | ||
| runCliWithin(1.minute)( | ||
| "SELECT \"legal 'string b\";select 22222 + 1;".stripMargin -> "22223" | ||
| ) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrian-wang Should we update the comment to reflect the newly added condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, maybe we can rephrase this comment here.