Repository: spark Updated Branches: refs/heads/branch-2.2 5e9541a4d -> 06c985c1b
[SPARK-20399][SQL][FOLLOW-UP] Add a config to fallback string literal parsing consistent with old sql parser behavior ## What changes were proposed in this pull request? As srowen pointed in https://github.com/apache/spark/commit/609ba5f2b9fd89b1b9971d08f7cc680d202dbc7c#commitcomment-22221259, the previous tests are not proper. This follow-up is going to fix the tests. ## How was this patch tested? Jenkins tests. Please review http://spark.apache.org/contributing.html before opening a pull request. Author: Liang-Chi Hsieh <vii...@gmail.com> Closes #18048 from viirya/SPARK-20399-follow-up. (cherry picked from commit 442287ae2993c24abb31fee6b5f6395724ca3dc7) Signed-off-by: Wenchen Fan <wenc...@databricks.com> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/06c985c1 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/06c985c1 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/06c985c1 Branch: refs/heads/branch-2.2 Commit: 06c985c1b4bb72a0a1102f12757124fbaa265a84 Parents: 5e9541a Author: Liang-Chi Hsieh <vii...@gmail.com> Authored: Tue May 23 16:09:38 2017 +0800 Committer: Wenchen Fan <wenc...@databricks.com> Committed: Tue May 23 16:09:55 2017 +0800 ---------------------------------------------------------------------- .../catalyst/parser/ExpressionParserSuite.scala | 30 +++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/06c985c1/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala ---------------------------------------------------------------------- diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala index ab81897..2d9d1f7 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala @@ -458,22 +458,30 @@ class ExpressionParserSuite extends PlanTest { assertEqual("'pattern\\\\\\%'", "pattern\\\\\\%", parser) // Escaped characters. - assertEqual("'\0'", "\u0000", parser) // ASCII NUL (X'00') + // Unescape string literal "'\\0'" for ASCII NUL (X'00') doesn't work + // when ESCAPED_STRING_LITERALS is enabled. + // It is parsed literally. + assertEqual("'\\0'", "\\0", parser) // Note: Single quote follows 1.6 parsing behavior when ESCAPED_STRING_LITERALS is enabled. val e = intercept[ParseException](parser.parseExpression("'\''")) assert(e.message.contains("extraneous input '''")) - assertEqual("'\"'", "\"", parser) // Double quote - assertEqual("'\b'", "\b", parser) // Backspace - assertEqual("'\n'", "\n", parser) // Newline - assertEqual("'\r'", "\r", parser) // Carriage return - assertEqual("'\t'", "\t", parser) // Tab character - - // Octals - assertEqual("'\110\145\154\154\157\041'", "Hello!", parser) - // Unicode - assertEqual("'\u0057\u006F\u0072\u006C\u0064\u0020\u003A\u0029'", "World :)", parser) + // The unescape special characters (e.g., "\\t") for 2.0+ don't work + // when ESCAPED_STRING_LITERALS is enabled. They are parsed literally. + assertEqual("'\\\"'", "\\\"", parser) // Double quote + assertEqual("'\\b'", "\\b", parser) // Backspace + assertEqual("'\\n'", "\\n", parser) // Newline + assertEqual("'\\r'", "\\r", parser) // Carriage return + assertEqual("'\\t'", "\\t", parser) // Tab character + + // The unescape Octals for 2.0+ don't work when ESCAPED_STRING_LITERALS is enabled. + // They are parsed literally. + assertEqual("'\\110\\145\\154\\154\\157\\041'", "\\110\\145\\154\\154\\157\\041", parser) + // The unescape Unicode for 2.0+ doesn't work when ESCAPED_STRING_LITERALS is enabled. + // They are parsed literally. + assertEqual("'\\u0057\\u006F\\u0072\\u006C\\u0064\\u0020\\u003A\\u0029'", + "\\u0057\\u006F\\u0072\\u006C\\u0064\\u0020\\u003A\\u0029", parser) } else { // Default behavior --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org