File tree Expand file tree Collapse file tree 5 files changed +12
-11
lines changed
main/scala/org/apache/spark/sql
test/scala/org/apache/spark/sql/catalyst/parser
core/src/test/scala/org/apache/spark/sql Expand file tree Collapse file tree 5 files changed +12
-11
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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]+$'" )
You can’t perform that action at this time.
0 commit comments