Explorar o código

HUE-2224 [beeswax] Ignore escaped characters while splitting queries

Ashu Pachauri %!s(int64=11) %!d(string=hai) anos
pai
achega
c0da227
Modificáronse 2 ficheiros con 6 adicións e 3 borrados
  1. 4 1
      apps/beeswax/src/beeswax/design.py
  2. 2 2
      apps/beeswax/src/beeswax/tests.py

+ 4 - 1
apps/beeswax/src/beeswax/design.py

@@ -201,7 +201,7 @@ def split_statements(hql):
   for line in lines:
     for c in line:
       current += c
-      if c in ('"', "'") and is_comment is None:
+      if c in ('"', "'") and prev != '\\' and is_comment is None:
         if between_quotes == c:
           between_quotes = None
         elif between_quotes is None:
@@ -216,6 +216,9 @@ def split_statements(hql):
           if len(current) > 1:
             statements.append(current)
           current = ''
+      # This character holds no significance if it was escaped within a string
+      if prev == '\\' and between_quotes is not None:
+        c = ''
       prev = c
     is_comment = None
     prev = os.linesep

+ 2 - 2
apps/beeswax/src/beeswax/tests.py

@@ -1762,7 +1762,7 @@ date_string_col string,
 string_col string,
 timestamp_col timestamp)
 PARTITIONED BY (year int, month int)
-ROW FORMAT delimited fields terminated by ','  escaped by '\\'
+ROW FORMAT delimited fields terminated by ','  escaped by '\\\\'
 STORED AS TEXTFILE
 LOCATION '/user/admin/alltypes/alltypes';
 
@@ -1771,7 +1771,7 @@ ALTER TABLE alltypes ADD IF NOT EXISTS PARTITION(year=2009, month=1);
 ALTER TABLE alltypes ADD IF NOT EXISTS PARTITION(year=2009, month=2);"""
   assert_equal(['CREATE DATABASE IF NOT EXISTS functional',
                 'DROP TABLE IF EXISTS functional.alltypes',
-                "CREATE EXTERNAL TABLE IF NOT EXISTS functional.alltypes (\nid int COMMENT 'Add a comment',\nbool_col boolean,\ntinyint_col tinyint,\nsmallint_col smallint,\nint_col int,\nbigint_col bigint,\nfloat_col float,\ndouble_col double,\ndate_string_col string,\nstring_col string,\ntimestamp_col timestamp)\nPARTITIONED BY (year int, month int)\nROW FORMAT delimited fields terminated by ','  escaped by '\\'\nSTORED AS TEXTFILE\nLOCATION '/user/admin/alltypes/alltypes'",
+                "CREATE EXTERNAL TABLE IF NOT EXISTS functional.alltypes (\nid int COMMENT 'Add a comment',\nbool_col boolean,\ntinyint_col tinyint,\nsmallint_col smallint,\nint_col int,\nbigint_col bigint,\nfloat_col float,\ndouble_col double,\ndate_string_col string,\nstring_col string,\ntimestamp_col timestamp)\nPARTITIONED BY (year int, month int)\nROW FORMAT delimited fields terminated by ','  escaped by '\\\\'\nSTORED AS TEXTFILE\nLOCATION '/user/admin/alltypes/alltypes'",
                 'USE functional',
                 'ALTER TABLE alltypes ADD IF NOT EXISTS PARTITION(year=2009, month=1)',
                 'ALTER TABLE alltypes ADD IF NOT EXISTS PARTITION(year=2009, month=2)'