Skip to content

Commit 8ae0747

Browse files
committed
Address comments.
1 parent d0b2c22 commit 8ae0747

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
14091409
* Special characters can be escaped by using Hive/C-style escaping.
14101410
*/
14111411
private def createString(ctx: StringLiteralContext): String = {
1412-
if (conf.noUnescapedStringLiteral) {
1412+
if (conf.escapedStringLiterals) {
14131413
ctx.STRING().asScala.map(stringWithoutUnescape).mkString
14141414
} else {
14151415
ctx.STRING().asScala.map(string).mkString

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParserUtils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ object ParserUtils {
7070

7171
/** Convert a string node into a string without unescaping. */
7272
def stringWithoutUnescape(node: TerminalNode): String = {
73+
// STRING parser rule forces that the input always has quotes at the starting and ending.
7374
node.getText.slice(1, node.getText.size - 1)
7475
}
7576

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ object SQLConf {
196196
.booleanConf
197197
.createWithDefault(true)
198198

199-
val NO_UNESCAPED_SQL_STRING = buildConf("spark.sql.noUnescapedStringLiteral")
199+
val ESCAPED_STRING_LITERALS = buildConf("spark.sql.parser.escapedStringLiterals")
200200
.internal()
201-
.doc("Since Spark 2.0, we use unescaped SQL string for string literals including regex. " +
202-
"It is different than 1.6 behavior. Enabling this config can use no unescaped SQL string " +
203-
"literals and mitigate migration problem.")
201+
.doc("When true, string literals (including regex patterns) remains escaped in our SQL " +
202+
"parser. The default is false since Spark 2.0. Setting it to true can restore the behavior " +
203+
"prior to Spark 2.0.")
204204
.booleanConf
205205
.createWithDefault(false)
206206

@@ -919,7 +919,7 @@ class SQLConf extends Serializable with Logging {
919919

920920
def constraintPropagationEnabled: Boolean = getConf(CONSTRAINT_PROPAGATION_ENABLED)
921921

922-
def noUnescapedStringLiteral: Boolean = getConf(NO_UNESCAPED_SQL_STRING)
922+
def escapedStringLiterals: Boolean = getConf(ESCAPED_STRING_LITERALS)
923923

924924
/**
925925
* Returns the [[Resolver]] for the current configuration, which can be used to determine if two

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ class ExpressionParserSuite extends PlanTest {
166166
assertEqual("a not regexp 'pattern%'", !('a rlike "pattern%"))
167167
}
168168

169-
test("like expressions with NO_UNESCAPED_SQL_STRING") {
169+
test("like expressions with ESCAPED_STRING_LITERALS = true") {
170170
val conf = new SQLConf()
171-
conf.setConfString("spark.sql.noUnescapedStringLiteral", "true")
171+
conf.setConfString("spark.sql.parser.escapedStringLiterals", "true")
172172
val parser = new CatalystSqlParser(conf)
173173
assertEqual("a rlike '^\\x20[\\x20-\\x23]+$'", 'a rlike "^\\x20[\\x20-\\x23]+$", parser)
174174
assertEqual("a rlike 'pattern\\\\'", 'a rlike "pattern\\\\", parser)
@@ -462,9 +462,9 @@ class ExpressionParserSuite extends PlanTest {
462462
assertEqual("'\\u0057\\u006F\\u0072\\u006C\\u0064\\u0020\\u003A\\u0029'", "World :)")
463463
}
464464

465-
test("strings with NO_UNESCAPED_SQL_STRING") {
465+
test("strings with ESCAPED_STRING_LITERALS = true") {
466466
val conf = new SQLConf()
467-
conf.setConfString("spark.sql.noUnescapedStringLiteral", "true")
467+
conf.setConfString("spark.sql.parser.escapedStringLiterals", "true")
468468
val parser = new CatalystSqlParser(conf)
469469

470470
// Single Strings.

sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ class DatasetSuite extends QueryTest with SharedSQLContext {
11711171
}
11721172

11731173
test("do not unescaped regex pattern string") {
1174-
withSQLConf(SQLConf.NO_UNESCAPED_SQL_STRING.key -> "true") {
1174+
withSQLConf(SQLConf.ESCAPED_STRING_LITERALS.key -> "true") {
11751175
val data = Seq("\u0020\u0021\u0023", "abc")
11761176
val df = data.toDF()
11771177
val rlike1 = df.filter("value rlike '^\\x20[\\x20-\\x23]+$'")

0 commit comments

Comments
 (0)