http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/sqlparse/tokens.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/sqlparse/tokens.py 
b/shell/ext-py/sqlparse-0.1.19/sqlparse/tokens.py
new file mode 100644
index 0000000..01a9b89
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/sqlparse/tokens.py
@@ -0,0 +1,83 @@
+# Copyright (C) 2008 Andi Albrecht, albrecht.a...@gmail.com
+#
+# This module is part of python-sqlparse and is released under
+# the BSD License: http://www.opensource.org/licenses/bsd-license.php.
+
+# The Token implementation is based on pygment's token system written
+# by Georg Brandl.
+# http://pygments.org/
+
+"""Tokens"""
+
+
+class _TokenType(tuple):
+    parent = None
+
+    def split(self):
+        buf = []
+        node = self
+        while node is not None:
+            buf.append(node)
+            node = node.parent
+        buf.reverse()
+        return buf
+
+    def __contains__(self, val):
+        return val is not None and (self is val or val[:len(self)] == self)
+
+    def __getattr__(self, val):
+        if not val or not val[0].isupper():
+            return tuple.__getattribute__(self, val)
+        new = _TokenType(self + (val,))
+        setattr(self, val, new)
+        new.parent = self
+        return new
+
+    def __hash__(self):
+        return hash(tuple(self))
+
+    def __repr__(self):
+        return 'Token' + (self and '.' or '') + '.'.join(self)
+
+
+Token = _TokenType()
+
+# Special token types
+Text = Token.Text
+Whitespace = Text.Whitespace
+Newline = Whitespace.Newline
+Error = Token.Error
+# Text that doesn't belong to this lexer (e.g. HTML in PHP)
+Other = Token.Other
+
+# Common token types for source code
+Keyword = Token.Keyword
+Name = Token.Name
+Literal = Token.Literal
+String = Literal.String
+Number = Literal.Number
+Punctuation = Token.Punctuation
+Operator = Token.Operator
+Comparison = Operator.Comparison
+Wildcard = Token.Wildcard
+Comment = Token.Comment
+Assignment = Token.Assignement
+
+# Generic types for non-source code
+Generic = Token.Generic
+
+# String and some others are not direct childs of Token.
+# alias them:
+Token.Token = Token
+Token.String = String
+Token.Number = Number
+
+# SQL specific tokens
+DML = Keyword.DML
+DDL = Keyword.DDL
+Command = Keyword.Command
+
+Group = Token.Group
+Group.Parenthesis = Token.Group.Parenthesis
+Group.Comment = Token.Group.Comment
+Group.Where = Token.Group.Where

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/sqlparse/utils.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/sqlparse/utils.py 
b/shell/ext-py/sqlparse-0.1.19/sqlparse/utils.py
new file mode 100644
index 0000000..3a49ac2
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/sqlparse/utils.py
@@ -0,0 +1,137 @@
+'''
+Created on 17/05/2012
+
+@author: piranna
+'''
+
+import re
+
+try:
+    from collections import OrderedDict
+except ImportError:
+    OrderedDict = None
+
+
+if OrderedDict:
+    class Cache(OrderedDict):
+        """Cache with LRU algorithm using an OrderedDict as basis
+        """
+        def __init__(self, maxsize=100):
+            OrderedDict.__init__(self)
+
+            self._maxsize = maxsize
+
+        def __getitem__(self, key, *args, **kwargs):
+            # Get the key and remove it from the cache, or raise KeyError
+            value = OrderedDict.__getitem__(self, key)
+            del self[key]
+
+            # Insert the (key, value) pair on the front of the cache
+            OrderedDict.__setitem__(self, key, value)
+
+            # Return the value from the cache
+            return value
+
+        def __setitem__(self, key, value, *args, **kwargs):
+            # Key was inserted before, remove it so we put it at front later
+            if key in self:
+                del self[key]
+
+            # Too much items on the cache, remove the least recent used
+            elif len(self) >= self._maxsize:
+                self.popitem(False)
+
+            # Insert the (key, value) pair on the front of the cache
+            OrderedDict.__setitem__(self, key, value, *args, **kwargs)
+
+else:
+    class Cache(dict):
+        """Cache that reset when gets full
+        """
+        def __init__(self, maxsize=100):
+            dict.__init__(self)
+
+            self._maxsize = maxsize
+
+        def __setitem__(self, key, value, *args, **kwargs):
+            # Reset the cache if we have too much cached entries and start over
+            if len(self) >= self._maxsize:
+                self.clear()
+
+            # Insert the (key, value) pair on the front of the cache
+            dict.__setitem__(self, key, value, *args, **kwargs)
+
+
+def memoize_generator(func):
+    """Memoize decorator for generators
+
+    Store `func` results in a cache according to their arguments as 'memoize'
+    does but instead this works on decorators instead of regular functions.
+    Obviusly, this is only useful if the generator will always return the same
+    values for each specific parameters...
+    """
+    cache = Cache()
+
+    def wrapped_func(*args, **kwargs):
+#        params = (args, kwargs)
+        params = (args, tuple(sorted(kwargs.items())))
+
+        # Look if cached
+        try:
+            cached = cache[params]
+
+        # Not cached, exec and store it
+        except KeyError:
+            cached = []
+
+            for item in func(*args, **kwargs):
+                cached.append(item)
+                yield item
+
+            cache[params] = cached
+
+        # Cached, yield its items
+        else:
+            for item in cached:
+                yield item
+
+    return wrapped_func
+
+
+# This regular expression replaces the home-cooked parser that was here before.
+# It is much faster, but requires an extra post-processing step to get the
+# desired results (that are compatible with what you would expect from the
+# str.splitlines() method).
+#
+# It matches groups of characters: newlines, quoted strings, or unquoted text,
+# and splits on that basis. The post-processing step puts those back together
+# into the actual lines of SQL.
+SPLIT_REGEX = re.compile(r"""
+(
+ (?:                     # Start of non-capturing group
+  (?:\r\n|\r|\n)      |  # Match any single newline, or
+  [^\r\n'"]+          |  # Match any character series without quotes or
+                         # newlines, or
+  "(?:[^"\\]|\\.)*"   |  # Match double-quoted strings, or
+  '(?:[^'\\]|\\.)*'      # Match single quoted strings
+ )
+)
+""", re.VERBOSE)
+
+LINE_MATCH = re.compile(r'(\r\n|\r|\n)')
+
+def split_unquoted_newlines(text):
+    """Split a string on all unquoted newlines.
+
+    Unlike str.splitlines(), this will ignore CR/LF/CR+LF if the requisite
+    character is inside of a string."""
+    lines = SPLIT_REGEX.split(text)
+    outputlines = ['']
+    for line in lines:
+        if not line:
+            continue
+        elif LINE_MATCH.match(line):
+            outputlines.append('')
+        else:
+            outputlines[-1] += line
+    return outputlines
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/__init__.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/__init__.py 
b/shell/ext-py/sqlparse-0.1.19/tests/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/_Make_DirEntry.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/_Make_DirEntry.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/_Make_DirEntry.sql
new file mode 100644
index 0000000..e877bf1
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/_Make_DirEntry.sql
@@ -0,0 +1,6 @@
+-- Make a new dir entry
+-- and return its inode
+
+
+INSERT INTO dir_entries(type)
+                VALUES(:type)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/begintag.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/begintag.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/begintag.sql
new file mode 100644
index 0000000..699b365
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/begintag.sql
@@ -0,0 +1,4 @@
+begin;
+update foo
+       set bar = 1;
+commit;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/begintag_2.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/begintag_2.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/begintag_2.sql
new file mode 100644
index 0000000..0de26d6
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/begintag_2.sql
@@ -0,0 +1,13 @@
+CREATE TRIGGER IF NOT EXISTS remove_if_it_was_the_last_file_link
+-- Delete the direntry when is removed it's last static link
+    AFTER DELETE ON links
+    WHEN NOT EXISTS
+    (
+        SELECT * FROM links
+        WHERE child_entry = OLD.child_entry
+        LIMIT 1
+    )
+BEGIN
+    DELETE FROM dir_entries
+    WHERE dir_entries.inode = OLD.child_entry;
+END;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/dashcomment.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/dashcomment.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/dashcomment.sql
new file mode 100644
index 0000000..0d5ac62
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/dashcomment.sql
@@ -0,0 +1,5 @@
+select * from user;
+--select * from host;
+select * from user;
+select * -- foo;
+from foo;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/function.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/function.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/function.sql
new file mode 100644
index 0000000..d19227f
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/function.sql
@@ -0,0 +1,13 @@
+CREATE OR REPLACE FUNCTION foo(
+       p_in1 VARCHAR
+       , p_in2 INTEGER
+) RETURNS INTEGER AS
+
+  DECLARE
+       v_foo INTEGER;  
+  BEGIN
+       SELECT *
+       FROM foo
+       INTO v_foo;
+       RETURN v_foo.id;
+  END;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql.sql
new file mode 100644
index 0000000..e485f7a
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql.sql
@@ -0,0 +1,72 @@
+CREATE OR REPLACE FUNCTION public.delete_data (
+    p_tabelle VARCHAR
+  , p_key VARCHAR
+  , p_value INTEGER
+) RETURNS INTEGER AS
+$$
+DECLARE
+    p_retval                INTEGER;
+    v_constraint            RECORD;
+    v_count                 INTEGER;
+    v_data                  RECORD;
+    v_fieldname             VARCHAR;
+    v_sql                   VARCHAR;
+    v_key                   VARCHAR;
+    v_value                 INTEGER;
+BEGIN
+    v_sql := 'SELECT COUNT(*) FROM ' || p_tabelle || ' WHERE ' || p_key || ' = 
' || p_value;
+    --RAISE NOTICE '%', v_sql;
+    EXECUTE v_sql INTO v_count;
+    IF v_count::integer != 0 THEN
+        SELECT att.attname
+            INTO v_key
+            FROM pg_attribute att
+                LEFT JOIN pg_constraint con ON con.conrelid = att.attrelid 
+                    AND con.conkey[1] = att.attnum 
+                    AND con.contype = 'p', pg_type typ, pg_class rel, 
pg_namespace ns
+            WHERE att.attrelid = rel.oid
+                AND att.attnum > 0 
+                AND typ.oid = att.atttypid
+                AND att.attisdropped = false
+                AND rel.relname = p_tabelle
+                AND con.conkey[1] = 1
+                AND ns.oid = rel.relnamespace
+                AND ns.nspname = 'public'
+            ORDER BY att.attnum;
+        v_sql := 'SELECT ' || v_key || ' AS id FROM ' || p_tabelle || ' WHERE 
' || p_key || ' = ' || p_value;
+        FOR v_data IN EXECUTE v_sql
+        LOOP
+            --RAISE NOTICE ' -> % %', p_tabelle, v_data.id;
+            FOR v_constraint IN SELECT t.constraint_name
+                                , t.constraint_type
+                                , t.table_name
+                                , c.column_name
+                                FROM public.v_table_constraints t
+                                    , public.v_constraint_columns c
+                                WHERE t.constraint_name = c.constraint_name
+                                    AND t.constraint_type = 'FOREIGN KEY'
+                                    AND c.table_name = p_tabelle
+                                    AND t.table_schema = 'public'
+                                    AND c.table_schema = 'public'
+            LOOP
+                v_fieldname := substring(v_constraint.constraint_name from 1 
for length(v_constraint.constraint_name) - length(v_constraint.column_name) - 
1);
+                IF (v_constraint.table_name = p_tabelle) AND (p_value = 
v_data.id) THEN
+                    --RAISE NOTICE 'Skip (Selbstverweis)';
+                    CONTINUE;
+                ELSE
+                    PERFORM delete_data(v_constraint.table_name::varchar, 
v_fieldname::varchar, v_data.id::integer);
+                END IF;
+            END LOOP;
+        END LOOP;
+        v_sql := 'DELETE FROM ' || p_tabelle || ' WHERE ' || p_key || ' = ' || 
p_value;
+        --RAISE NOTICE '%', v_sql;
+        EXECUTE v_sql;
+        p_retval := 1;
+    ELSE
+        --RAISE NOTICE ' -> Keine Sätze gefunden';
+        p_retval := 0;
+    END IF;
+    RETURN p_retval;
+END;
+$$
+LANGUAGE plpgsql;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql2.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql2.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql2.sql
new file mode 100644
index 0000000..b5d494c
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql2.sql
@@ -0,0 +1,7 @@
+CREATE OR REPLACE FUNCTION update_something() RETURNS void AS
+$body$
+BEGIN
+    raise notice 'foo';
+END;
+$body$
+LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql3.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql3.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql3.sql
new file mode 100644
index 0000000..b25d818
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/function_psql3.sql
@@ -0,0 +1,8 @@
+CREATE OR REPLACE FUNCTION foo() RETURNS integer AS
+$body$
+DECLARE
+BEGIN
+ select * from foo;
+END;
+$body$
+LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/huge_select.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/huge_select.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/huge_select.sql
new file mode 100644
index 0000000..ab39823
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/huge_select.sql
@@ -0,0 +1 @@
+select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 
1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 
1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 
5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case 
when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as 
col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 
10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 
then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case 
when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as 
col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 
else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i 
= 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, 
case when i = 21 then 1 else 21 end as col21, case whe
 n i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 
then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when 
i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, 
case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as 
col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 
end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 
else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 
11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, 
case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 
end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 
then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case 
when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as 
col19, case when i = 20 then 1 else 20 end as col20, ca
 se when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 
end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, 
case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as 
col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 
end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 
else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 
then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when 
i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as 
col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 
else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i 
= 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, 
case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 
end as col18, case when i = 19 then 1 else 19 end as col
 19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 
21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION 
select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 
end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 
else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 
then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when 
i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, 
case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end 
as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 
else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i 
= 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, 
case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 
end as col17, case when i = 18 then 1 else 18 end 
 as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 
1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when 
i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 
else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 
then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when 
i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, 
case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as 
col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 
end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 
then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case 
when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as 
col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 
else 16 end as col16, case when i = 17 then 1 else 1
 7 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 
then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case 
when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as 
col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case 
when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as 
col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 
end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 
else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 
then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when 
i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as 
col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 
else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i 
= 15 then 1 else 15 end as col15, case when i = 16 then 1 
 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when 
i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as 
col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 
else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo 
UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 
else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 
then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when 
i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, 
case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as 
col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 
10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 
then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case 
when i = 14 then 1 else 14 end as col14, case when i = 15 t
 hen 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case 
when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as 
col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 
else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i 
= 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 
else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 
then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when 
i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, 
case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as 
col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 
end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 
then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case 
when i = 13 then 1 else 13 end as col13, case when i 
 = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as 
col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 
else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i 
= 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, 
case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 
end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, 
case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as 
col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 
end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 
else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 
then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when 
i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as 
col11, case when i = 12 then 1 else 12 end as col12, case w
 hen i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as 
col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 
else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i 
= 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, 
case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 
end as col21, case when i = 22 then 1 else 22 end as col22 from foo
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/files/test_cp1251.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/files/test_cp1251.sql 
b/shell/ext-py/sqlparse-0.1.19/tests/files/test_cp1251.sql
new file mode 100644
index 0000000..6c0228b
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/files/test_cp1251.sql
@@ -0,0 +1 @@
+insert into foo values (1); -- ����� ��� �������

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/test_filters.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_filters.py 
b/shell/ext-py/sqlparse-0.1.19/tests/test_filters.py
new file mode 100644
index 0000000..d827454
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/test_filters.py
@@ -0,0 +1,78 @@
+'''
+Created on 24/03/2012
+
+@author: piranna
+'''
+import unittest
+
+from sqlparse.filters import StripWhitespace, Tokens2Unicode
+from sqlparse.lexer import tokenize
+
+
+class Test__StripWhitespace(unittest.TestCase):
+    sql = """INSERT INTO dir_entries(type)VALUES(:type);
+
+            INSERT INTO directories(inode)
+                            VALUES(:inode)
+            LIMIT 1"""
+
+    sql2 = """SELECT child_entry,asdf AS inode, creation
+              FROM links
+              WHERE parent_dir == :parent_dir AND name == :name
+              LIMIT 1"""
+
+    sql3 = """SELECT
+    0 AS st_dev,
+    0 AS st_uid,
+    0 AS st_gid,
+
+    dir_entries.type         AS st_mode,
+    dir_entries.inode        AS st_ino,
+    COUNT(links.child_entry) AS st_nlink,
+
+    :creation                AS st_ctime,
+    dir_entries.access       AS st_atime,
+    dir_entries.modification AS st_mtime,
+
+    COALESCE(files.size,0) AS st_size,
+    COALESCE(files.size,0) AS size
+
+FROM dir_entries
+    LEFT JOIN files
+        ON dir_entries.inode == files.inode
+    LEFT JOIN links
+        ON dir_entries.inode == links.child_entry
+
+WHERE dir_entries.inode == :inode
+
+GROUP BY dir_entries.inode
+LIMIT 1"""
+
+    def test_StripWhitespace1(self):
+        self.assertEqual(
+            Tokens2Unicode(StripWhitespace(tokenize(self.sql))),
+            'INSERT INTO dir_entries(type)VALUES(:type);INSERT INTO '
+            'directories(inode)VALUES(:inode)LIMIT 1')
+
+    def test_StripWhitespace2(self):
+        self.assertEqual(
+            Tokens2Unicode(StripWhitespace(tokenize(self.sql2))),
+            'SELECT child_entry,asdf AS inode,creation FROM links WHERE '
+            'parent_dir==:parent_dir AND name==:name LIMIT 1')
+
+    def test_StripWhitespace3(self):
+        self.assertEqual(
+            Tokens2Unicode(StripWhitespace(tokenize(self.sql3))),
+            'SELECT 0 AS st_dev,0 AS st_uid,0 AS st_gid,dir_entries.type AS '
+            'st_mode,dir_entries.inode AS st_ino,COUNT(links.child_entry)AS '
+            'st_nlink,:creation AS st_ctime,dir_entries.access AS st_atime,'
+            'dir_entries.modification AS st_mtime,COALESCE(files.size,0)AS '
+            'st_size,COALESCE(files.size,0)AS size FROM dir_entries LEFT JOIN'
+            ' files ON dir_entries.inode==files.inode LEFT JOIN links ON '
+            'dir_entries.inode==links.child_entry WHERE dir_entries.inode=='
+            ':inode GROUP BY dir_entries.inode LIMIT 1')
+
+
+if __name__ == "__main__":
+    #import sys;sys.argv = ['', 'Test.testName']
+    unittest.main()

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/test_format.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_format.py 
b/shell/ext-py/sqlparse-0.1.19/tests/test_format.py
new file mode 100644
index 0000000..a105b1c
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/test_format.py
@@ -0,0 +1,346 @@
+# -*- coding: utf-8 -*-
+
+import pytest
+
+from tests.utils import TestCaseBase
+
+import sqlparse
+from sqlparse.exceptions import SQLParseError
+
+
+class TestFormat(TestCaseBase):
+
+    def test_keywordcase(self):
+        sql = 'select * from bar; -- select foo\n'
+        res = sqlparse.format(sql, keyword_case='upper')
+        self.ndiffAssertEqual(res, 'SELECT * FROM bar; -- select foo\n')
+        res = sqlparse.format(sql, keyword_case='capitalize')
+        self.ndiffAssertEqual(res, 'Select * From bar; -- select foo\n')
+        res = sqlparse.format(sql.upper(), keyword_case='lower')
+        self.ndiffAssertEqual(res, 'select * from BAR; -- SELECT FOO\n')
+        self.assertRaises(SQLParseError, sqlparse.format, sql,
+                          keyword_case='foo')
+
+    def test_identifiercase(self):
+        sql = 'select * from bar; -- select foo\n'
+        res = sqlparse.format(sql, identifier_case='upper')
+        self.ndiffAssertEqual(res, 'select * from BAR; -- select foo\n')
+        res = sqlparse.format(sql, identifier_case='capitalize')
+        self.ndiffAssertEqual(res, 'select * from Bar; -- select foo\n')
+        res = sqlparse.format(sql.upper(), identifier_case='lower')
+        self.ndiffAssertEqual(res, 'SELECT * FROM bar; -- SELECT FOO\n')
+        self.assertRaises(SQLParseError, sqlparse.format, sql,
+                          identifier_case='foo')
+        sql = 'select * from "foo"."bar"'
+        res = sqlparse.format(sql, identifier_case="upper")
+        self.ndiffAssertEqual(res, 'select * from "foo"."bar"')
+
+    def test_strip_comments_single(self):
+        sql = 'select *-- statement starts here\nfrom foo'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select * from foo')
+        sql = 'select * -- statement starts here\nfrom foo'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select * from foo')
+        sql = 'select-- foo\nfrom -- bar\nwhere'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select from where')
+        self.assertRaises(SQLParseError, sqlparse.format, sql,
+                          strip_comments=None)
+
+    def test_strip_comments_multi(self):
+        sql = '/* sql starts here */\nselect'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select')
+        sql = '/* sql starts here */ select'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select')
+        sql = '/*\n * sql starts here\n */\nselect'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select')
+        sql = 'select (/* sql starts here */ select 2)'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select (select 2)')
+        sql = 'select (/* sql /* starts here */ select 2)'
+        res = sqlparse.format(sql, strip_comments=True)
+        self.ndiffAssertEqual(res, 'select (select 2)')
+
+    def test_strip_ws(self):
+        f = lambda sql: sqlparse.format(sql, strip_whitespace=True)
+        s = 'select\n* from      foo\n\twhere  ( 1 = 2 )\n'
+        self.ndiffAssertEqual(f(s), 'select * from foo where (1 = 2)')
+        s = 'select -- foo\nfrom    bar\n'
+        self.ndiffAssertEqual(f(s), 'select -- foo\nfrom bar')
+        self.assertRaises(SQLParseError, sqlparse.format, s,
+                          strip_whitespace=None)
+
+    def test_preserve_ws(self):
+        # preserve at least one whitespace after subgroups
+        f = lambda sql: sqlparse.format(sql, strip_whitespace=True)
+        s = 'select\n* /* foo */  from bar '
+        self.ndiffAssertEqual(f(s), 'select * /* foo */ from bar')
+
+    def test_notransform_of_quoted_crlf(self):
+        # Make sure that CR/CR+LF characters inside string literals don't get
+        # affected by the formatter.
+
+        s1 = "SELECT some_column LIKE 'value\r'"
+        s2 = "SELECT some_column LIKE 'value\r'\r\nWHERE id = 1\n"
+        s3 = "SELECT some_column LIKE 'value\\'\r' WHERE id = 1\r"
+        s4 = "SELECT some_column LIKE 'value\\\\\\'\r' WHERE id = 1\r\n"
+
+        f = lambda x: sqlparse.format(x)
+
+        # Because of the use of
+        self.ndiffAssertEqual(f(s1), "SELECT some_column LIKE 'value\r'")
+        self.ndiffAssertEqual(f(s2), "SELECT some_column LIKE 'value\r'\nWHERE 
id = 1\n")
+        self.ndiffAssertEqual(f(s3), "SELECT some_column LIKE 'value\\'\r' 
WHERE id = 1\n")
+        self.ndiffAssertEqual(f(s4), "SELECT some_column LIKE 'value\\\\\\'\r' 
WHERE id = 1\n")
+
+    def test_outputformat(self):
+        sql = 'select * from foo;'
+        self.assertRaises(SQLParseError, sqlparse.format, sql,
+                          output_format='foo')
+
+
+class TestFormatReindent(TestCaseBase):
+
+    def test_option(self):
+        self.assertRaises(SQLParseError, sqlparse.format, 'foo',
+                          reindent=2)
+        self.assertRaises(SQLParseError, sqlparse.format, 'foo',
+                          indent_tabs=2)
+        self.assertRaises(SQLParseError, sqlparse.format, 'foo',
+                          reindent=True, indent_width='foo')
+        self.assertRaises(SQLParseError, sqlparse.format, 'foo',
+                          reindent=True, indent_width=-12)
+
+    def test_stmts(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select foo; select bar'
+        self.ndiffAssertEqual(f(s), 'select foo;\n\nselect bar')
+        s = 'select foo'
+        self.ndiffAssertEqual(f(s), 'select foo')
+        s = 'select foo; -- test\n select bar'
+        self.ndiffAssertEqual(f(s), 'select foo; -- test\n\nselect bar')
+
+    def test_keywords(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select * from foo union select * from bar;'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select *',
+                                               'from foo',
+                                               'union',
+                                               'select *',
+                                               'from bar;']))
+
+    def test_keywords_between(self):  # issue 14
+        # don't break AND after BETWEEN
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'and foo between 1 and 2 and bar = 3'
+        self.ndiffAssertEqual(f(s), '\n'.join(['',
+                                               'and foo between 1 and 2',
+                                               'and bar = 3']))
+
+    def test_parenthesis(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select count(*) from (select * from foo);'
+        self.ndiffAssertEqual(f(s),
+                              '\n'.join(['select count(*)',
+                                         'from',
+                                         '  (select *',
+                                         '   from foo);',
+                                         ])
+                              )
+
+    def test_where(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select * from foo where bar = 1 and baz = 2 or bzz = 3;'
+        self.ndiffAssertEqual(f(s), ('select *\nfrom foo\n'
+                                     'where bar = 1\n'
+                                     '  and baz = 2\n'
+                                     '  or bzz = 3;'))
+        s = 'select * from foo where bar = 1 and (baz = 2 or bzz = 3);'
+        self.ndiffAssertEqual(f(s), ('select *\nfrom foo\n'
+                                     'where bar = 1\n'
+                                     '  and (baz = 2\n'
+                                     '       or bzz = 3);'))
+
+    def test_join(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select * from foo join bar on 1 = 2'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select *',
+                                               'from foo',
+                                               'join bar on 1 = 2']))
+        s = 'select * from foo inner join bar on 1 = 2'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select *',
+                                               'from foo',
+                                               'inner join bar on 1 = 2']))
+        s = 'select * from foo left outer join bar on 1 = 2'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select *',
+                                               'from foo',
+                                               'left outer join bar on 1 = 2']
+                                              ))
+        s = 'select * from foo straight_join bar on 1 = 2'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select *',
+                                               'from foo',
+                                               'straight_join bar on 1 = 2']
+                                              ))
+
+    def test_identifier_list(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select foo, bar, baz from table1, table2 where 1 = 2'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select foo,',
+                                               '       bar,',
+                                               '       baz',
+                                               'from table1,',
+                                               '     table2',
+                                               'where 1 = 2']))
+        s = 'select a.*, b.id from a, b'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select a.*,',
+                                               '       b.id',
+                                               'from a,',
+                                               '     b']))
+
+    def test_identifier_list_with_functions(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = ("select 'abc' as foo, coalesce(col1, col2)||col3 as bar,"
+             "col3 from my_table")
+        self.ndiffAssertEqual(f(s), '\n'.join(
+            ["select 'abc' as foo,",
+             "       coalesce(col1, col2)||col3 as bar,",
+             "       col3",
+             "from my_table"]))
+
+    def test_case(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'case when foo = 1 then 2 when foo = 3 then 4 else 5 end'
+        self.ndiffAssertEqual(f(s), '\n'.join(['case',
+                                               '    when foo = 1 then 2',
+                                               '    when foo = 3 then 4',
+                                               '    else 5',
+                                               'end']))
+
+    def test_case2(self):
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'case(foo) when bar = 1 then 2 else 3 end'
+        self.ndiffAssertEqual(f(s), '\n'.join(['case(foo)',
+                                               '    when bar = 1 then 2',
+                                               '    else 3',
+                                               'end']))
+
+    def test_nested_identifier_list(self):  # issue4
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = '(foo as bar, bar1, bar2 as bar3, b4 as b5)'
+        self.ndiffAssertEqual(f(s), '\n'.join(['(foo as bar,',
+                                               ' bar1,',
+                                               ' bar2 as bar3,',
+                                               ' b4 as b5)']))
+
+    def test_duplicate_linebreaks(self):  # issue3
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select c1 -- column1\nfrom foo'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select c1 -- column1',
+                                               'from foo']))
+        s = 'select c1 -- column1\nfrom foo'
+        r = sqlparse.format(s, reindent=True, strip_comments=True)
+        self.ndiffAssertEqual(r, '\n'.join(['select c1',
+                                            'from foo']))
+        s = 'select c1\nfrom foo\norder by c1'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select c1',
+                                               'from foo',
+                                               'order by c1']))
+        s = 'select c1 from t1 where (c1 = 1) order by c1'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select c1',
+                                               'from t1',
+                                               'where (c1 = 1)',
+                                               'order by c1']))
+
+    def test_keywordfunctions(self):  # issue36
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select max(a) b, foo, bar'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select max(a) b,',
+                                               '       foo,',
+                                               '       bar']))
+
+    def test_identifier_and_functions(self):  # issue45
+        f = lambda sql: sqlparse.format(sql, reindent=True)
+        s = 'select foo.bar, nvl(1) from dual'
+        self.ndiffAssertEqual(f(s), '\n'.join(['select foo.bar,',
+                                               '       nvl(1)',
+                                               'from dual']))
+
+
+class TestOutputFormat(TestCaseBase):
+
+    def test_python(self):
+        sql = 'select * from foo;'
+        f = lambda sql: sqlparse.format(sql, output_format='python')
+        self.ndiffAssertEqual(f(sql), "sql = 'select * from foo;'")
+        f = lambda sql: sqlparse.format(sql, output_format='python',
+                                        reindent=True)
+        self.ndiffAssertEqual(f(sql), ("sql = ('select * '\n"
+                                       "       'from foo;')"))
+
+    def test_php(self):
+        sql = 'select * from foo;'
+        f = lambda sql: sqlparse.format(sql, output_format='php')
+        self.ndiffAssertEqual(f(sql), '$sql = "select * from foo;";')
+        f = lambda sql: sqlparse.format(sql, output_format='php',
+                                        reindent=True)
+        self.ndiffAssertEqual(f(sql), ('$sql  = "select * ";\n'
+                                       '$sql .= "from foo;";'))
+
+    def test_sql(self):  # "sql" is an allowed option but has no effect
+        sql = 'select * from foo;'
+        f = lambda sql: sqlparse.format(sql, output_format='sql')
+        self.ndiffAssertEqual(f(sql), 'select * from foo;')
+
+
+def test_format_column_ordering():  # issue89
+    sql = 'select * from foo order by c1 desc, c2, c3;'
+    formatted = sqlparse.format(sql, reindent=True)
+    expected = '\n'.join(['select *',
+                          'from foo',
+                          'order by c1 desc,',
+                          '         c2,',
+                          '         c3;'])
+    assert formatted == expected
+
+
+def test_truncate_strings():
+    sql = 'update foo set value = \'' + 'x' * 1000 + '\';'
+    formatted = sqlparse.format(sql, truncate_strings=10)
+    assert formatted == 'update foo set value = \'xxxxxxxxxx[...]\';'
+    formatted = sqlparse.format(sql, truncate_strings=3, truncate_char='YYY')
+    assert formatted == 'update foo set value = \'xxxYYY\';'
+
+
+def test_truncate_strings_invalid_option():
+    pytest.raises(SQLParseError, sqlparse.format,
+                  'foo', truncate_strings='bar')
+    pytest.raises(SQLParseError, sqlparse.format,
+                  'foo', truncate_strings=-1)
+    pytest.raises(SQLParseError, sqlparse.format,
+                  'foo', truncate_strings=0)
+
+
+@pytest.mark.parametrize('sql', ['select verrrylongcolumn from foo',
+                                 'select "verrrylongcolumn" from "foo"'])
+def test_truncate_strings_doesnt_truncate_identifiers(sql):
+    formatted = sqlparse.format(sql, truncate_strings=2)
+    assert formatted == sql
+
+
+def test_having_produces_newline():
+    sql = (
+        'select * from foo, bar where bar.id = foo.bar_id'
+        ' having sum(bar.value) > 100')
+    formatted = sqlparse.format(sql, reindent=True)
+    expected = [
+        'select *',
+        'from foo,',
+        '     bar',
+        'where bar.id = foo.bar_id',
+        'having sum(bar.value) > 100'
+    ]
+    assert formatted == '\n'.join(expected)

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/test_functions.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_functions.py 
b/shell/ext-py/sqlparse-0.1.19/tests/test_functions.py
new file mode 100644
index 0000000..52e2ce7
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/test_functions.py
@@ -0,0 +1,164 @@
+'''
+Created on 13/02/2012
+
+@author: piranna
+'''
+from unittest import main, TestCase
+
+from sqlparse.filters import IncludeStatement, Tokens2Unicode
+from sqlparse.lexer import tokenize
+
+import sys
+sys.path.insert(0, '..')
+
+from sqlparse.filters import compact
+from sqlparse.functions import getcolumns, getlimit, IsType
+
+
+class Test_IncludeStatement(TestCase):
+    sql = """-- type: script
+            -- return: integer
+
+            INCLUDE "_Make_DirEntry.sql";
+
+            INSERT INTO directories(inode)
+                            VALUES(:inode)
+            LIMIT 1"""
+
+    def test_includeStatement(self):
+        stream = tokenize(self.sql)
+        includeStatement = IncludeStatement('tests/files',
+                                            raiseexceptions=True)
+        stream = includeStatement.process(None, stream)
+        stream = compact(stream)
+
+        result = Tokens2Unicode(stream)
+
+        self.assertEqual(
+            result, (
+                'INSERT INTO dir_entries(type)VALUES(:type);INSERT INTO '
+                'directories(inode)VALUES(:inode)LIMIT 1'))
+
+
+class Test_SQL(TestCase):
+    sql = """-- type: script
+            -- return: integer
+
+            INSERT INTO directories(inode)
+                            VALUES(:inode)
+            LIMIT 1"""
+
+    sql2 = """SELECT child_entry,asdf AS inode, creation
+              FROM links
+              WHERE parent_dir == :parent_dir AND name == :name
+              LIMIT 1"""
+
+    sql3 = """SELECT
+    0 AS st_dev,
+    0 AS st_uid,
+    0 AS st_gid,
+
+    dir_entries.type         AS st_mode,
+    dir_entries.inode        AS st_ino,
+    COUNT(links.child_entry) AS st_nlink,
+
+    :creation                AS st_ctime,
+    dir_entries.access       AS st_atime,
+    dir_entries.modification AS st_mtime,
+--    :creation                                                AS st_ctime,
+--    CAST(STRFTIME('%s',dir_entries.access)       AS INTEGER) AS st_atime,
+--    CAST(STRFTIME('%s',dir_entries.modification) AS INTEGER) AS st_mtime,
+
+    COALESCE(files.size,0) AS st_size, -- Python-FUSE
+    COALESCE(files.size,0) AS size     -- PyFilesystem
+
+FROM dir_entries
+    LEFT JOIN files
+        ON dir_entries.inode == files.inode
+    LEFT JOIN links
+        ON dir_entries.inode == links.child_entry
+
+WHERE dir_entries.inode == :inode
+
+GROUP BY dir_entries.inode
+LIMIT 1"""
+
+
+class Test_Compact(Test_SQL):
+    def test_compact1(self):
+        stream = compact(tokenize(self.sql))
+
+        result = Tokens2Unicode(stream)
+
+        self.assertEqual(result,
+                         'INSERT INTO directories(inode)VALUES(:inode)LIMIT 1')
+
+    def test_compact2(self):
+        stream = tokenize(self.sql2)
+
+        result = compact(stream)
+
+        self.assertEqual(
+            Tokens2Unicode(result),
+            'SELECT child_entry,asdf AS inode,creation FROM links WHERE '
+            'parent_dir==:parent_dir AND name==:name LIMIT 1')
+
+    def test_compact3(self):
+        stream = tokenize(self.sql3)
+
+        result = compact(stream)
+
+        self.assertEqual(
+            Tokens2Unicode(result),
+            'SELECT 0 AS st_dev,0 AS st_uid,0 AS st_gid,dir_entries.type AS '
+            'st_mode,dir_entries.inode AS st_ino,COUNT(links.child_entry)AS '
+            'st_nlink,:creation AS st_ctime,dir_entries.access AS st_atime,'
+            'dir_entries.modification AS st_mtime,COALESCE(files.size,0)AS '
+            'st_size,COALESCE(files.size,0)AS size FROM dir_entries LEFT JOIN'
+            ' files ON dir_entries.inode==files.inode LEFT JOIN links ON '
+            'dir_entries.inode==links.child_entry WHERE dir_entries.inode=='
+            ':inode GROUP BY dir_entries.inode LIMIT 1')
+
+
+class Test_GetColumns(Test_SQL):
+    def test_getcolumns1(self):
+        columns = getcolumns(tokenize(self.sql))
+        self.assertEqual(columns, [])
+
+    def test_getcolumns2(self):
+        columns = getcolumns(tokenize(self.sql2))
+        self.assertEqual(columns, ['child_entry', 'inode', 'creation'])
+
+    def test_getcolumns3(self):
+        columns = getcolumns(tokenize(self.sql3))
+        self.assertEqual(columns, ['st_dev', 'st_uid', 'st_gid', 'st_mode',
+                                   'st_ino', 'st_nlink', 'st_ctime',
+                                   'st_atime', 'st_mtime', 'st_size', 'size'])
+
+
+class Test_GetLimit(Test_SQL):
+    def test_getlimit1(self):
+        limit = getlimit(tokenize(self.sql))
+        self.assertEqual(limit, 1)
+
+    def test_getlimit2(self):
+        limit = getlimit(tokenize(self.sql2))
+        self.assertEqual(limit, 1)
+
+    def test_getlimit3(self):
+        limit = getlimit(tokenize(self.sql3))
+        self.assertEqual(limit, 1)
+
+
+class Test_IsType(Test_SQL):
+    def test_istype2(self):
+        stream = tokenize(self.sql2)
+        self.assertTrue(IsType('SELECT')(stream))
+
+        stream = tokenize(self.sql2)
+        self.assertFalse(IsType('INSERT')(stream))
+
+
+if __name__ == "__main__":
+    #import sys;sys.argv = ['', 'Test.testName']
+    main()

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/test_grouping.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_grouping.py 
b/shell/ext-py/sqlparse-0.1.19/tests/test_grouping.py
new file mode 100644
index 0000000..5ade830
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/test_grouping.py
@@ -0,0 +1,399 @@
+# -*- coding: utf-8 -*-
+
+import pytest
+
+import sqlparse
+from sqlparse import sql
+from sqlparse import tokens as T
+
+from tests.utils import TestCaseBase
+
+
+class TestGrouping(TestCaseBase):
+
+    def test_parenthesis(self):
+        s = 'select (select (x3) x2) and (y2) bar'
+        parsed = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, str(parsed))
+        self.assertEqual(len(parsed.tokens), 7)
+        self.assert_(isinstance(parsed.tokens[2], sql.Parenthesis))
+        self.assert_(isinstance(parsed.tokens[-1], sql.Identifier))
+        self.assertEqual(len(parsed.tokens[2].tokens), 5)
+        self.assert_(isinstance(parsed.tokens[2].tokens[3], sql.Identifier))
+        self.assert_(isinstance(parsed.tokens[2].tokens[3].tokens[0], 
sql.Parenthesis))
+        self.assertEqual(len(parsed.tokens[2].tokens[3].tokens), 3)
+
+    def test_comments(self):
+        s = '/*\n * foo\n */   \n  bar'
+        parsed = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(parsed))
+        self.assertEqual(len(parsed.tokens), 2)
+
+    def test_assignment(self):
+        s = 'foo := 1;'
+        parsed = sqlparse.parse(s)[0]
+        self.assertEqual(len(parsed.tokens), 1)
+        self.assert_(isinstance(parsed.tokens[0], sql.Assignment))
+        s = 'foo := 1'
+        parsed = sqlparse.parse(s)[0]
+        self.assertEqual(len(parsed.tokens), 1)
+        self.assert_(isinstance(parsed.tokens[0], sql.Assignment))
+
+    def test_identifiers(self):
+        s = 'select foo.bar from "myscheme"."table" where fail. order'
+        parsed = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(parsed))
+        self.assert_(isinstance(parsed.tokens[2], sql.Identifier))
+        self.assert_(isinstance(parsed.tokens[6], sql.Identifier))
+        self.assert_(isinstance(parsed.tokens[8], sql.Where))
+        s = 'select * from foo where foo.id = 1'
+        parsed = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(parsed))
+        self.assert_(isinstance(parsed.tokens[-1].tokens[-1].tokens[0],
+                                sql.Identifier))
+        s = 'select * from (select "foo"."id" from foo)'
+        parsed = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(parsed))
+        self.assert_(isinstance(parsed.tokens[-1].tokens[3], sql.Identifier))
+
+        s = "INSERT INTO `test` VALUES('foo', 'bar');"
+        parsed = sqlparse.parse(s)[0]
+        types = [l.ttype for l in parsed.tokens if not l.is_whitespace()]
+        self.assertEquals(types, [T.DML, T.Keyword, None,
+                                  T.Keyword, None, T.Punctuation])
+
+        s = "select 1.0*(a+b) as col, sum(c)/sum(d) from myschema.mytable"
+        parsed = sqlparse.parse(s)[0]
+        self.assertEqual(len(parsed.tokens), 7)
+        self.assert_(isinstance(parsed.tokens[2], sql.IdentifierList))
+        self.assertEqual(len(parsed.tokens[2].tokens), 4)
+        identifiers = list(parsed.tokens[2].get_identifiers())
+        self.assertEqual(len(identifiers), 2)
+        self.assertEquals(identifiers[0].get_alias(), u"col")
+
+    def test_identifier_wildcard(self):
+        p = sqlparse.parse('a.*, b.id')[0]
+        self.assert_(isinstance(p.tokens[0], sql.IdentifierList))
+        self.assert_(isinstance(p.tokens[0].tokens[0], sql.Identifier))
+        self.assert_(isinstance(p.tokens[0].tokens[-1], sql.Identifier))
+
+    def test_identifier_name_wildcard(self):
+        p = sqlparse.parse('a.*')[0]
+        t = p.tokens[0]
+        self.assertEqual(t.get_name(), '*')
+        self.assertEqual(t.is_wildcard(), True)
+
+    def test_identifier_invalid(self):
+        p = sqlparse.parse('a.')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+        self.assertEqual(p.tokens[0].has_alias(), False)
+        self.assertEqual(p.tokens[0].get_name(), None)
+        self.assertEqual(p.tokens[0].get_real_name(), None)
+        self.assertEqual(p.tokens[0].get_parent_name(), 'a')
+
+    def test_identifier_as_invalid(self):  # issue8
+        p = sqlparse.parse('foo as select *')[0]
+        self.assert_(len(p.tokens), 5)
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+        self.assertEqual(len(p.tokens[0].tokens), 1)
+        self.assertEqual(p.tokens[2].ttype, T.Keyword)
+
+    def test_identifier_function(self):
+        p = sqlparse.parse('foo() as bar')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+        self.assert_(isinstance(p.tokens[0].tokens[0], sql.Function))
+        p = sqlparse.parse('foo()||col2 bar')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+        self.assert_(isinstance(p.tokens[0].tokens[0], sql.Function))
+
+    def test_identifier_extended(self):  # issue 15
+        p = sqlparse.parse('foo+100')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+        p = sqlparse.parse('foo + 100')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+        p = sqlparse.parse('foo*100')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Identifier))
+
+    def test_identifier_list(self):
+        p = sqlparse.parse('a, b, c')[0]
+        self.assert_(isinstance(p.tokens[0], sql.IdentifierList))
+        p = sqlparse.parse('(a, b, c)')[0]
+        self.assert_(isinstance(p.tokens[0].tokens[1], sql.IdentifierList))
+
+    def test_identifier_list_case(self):
+        p = sqlparse.parse('a, case when 1 then 2 else 3 end as b, c')[0]
+        self.assert_(isinstance(p.tokens[0], sql.IdentifierList))
+        p = sqlparse.parse('(a, case when 1 then 2 else 3 end as b, c)')[0]
+        self.assert_(isinstance(p.tokens[0].tokens[1], sql.IdentifierList))
+
+    def test_identifier_list_other(self):  # issue2
+        p = sqlparse.parse("select *, null, 1, 'foo', bar from mytable, x")[0]
+        self.assert_(isinstance(p.tokens[2], sql.IdentifierList))
+        l = p.tokens[2]
+        self.assertEqual(len(l.tokens), 13)
+
+    def test_identifier_list_with_inline_comments(self):  # issue163
+        p = sqlparse.parse('foo /* a comment */, bar')[0]
+        self.assert_(isinstance(p.tokens[0], sql.IdentifierList))
+        self.assert_(isinstance(p.tokens[0].tokens[0], sql.Identifier))
+        self.assert_(isinstance(p.tokens[0].tokens[3], sql.Identifier))
+
+    def test_where(self):
+        s = 'select * from foo where bar = 1 order by id desc'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertTrue(len(p.tokens), 16)
+        s = 'select x from (select y from foo where bar = 1) z'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertTrue(isinstance(p.tokens[-1].tokens[0].tokens[-2], 
sql.Where))
+
+    def test_typecast(self):
+        s = 'select foo::integer from bar'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertEqual(p.tokens[2].get_typecast(), 'integer')
+        self.assertEqual(p.tokens[2].get_name(), 'foo')
+        s = 'select (current_database())::information_schema.sql_identifier'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertEqual(p.tokens[2].get_typecast(),
+                         'information_schema.sql_identifier')
+
+    def test_alias(self):
+        s = 'select foo as bar from mytable'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertEqual(p.tokens[2].get_real_name(), 'foo')
+        self.assertEqual(p.tokens[2].get_alias(), 'bar')
+        s = 'select foo from mytable t1'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertEqual(p.tokens[6].get_real_name(), 'mytable')
+        self.assertEqual(p.tokens[6].get_alias(), 't1')
+        s = 'select foo::integer as bar from mytable'
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertEqual(p.tokens[2].get_alias(), 'bar')
+        s = ('SELECT DISTINCT '
+             '(current_database())::information_schema.sql_identifier AS view')
+        p = sqlparse.parse(s)[0]
+        self.ndiffAssertEqual(s, unicode(p))
+        self.assertEqual(p.tokens[4].get_alias(), 'view')
+
+    def test_alias_case(self):  # see issue46
+        p = sqlparse.parse('CASE WHEN 1 THEN 2 ELSE 3 END foo')[0]
+        self.assertEqual(len(p.tokens), 1)
+        self.assertEqual(p.tokens[0].get_alias(), 'foo')
+
+    def test_alias_returns_none(self):  # see issue185
+        p = sqlparse.parse('foo.bar')[0]
+        self.assertEqual(len(p.tokens), 1)
+        self.assertEqual(p.tokens[0].get_alias(), None)
+
+    def test_idlist_function(self):  # see issue10 too
+        p = sqlparse.parse('foo(1) x, bar')[0]
+        self.assert_(isinstance(p.tokens[0], sql.IdentifierList))
+
+    def test_comparison_exclude(self):
+        # make sure operators are not handled too lazy
+        p = sqlparse.parse('(=)')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Parenthesis))
+        self.assert_(not isinstance(p.tokens[0].tokens[1], sql.Comparison))
+        p = sqlparse.parse('(a=1)')[0]
+        self.assert_(isinstance(p.tokens[0].tokens[1], sql.Comparison))
+        p = sqlparse.parse('(a>=1)')[0]
+        self.assert_(isinstance(p.tokens[0].tokens[1], sql.Comparison))
+
+    def test_function(self):
+        p = sqlparse.parse('foo()')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Function))
+        p = sqlparse.parse('foo(null, bar)')[0]
+        self.assert_(isinstance(p.tokens[0], sql.Function))
+        self.assertEqual(len(list(p.tokens[0].get_parameters())), 2)
+
+    def test_function_not_in(self):  # issue183
+        p = sqlparse.parse('in(1, 2)')[0]
+        self.assertEqual(len(p.tokens), 2)
+        self.assertEqual(p.tokens[0].ttype, T.Keyword)
+        self.assert_(isinstance(p.tokens[1], sql.Parenthesis))
+
+    def test_varchar(self):
+        p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
+        self.assert_(isinstance(p.tokens[2], sql.Function))
+
+
+class TestStatement(TestCaseBase):
+
+    def test_get_type(self):
+        f = lambda sql: sqlparse.parse(sql)[0]
+        self.assertEqual(f('select * from foo').get_type(), 'SELECT')
+        self.assertEqual(f('update foo').get_type(), 'UPDATE')
+        self.assertEqual(f(' update foo').get_type(), 'UPDATE')
+        self.assertEqual(f('\nupdate foo').get_type(), 'UPDATE')
+        self.assertEqual(f('foo').get_type(), 'UNKNOWN')
+        # Statements that have a whitespace after the closing semicolon
+        # are parsed as two statements where later only consists of the
+        # trailing whitespace.
+        self.assertEqual(f('\n').get_type(), 'UNKNOWN')
+
+
+def test_identifier_with_operators():  # issue 53
+    p = sqlparse.parse('foo||bar')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Identifier)
+    # again with whitespaces
+    p = sqlparse.parse('foo || bar')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Identifier)
+
+
+def test_identifier_with_op_trailing_ws():
+    # make sure trailing whitespace isn't grouped with identifier
+    p = sqlparse.parse('foo || bar ')[0]
+    assert len(p.tokens) == 2
+    assert isinstance(p.tokens[0], sql.Identifier)
+    assert p.tokens[1].ttype is T.Whitespace
+
+
+def test_identifier_with_string_literals():
+    p = sqlparse.parse('foo + \'bar\'')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Identifier)
+
+
+# This test seems to be wrong. It was introduced when fixing #53, but #111
+# showed that this shouldn't be an identifier at all. I'm leaving this
+# commented in the source for a while.
+# def test_identifier_string_concat():
+#     p = sqlparse.parse('\'foo\' || bar')[0]
+#     assert len(p.tokens) == 1
+#     assert isinstance(p.tokens[0], sql.Identifier)
+
+
+def test_identifier_consumes_ordering():  # issue89
+    p = sqlparse.parse('select * from foo order by c1 desc, c2, c3')[0]
+    assert isinstance(p.tokens[-1], sql.IdentifierList)
+    ids = list(p.tokens[-1].get_identifiers())
+    assert len(ids) == 3
+    assert ids[0].get_name() == 'c1'
+    assert ids[0].get_ordering() == 'DESC'
+    assert ids[1].get_name() == 'c2'
+    assert ids[1].get_ordering() is None
+
+
+def test_comparison_with_keywords():  # issue90
+    # in fact these are assignments, but for now we don't distinguish them
+    p = sqlparse.parse('foo = NULL')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    assert len(p.tokens[0].tokens) == 5
+    assert p.tokens[0].left.value == 'foo'
+    assert p.tokens[0].right.value == 'NULL'
+    # make sure it's case-insensitive
+    p = sqlparse.parse('foo = null')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+
+
+def test_comparison_with_floats():  # issue145
+    p = sqlparse.parse('foo = 25.5')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    assert len(p.tokens[0].tokens) == 5
+    assert p.tokens[0].left.value == 'foo'
+    assert p.tokens[0].right.value == '25.5'
+
+
+def test_comparison_with_parenthesis():  # issue23
+    p = sqlparse.parse('(3 + 4) = 7')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    comp = p.tokens[0]
+    assert isinstance(comp.left, sql.Parenthesis)
+    assert comp.right.ttype is T.Number.Integer
+
+
+def test_comparison_with_strings():  # issue148
+    p = sqlparse.parse('foo = \'bar\'')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Comparison)
+    assert p.tokens[0].right.value == '\'bar\''
+    assert p.tokens[0].right.ttype == T.String.Single
+
+
+@pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
+def test_forloops(start):
+    p = sqlparse.parse('%s foo in bar LOOP foobar END LOOP' % start)[0]
+    assert (len(p.tokens)) == 1
+    assert isinstance(p.tokens[0], sql.For)
+
+
+def test_nested_for():
+    p = sqlparse.parse('FOR foo LOOP FOR bar LOOP END LOOP END LOOP')[0]
+    assert len(p.tokens) == 1
+    for1 = p.tokens[0]
+    assert for1.tokens[0].value == 'FOR'
+    assert for1.tokens[-1].value == 'END LOOP'
+    for2 = for1.tokens[6]
+    assert isinstance(for2, sql.For)
+    assert for2.tokens[0].value == 'FOR'
+    assert for2.tokens[-1].value == 'END LOOP'
+
+
+def test_begin():
+    p = sqlparse.parse('BEGIN foo END')[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sql.Begin)
+
+
+def test_nested_begin():
+    p = sqlparse.parse('BEGIN foo BEGIN bar END END')[0]
+    assert len(p.tokens) == 1
+    outer = p.tokens[0]
+    assert outer.tokens[0].value == 'BEGIN'
+    assert outer.tokens[-1].value == 'END'
+    inner = outer.tokens[4]
+    assert inner.tokens[0].value == 'BEGIN'
+    assert inner.tokens[-1].value == 'END'
+    assert isinstance(inner, sql.Begin)
+
+
+def test_aliased_column_without_as():
+    p = sqlparse.parse('foo bar')[0].tokens
+    assert len(p) == 1
+    assert p[0].get_real_name() == 'foo'
+    assert p[0].get_alias() == 'bar'
+
+    p = sqlparse.parse('foo.bar baz')[0].tokens[0]
+    assert p.get_parent_name() == 'foo'
+    assert p.get_real_name() == 'bar'
+    assert p.get_alias() == 'baz'
+
+
+def test_qualified_function():
+    p = sqlparse.parse('foo()')[0].tokens[0]
+    assert p.get_parent_name() is None
+    assert p.get_real_name() == 'foo'
+
+    p = sqlparse.parse('foo.bar()')[0].tokens[0]
+    assert p.get_parent_name() == 'foo'
+    assert p.get_real_name() == 'bar'
+
+
+def test_aliased_function_without_as():
+    p = sqlparse.parse('foo() bar')[0].tokens[0]
+    assert p.get_parent_name() is None
+    assert p.get_real_name() == 'foo'
+    assert p.get_alias() == 'bar'
+
+    p = sqlparse.parse('foo.bar() baz')[0].tokens[0]
+    assert p.get_parent_name() == 'foo'
+    assert p.get_real_name() == 'bar'
+    assert p.get_alias() == 'baz'
+
+
+def test_aliased_literal_without_as():
+    p = sqlparse.parse('1 foo')[0].tokens
+    assert len(p) == 1
+    assert p[0].get_alias() == 'foo'

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/test_parse.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_parse.py 
b/shell/ext-py/sqlparse-0.1.19/tests/test_parse.py
new file mode 100644
index 0000000..6c9d6a6
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/test_parse.py
@@ -0,0 +1,305 @@
+# -*- coding: utf-8 -*-
+
+"""Tests sqlparse function."""
+
+import pytest
+
+from tests.utils import TestCaseBase
+
+import sqlparse
+import sqlparse.sql
+
+from sqlparse import tokens as T
+
+
+class SQLParseTest(TestCaseBase):
+    """Tests sqlparse.parse()."""
+
+    def test_tokenize(self):
+        sql = 'select * from foo;'
+        stmts = sqlparse.parse(sql)
+        self.assertEqual(len(stmts), 1)
+        self.assertEqual(str(stmts[0]), sql)
+
+    def test_multistatement(self):
+        sql1 = 'select * from foo;'
+        sql2 = 'select * from bar;'
+        stmts = sqlparse.parse(sql1 + sql2)
+        self.assertEqual(len(stmts), 2)
+        self.assertEqual(str(stmts[0]), sql1)
+        self.assertEqual(str(stmts[1]), sql2)
+
+    def test_newlines(self):
+        sql = u'select\n*from foo;'
+        p = sqlparse.parse(sql)[0]
+        self.assertEqual(unicode(p), sql)
+        sql = u'select\r\n*from foo'
+        p = sqlparse.parse(sql)[0]
+        self.assertEqual(unicode(p), sql)
+        sql = u'select\r*from foo'
+        p = sqlparse.parse(sql)[0]
+        self.assertEqual(unicode(p), sql)
+        sql = u'select\r\n*from foo\n'
+        p = sqlparse.parse(sql)[0]
+        self.assertEqual(unicode(p), sql)
+
+    def test_within(self):
+        sql = 'foo(col1, col2)'
+        p = sqlparse.parse(sql)[0]
+        col1 = p.tokens[0].tokens[1].tokens[1].tokens[0]
+        self.assert_(col1.within(sqlparse.sql.Function))
+
+    def test_child_of(self):
+        sql = '(col1, col2)'
+        p = sqlparse.parse(sql)[0]
+        self.assert_(p.tokens[0].tokens[1].is_child_of(p.tokens[0]))
+        sql = 'select foo'
+        p = sqlparse.parse(sql)[0]
+        self.assert_(not p.tokens[2].is_child_of(p.tokens[0]))
+        self.assert_(p.tokens[2].is_child_of(p))
+
+    def test_has_ancestor(self):
+        sql = 'foo or (bar, baz)'
+        p = sqlparse.parse(sql)[0]
+        baz = p.tokens[-1].tokens[1].tokens[-1]
+        self.assert_(baz.has_ancestor(p.tokens[-1].tokens[1]))
+        self.assert_(baz.has_ancestor(p.tokens[-1]))
+        self.assert_(baz.has_ancestor(p))
+
+    def test_float(self):
+        t = sqlparse.parse('.5')[0].tokens
+        self.assertEqual(len(t), 1)
+        self.assert_(t[0].ttype is sqlparse.tokens.Number.Float)
+        t = sqlparse.parse('.51')[0].tokens
+        self.assertEqual(len(t), 1)
+        self.assert_(t[0].ttype is sqlparse.tokens.Number.Float)
+        t = sqlparse.parse('1.5')[0].tokens
+        self.assertEqual(len(t), 1)
+        self.assert_(t[0].ttype is sqlparse.tokens.Number.Float)
+        t = sqlparse.parse('12.5')[0].tokens
+        self.assertEqual(len(t), 1)
+        self.assert_(t[0].ttype is sqlparse.tokens.Number.Float)
+
+    def test_placeholder(self):
+        def _get_tokens(sql):
+            return sqlparse.parse(sql)[0].tokens[-1].tokens
+        t = _get_tokens('select * from foo where user = ?')
+        self.assert_(t[-1].ttype is sqlparse.tokens.Name.Placeholder)
+        self.assertEqual(t[-1].value, '?')
+        t = _get_tokens('select * from foo where user = :1')
+        self.assert_(t[-1].ttype is sqlparse.tokens.Name.Placeholder)
+        self.assertEqual(t[-1].value, ':1')
+        t = _get_tokens('select * from foo where user = :name')
+        self.assert_(t[-1].ttype is sqlparse.tokens.Name.Placeholder)
+        self.assertEqual(t[-1].value, ':name')
+        t = _get_tokens('select * from foo where user = %s')
+        self.assert_(t[-1].ttype is sqlparse.tokens.Name.Placeholder)
+        self.assertEqual(t[-1].value, '%s')
+        t = _get_tokens('select * from foo where user = $a')
+        self.assert_(t[-1].ttype is sqlparse.tokens.Name.Placeholder)
+        self.assertEqual(t[-1].value, '$a')
+
+    def test_modulo_not_placeholder(self):
+        tokens = list(sqlparse.lexer.tokenize('x %3'))
+        self.assertEqual(tokens[2][0], sqlparse.tokens.Operator)
+
+    def test_access_symbol(self):  # see issue27
+        t = sqlparse.parse('select a.[foo bar] as foo')[0].tokens
+        self.assert_(isinstance(t[-1], sqlparse.sql.Identifier))
+        self.assertEqual(t[-1].get_name(), 'foo')
+        self.assertEqual(t[-1].get_real_name(), '[foo bar]')
+        self.assertEqual(t[-1].get_parent_name(), 'a')
+
+    def test_square_brackets_notation_isnt_too_greedy(self):  # see issue153
+        t = sqlparse.parse('[foo], [bar]')[0].tokens
+        self.assert_(isinstance(t[0], sqlparse.sql.IdentifierList))
+        self.assertEqual(len(t[0].tokens), 4)
+        self.assertEqual(t[0].tokens[0].get_real_name(), '[foo]')
+        self.assertEqual(t[0].tokens[-1].get_real_name(), '[bar]')
+
+    def test_keyword_like_identifier(self):  # see issue47
+        t = sqlparse.parse('foo.key')[0].tokens
+        self.assertEqual(len(t), 1)
+        self.assert_(isinstance(t[0], sqlparse.sql.Identifier))
+
+    def test_function_parameter(self):  # see issue94
+        t = sqlparse.parse('abs(some_col)')[0].tokens[0].get_parameters()
+        self.assertEqual(len(t), 1)
+        self.assert_(isinstance(t[0], sqlparse.sql.Identifier))
+
+    def test_function_param_single_literal(self):
+        t = sqlparse.parse('foo(5)')[0].tokens[0].get_parameters()
+        self.assertEqual(len(t), 1)
+        self.assert_(t[0].ttype is T.Number.Integer)
+
+    def test_nested_function(self):
+        t = sqlparse.parse('foo(bar(5))')[0].tokens[0].get_parameters()
+        self.assertEqual(len(t), 1)
+        self.assert_(type(t[0]) is sqlparse.sql.Function)
+
+
+def test_quoted_identifier():
+    t = sqlparse.parse('select x.y as "z" from foo')[0].tokens
+    assert isinstance(t[2], sqlparse.sql.Identifier)
+    assert t[2].get_name() == 'z'
+    assert t[2].get_real_name() == 'y'
+
+
+@pytest.mark.parametrize('name', [
+    'foo',
+    '_foo',
+])
+def test_valid_identifier_names(name):  # issue175
+    t = sqlparse.parse(name)[0].tokens
+    assert isinstance(t[0], sqlparse.sql.Identifier)
+
+
+def test_psql_quotation_marks():  # issue83
+    # regression: make sure plain $$ work
+    t = sqlparse.split("""
+    CREATE OR REPLACE FUNCTION testfunc1(integer) RETURNS integer AS $$
+          ....
+    $$ LANGUAGE plpgsql;
+    CREATE OR REPLACE FUNCTION testfunc2(integer) RETURNS integer AS $$
+          ....
+    $$ LANGUAGE plpgsql;""")
+    assert len(t) == 2
+    # make sure $SOMETHING$ works too
+    t = sqlparse.split("""
+    CREATE OR REPLACE FUNCTION testfunc1(integer) RETURNS integer AS $PROC_1$
+          ....
+    $PROC_1$ LANGUAGE plpgsql;
+    CREATE OR REPLACE FUNCTION testfunc2(integer) RETURNS integer AS $PROC_2$
+          ....
+    $PROC_2$ LANGUAGE plpgsql;""")
+    assert len(t) == 2
+
+
+def test_double_precision_is_builtin():
+    sql = 'DOUBLE PRECISION'
+    t = sqlparse.parse(sql)[0].tokens
+    assert (len(t) == 1
+            and t[0].ttype == sqlparse.tokens.Name.Builtin
+            and t[0].value == 'DOUBLE PRECISION')
+
+
+@pytest.mark.parametrize('ph', ['?', ':1', ':foo', '%s', '%(foo)s'])
+def test_placeholder(ph):
+    p = sqlparse.parse(ph)[0].tokens
+    assert len(p) == 1
+    assert p[0].ttype is T.Name.Placeholder
+
+
+@pytest.mark.parametrize('num', ['6.67428E-8', '1.988e33', '1e-12'])
+def test_scientific_numbers(num):
+    p = sqlparse.parse(num)[0].tokens
+    assert len(p) == 1
+    assert p[0].ttype is T.Number.Float
+
+
+def test_single_quotes_are_strings():
+    p = sqlparse.parse("'foo'")[0].tokens
+    assert len(p) == 1
+    assert p[0].ttype is T.String.Single
+
+
+def test_double_quotes_are_identifiers():
+    p = sqlparse.parse('"foo"')[0].tokens
+    assert len(p) == 1
+    assert isinstance(p[0], sqlparse.sql.Identifier)
+
+
+def test_single_quotes_with_linebreaks():  # issue118
+    p = sqlparse.parse("'f\nf'")[0].tokens
+    assert len(p) == 1
+    assert p[0].ttype is T.String.Single
+
+
+def test_sqlite_identifiers():
+    # Make sure we still parse sqlite style escapes
+    p = sqlparse.parse('[col1],[col2]')[0].tokens
+    assert (len(p) == 1
+            and isinstance(p[0], sqlparse.sql.IdentifierList)
+            and [id.get_name() for id in p[0].get_identifiers()]
+                    == ['[col1]', '[col2]'])
+
+    p = sqlparse.parse('[col1]+[col2]')[0]
+    types = [tok.ttype for tok in p.flatten()]
+    assert types == [T.Name, T.Operator, T.Name]
+
+
+def test_simple_1d_array_index():
+    p = sqlparse.parse('col[1]')[0].tokens
+    assert len(p) == 1
+    assert p[0].get_name() == 'col'
+    indices = list(p[0].get_array_indices())
+    assert (len(indices) == 1  # 1-dimensional index
+            and len(indices[0]) == 1  # index is single token
+            and indices[0][0].value == '1')
+
+
+def test_2d_array_index():
+    p = sqlparse.parse('col[x][(y+1)*2]')[0].tokens
+    assert len(p) == 1
+    assert p[0].get_name() == 'col'
+    assert len(list(p[0].get_array_indices())) == 2  # 2-dimensional index
+
+
+def test_array_index_function_result():
+    p = sqlparse.parse('somefunc()[1]')[0].tokens
+    assert len(p) == 1
+    assert len(list(p[0].get_array_indices())) == 1
+
+
+def test_schema_qualified_array_index():
+    p = sqlparse.parse('schem.col[1]')[0].tokens
+    assert len(p) == 1
+    assert p[0].get_parent_name() == 'schem'
+    assert p[0].get_name() == 'col'
+    assert list(p[0].get_array_indices())[0][0].value == '1'
+
+
+def test_aliased_array_index():
+    p = sqlparse.parse('col[1] x')[0].tokens
+    assert len(p) == 1
+    assert p[0].get_alias() == 'x'
+    assert p[0].get_real_name() == 'col'
+    assert list(p[0].get_array_indices())[0][0].value == '1'
+
+
+def test_array_literal():
+    # See issue #176
+    p = sqlparse.parse('ARRAY[%s, %s]')[0]
+    assert len(p.tokens) == 2
+    assert len(list(p.flatten())) == 7
+
+
+def test_typed_array_definition():
+    # array indices aren't grouped with builtins, but make sure we can extract
+    # indentifer names
+    p = sqlparse.parse('x int, y int[], z int')[0]
+    names = [x.get_name() for x in p.get_sublists()
+             if isinstance(x, sqlparse.sql.Identifier)]
+    assert names == ['x', 'y', 'z']
+
+
+@pytest.mark.parametrize('sql', [
+    'select 1 -- foo',
+    'select 1 # foo'  # see issue178
+])
+def test_single_line_comments(sql):
+    p = sqlparse.parse(sql)[0]
+    assert len(p.tokens) == 5
+    assert p.tokens[-1].ttype == T.Comment.Single
+
+
+@pytest.mark.parametrize('sql', [
+    'foo',
+    '@foo',
+    '#foo',  # see issue192
+    '##foo'
+])
+def test_names_and_special_names(sql):
+    p = sqlparse.parse(sql)[0]
+    assert len(p.tokens) == 1
+    assert isinstance(p.tokens[0], sqlparse.sql.Identifier)

http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.19/tests/test_pipeline.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_pipeline.py 
b/shell/ext-py/sqlparse-0.1.19/tests/test_pipeline.py
new file mode 100644
index 0000000..3442a5b
--- /dev/null
+++ b/shell/ext-py/sqlparse-0.1.19/tests/test_pipeline.py
@@ -0,0 +1,70 @@
+import unittest
+
+from sqlparse.filters import ColumnsSelect
+from sqlparse.lexer import tokenize
+from sqlparse.pipeline import Pipeline
+
+
+class Test(unittest.TestCase):
+
+    def setUp(self):
+        self.pipe = Pipeline()
+        self.pipe.append(tokenize)
+        self.pipe.append(ColumnsSelect())
+
+    def test_1(self):
+        sql = """
+        -- type: script
+        -- return: integer
+
+        INCLUDE "Direntry.make.sql";
+
+        INSERT INTO directories(inode)
+        VALUES(:inode)
+        LIMIT 1"""
+        self.assertEqual([], self.pipe(sql))
+
+    def test_2(self):
+        sql = """
+        SELECT child_entry,asdf AS inode, creation
+        FROM links
+        WHERE parent_dir == :parent_dir AND name == :name
+        LIMIT 1"""
+        self.assertEqual([u'child_entry', u'inode', u'creation'],
+                         self.pipe(sql))
+
+    def test_3(self):
+        sql = """
+SELECT
+0 AS st_dev,
+0 AS st_uid,
+0 AS st_gid,
+
+dir_entries.type         AS st_mode,
+dir_entries.inode        AS st_ino,
+COUNT(links.child_entry) AS st_nlink,
+
+:creation                AS st_ctime,
+dir_entries.access       AS st_atime,
+dir_entries.modification AS st_mtime,
+--    :creation                                                AS st_ctime,
+--    CAST(STRFTIME('%s',dir_entries.access)       AS INTEGER) AS st_atime,
+--    CAST(STRFTIME('%s',dir_entries.modification) AS INTEGER) AS st_mtime,
+
+COALESCE(files.size,0) AS st_size, -- Python-FUSE
+COALESCE(files.size,0) AS size     -- PyFilesystem
+
+FROM dir_entries
+LEFT JOIN files
+ON dir_entries.inode == files.inode
+LEFT JOIN links
+ON dir_entries.inode == links.child_entry
+
+WHERE dir_entries.inode == :inode
+
+GROUP BY dir_entries.inode
+LIMIT 1"""
+        self.assertEqual([u'st_dev', u'st_uid', u'st_gid', u'st_mode',
+                          u'st_ino', u'st_nlink', u'st_ctime',
+                          u'st_atime', u'st_mtime', u'st_size', u'size'],
+                         self.pipe(sql))

Reply via email to