diff --git a/shell/ext-py/sqlparse-0.1.14/sqlparse/lexer.py b/shell/ext-py/sqlparse-0.1.14/sqlparse/lexer.py index 6bd414fb6..b7a33ff28 100644 --- a/shell/ext-py/sqlparse-0.1.14/sqlparse/lexer.py +++ b/shell/ext-py/sqlparse-0.1.14/sqlparse/lexer.py @@ -191,8 +191,7 @@ class Lexer(object): (r'[-]?[0-9]*(\.[0-9]+)?[eE][-]?[0-9]+', tokens.Number.Float), (r'[-]?[0-9]*\.[0-9]+', tokens.Number.Float), (r'[-]?[0-9]+', tokens.Number.Integer), - # TODO: Backslash escapes? - (r"'(''|\\'|[^'])*'", tokens.String.Single), + (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single), # not a real string literal in ANSI SQL: (r'(""|".*?[^\\]")', tokens.String.Symbol), (r'(\[.*[^\]]\])', tokens.Name), diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_split.py b/shell/ext-py/sqlparse-0.1.14/tests/test_split.py index e4ebf7e51..54e8d04db 100644 --- a/shell/ext-py/sqlparse-0.1.14/tests/test_split.py +++ b/shell/ext-py/sqlparse-0.1.14/tests/test_split.py @@ -22,6 +22,10 @@ class SQLSplitTest(TestCaseBase): self.ndiffAssertEqual(unicode(stmts[0]), self._sql1) self.ndiffAssertEqual(unicode(stmts[1]), sql2) + def test_split_backslash(self): + stmts = sqlparse.parse(r"select '\\'; select '\''; select '\\\'';") + self.assertEqual(len(stmts), 3) + def test_create_function(self): sql = load_file('function.sql') stmts = sqlparse.parse(sql) diff --git a/tests/shell/test_shell_commandline.py b/tests/shell/test_shell_commandline.py index d5052469c..c34913b46 100755 --- a/tests/shell/test_shell_commandline.py +++ b/tests/shell/test_shell_commandline.py @@ -74,6 +74,12 @@ class TestImpalaShell(object): args = '-q "%s" -B' % queries run_impala_shell_cmd(args) + @pytest.mark.execute_serially + def test_multiple_queries_with_escaped_backslash(self): + # Regression test for string containing an escaped backslash. This relies on the + # patch at thirdparty/patches/sqlparse/0001-....patch. + run_impala_shell_cmd(r'''-q "select '\\\\'; select '\\'';" -B''') + @pytest.mark.execute_serially def test_default_db(self): args = '-d %s -q "describe %s" --quiet' % (TEST_DB, TEST_TBL)