Pārlūkot izejas kodu

[beeswax] Better multi query separation support

Now understand the "escaped by '\\'".
Romain Rigaux 11 gadi atpakaļ
vecāks
revīzija
0e09ed5

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

@@ -189,12 +189,11 @@ def split_statements(hql):
   """
   statements = []
   current = ''
-  prev = ''
   between_quotes = None
 
   for c in hql:
     current += c
-    if c in ('"', "'") and prev != '\\':
+    if c in ('"', "'"):
       if between_quotes == c:
         between_quotes = None
       elif between_quotes is None:
@@ -203,7 +202,6 @@ def split_statements(hql):
       if between_quotes is None:
         statements.append(current)
         current = ''
-    prev = c
 
   if current and current != ';':
     statements.append(current)

+ 30 - 1
apps/beeswax/src/beeswax/tests.py

@@ -1724,8 +1724,37 @@ def test_split_statements():
   assert_equal(["select * where id == '10'"], hql_query("select * where id == '10';").statements)
   assert_equal(['select', "select * where id == '10;' limit 100"], hql_query("select; select * where id == '10;' limit 100;").statements)
   assert_equal(['select', "select * where id == \"10;\" limit 100"], hql_query("select; select * where id == \"10;\" limit 100;").statements)
-  assert_equal(['select', "select * where id == '\\'10;' limit 100"], hql_query("select; select * where id == '\\'10;' limit 100;").statements)
   assert_equal(['select', "select * where id == '\"10;\"\"\"' limit 100"], hql_query("select; select * where id == '\"10;\"\"\"' limit 100;").statements)
+  query = """CREATE DATABASE IF NOT EXISTS functional;
+DROP TABLE IF EXISTS functional.alltypes;
+CREATE EXTERNAL TABLE IF NOT EXISTS functional.alltypes (
+id int COMMENT 'Add a comment',
+bool_col boolean,
+tinyint_col tinyint,
+smallint_col smallint,
+int_col int,
+bigint_col bigint,
+float_col float,
+double_col double,
+date_string_col string,
+string_col string,
+timestamp_col timestamp)
+PARTITIONED BY (year int, month int)
+ROW FORMAT delimited fields terminated by ','  escaped by '\\'
+STORED AS TEXTFILE
+LOCATION '/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);"""
+  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'",
+                '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)'
+              ],
+              hql_query(query).statements, hql_query(query).statements)
 
 
 class MockHiveServerTable(HiveServerTable):