You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jo...@apache.org on 2018/05/10 21:48:58 UTC
[6/8] impala git commit: IMPALA-6999: Upgrade to sqlparse-0.1.19 for
Impala shell
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/sqlparse/utils.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/sqlparse/utils.py b/shell/ext-py/sqlparse-0.1.14/sqlparse/utils.py
deleted file mode 100644
index 3a49ac2..0000000
--- a/shell/ext-py/sqlparse-0.1.14/sqlparse/utils.py
+++ /dev/null
@@ -1,137 +0,0 @@
-'''
-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.14/tests/__init__.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/__init__.py b/shell/ext-py/sqlparse-0.1.14/tests/__init__.py
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/files/_Make_DirEntry.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/_Make_DirEntry.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/_Make_DirEntry.sql
deleted file mode 100644
index e877bf1..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/_Make_DirEntry.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- 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.14/tests/files/begintag.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/begintag.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/begintag.sql
deleted file mode 100644
index 699b365..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/begintag.sql
+++ /dev/null
@@ -1,4 +0,0 @@
-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.14/tests/files/begintag_2.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/begintag_2.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/begintag_2.sql
deleted file mode 100644
index 0de26d6..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/begintag_2.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-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.14/tests/files/dashcomment.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/dashcomment.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/dashcomment.sql
deleted file mode 100644
index 0d5ac62..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/dashcomment.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-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.14/tests/files/function.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/function.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/function.sql
deleted file mode 100644
index d19227f..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/function.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-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.14/tests/files/function_psql.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql.sql
deleted file mode 100644
index e485f7a..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql.sql
+++ /dev/null
@@ -1,72 +0,0 @@
-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.14/tests/files/function_psql2.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql2.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql2.sql
deleted file mode 100644
index b5d494c..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql2.sql
+++ /dev/null
@@ -1,7 +0,0 @@
-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.14/tests/files/function_psql3.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql3.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql3.sql
deleted file mode 100644
index b25d818..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/function_psql3.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-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.14/tests/files/huge_select.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/huge_select.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/huge_select.sql
deleted file mode 100644
index ab39823..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/huge_select.sql
+++ /dev/null
@@ -1 +0,0 @@
-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.14/tests/files/test_cp1251.sql
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/files/test_cp1251.sql b/shell/ext-py/sqlparse-0.1.14/tests/files/test_cp1251.sql
deleted file mode 100644
index 6c0228b..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/files/test_cp1251.sql
+++ /dev/null
@@ -1 +0,0 @@
-insert into foo values (1); -- ����� ��� �������
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/test_filters.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_filters.py b/shell/ext-py/sqlparse-0.1.14/tests/test_filters.py
deleted file mode 100644
index d827454..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_filters.py
+++ /dev/null
@@ -1,78 +0,0 @@
-'''
-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.14/tests/test_format.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_format.py b/shell/ext-py/sqlparse-0.1.14/tests/test_format.py
deleted file mode 100644
index b77b7a1..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_format.py
+++ /dev/null
@@ -1,328 +0,0 @@
-# -*- 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)')
-
- 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
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/test_functions.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_functions.py b/shell/ext-py/sqlparse-0.1.14/tests/test_functions.py
deleted file mode 100644
index 52e2ce7..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_functions.py
+++ /dev/null
@@ -1,164 +0,0 @@
-'''
-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.14/tests/test_grouping.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_grouping.py b/shell/ext-py/sqlparse-0.1.14/tests/test_grouping.py
deleted file mode 100644
index 86d4c7a..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_grouping.py
+++ /dev/null
@@ -1,341 +0,0 @@
-# -*- 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), 9)
- self.assert_(isinstance(parsed.tokens[2], sql.Parenthesis))
- self.assert_(isinstance(parsed.tokens[-3], sql.Parenthesis))
- self.assertEqual(len(parsed.tokens[2].tokens), 7)
- self.assert_(isinstance(parsed.tokens[2].tokens[3], 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_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[-3].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_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_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)
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/test_parse.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_parse.py b/shell/ext-py/sqlparse-0.1.14/tests/test_parse.py
deleted file mode 100644
index d77bb43..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_parse.py
+++ /dev/null
@@ -1,191 +0,0 @@
-# -*- 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_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'
-
-
-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
-
-
-@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
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/test_pipeline.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_pipeline.py b/shell/ext-py/sqlparse-0.1.14/tests/test_pipeline.py
deleted file mode 100644
index 3442a5b..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_pipeline.py
+++ /dev/null
@@ -1,70 +0,0 @@
-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))
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/test_regressions.py
----------------------------------------------------------------------
diff --git a/shell/ext-py/sqlparse-0.1.14/tests/test_regressions.py b/shell/ext-py/sqlparse-0.1.14/tests/test_regressions.py
deleted file mode 100644
index e30ddf0..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_regressions.py
+++ /dev/null
@@ -1,246 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import sys
-
-from tests.utils import TestCaseBase, load_file
-
-import sqlparse
-from sqlparse import sql
-from sqlparse import tokens as T
-
-
-class RegressionTests(TestCaseBase):
-
- def test_issue9(self):
- # make sure where doesn't consume parenthesis
- p = sqlparse.parse('(where 1)')[0]
- self.assert_(isinstance(p, sql.Statement))
- self.assertEqual(len(p.tokens), 1)
- self.assert_(isinstance(p.tokens[0], sql.Parenthesis))
- prt = p.tokens[0]
- self.assertEqual(len(prt.tokens), 3)
- self.assertEqual(prt.tokens[0].ttype, T.Punctuation)
- self.assertEqual(prt.tokens[-1].ttype, T.Punctuation)
-
- def test_issue13(self):
- parsed = sqlparse.parse(("select 'one';\n"
- "select 'two\\'';\n"
- "select 'three';"))
- self.assertEqual(len(parsed), 3)
- self.assertEqual(str(parsed[1]).strip(), "select 'two\\'';")
-
- def test_issue26(self):
- # parse stand-alone comments
- p = sqlparse.parse('--hello')[0]
- self.assertEqual(len(p.tokens), 1)
- self.assert_(p.tokens[0].ttype is T.Comment.Single)
- p = sqlparse.parse('-- hello')[0]
- self.assertEqual(len(p.tokens), 1)
- self.assert_(p.tokens[0].ttype is T.Comment.Single)
- p = sqlparse.parse('--hello\n')[0]
- self.assertEqual(len(p.tokens), 1)
- self.assert_(p.tokens[0].ttype is T.Comment.Single)
- p = sqlparse.parse('--')[0]
- self.assertEqual(len(p.tokens), 1)
- self.assert_(p.tokens[0].ttype is T.Comment.Single)
- p = sqlparse.parse('--\n')[0]
- self.assertEqual(len(p.tokens), 1)
- self.assert_(p.tokens[0].ttype is T.Comment.Single)
-
- def test_issue34(self):
- t = sqlparse.parse("create")[0].token_first()
- self.assertEqual(t.match(T.Keyword.DDL, "create"), True)
- self.assertEqual(t.match(T.Keyword.DDL, "CREATE"), True)
-
- def test_issue35(self):
- # missing space before LIMIT
- sql = sqlparse.format("select * from foo where bar = 1 limit 1",
- reindent=True)
- self.ndiffAssertEqual(sql, "\n".join(["select *",
- "from foo",
- "where bar = 1 limit 1"]))
-
- def test_issue38(self):
- sql = sqlparse.format("SELECT foo; -- comment",
- strip_comments=True)
- self.ndiffAssertEqual(sql, "SELECT foo;")
- sql = sqlparse.format("/* foo */", strip_comments=True)
- self.ndiffAssertEqual(sql, "")
-
- def test_issue39(self):
- p = sqlparse.parse('select user.id from user')[0]
- self.assertEqual(len(p.tokens), 7)
- idt = p.tokens[2]
- self.assertEqual(idt.__class__, sql.Identifier)
- self.assertEqual(len(idt.tokens), 3)
- self.assertEqual(idt.tokens[0].match(T.Name, 'user'), True)
- self.assertEqual(idt.tokens[1].match(T.Punctuation, '.'), True)
- self.assertEqual(idt.tokens[2].match(T.Name, 'id'), True)
-
- def test_issue40(self):
- # make sure identifier lists in subselects are grouped
- p = sqlparse.parse(('SELECT id, name FROM '
- '(SELECT id, name FROM bar) as foo'))[0]
- self.assertEqual(len(p.tokens), 7)
- self.assertEqual(p.tokens[2].__class__, sql.IdentifierList)
- self.assertEqual(p.tokens[-1].__class__, sql.Identifier)
- self.assertEqual(p.tokens[-1].get_name(), u'foo')
- sp = p.tokens[-1].tokens[0]
- self.assertEqual(sp.tokens[3].__class__, sql.IdentifierList)
- # make sure that formatting works as expected
- self.ndiffAssertEqual(
- sqlparse.format(('SELECT id, name FROM '
- '(SELECT id, name FROM bar)'),
- reindent=True),
- ('SELECT id,\n'
- ' name\n'
- 'FROM\n'
- ' (SELECT id,\n'
- ' name\n'
- ' FROM bar)'))
- self.ndiffAssertEqual(
- sqlparse.format(('SELECT id, name FROM '
- '(SELECT id, name FROM bar) as foo'),
- reindent=True),
- ('SELECT id,\n'
- ' name\n'
- 'FROM\n'
- ' (SELECT id,\n'
- ' name\n'
- ' FROM bar) as foo'))
-
-
-def test_issue78():
- # the bug author provided this nice examples, let's use them!
- def _get_identifier(sql):
- p = sqlparse.parse(sql)[0]
- return p.tokens[2]
- results = (('get_name', 'z'),
- ('get_real_name', 'y'),
- ('get_parent_name', 'x'),
- ('get_alias', 'z'),
- ('get_typecast', 'text'))
- variants = (
- 'select x.y::text as z from foo',
- 'select x.y::text as "z" from foo',
- 'select x."y"::text as z from foo',
- 'select x."y"::text as "z" from foo',
- 'select "x".y::text as z from foo',
- 'select "x".y::text as "z" from foo',
- 'select "x"."y"::text as z from foo',
- 'select "x"."y"::text as "z" from foo',
- )
- for variant in variants:
- i = _get_identifier(variant)
- assert isinstance(i, sql.Identifier)
- for func_name, result in results:
- func = getattr(i, func_name)
- assert func() == result
-
-
-def test_issue83():
- sql = """
-CREATE OR REPLACE FUNCTION func_a(text)
- RETURNS boolean LANGUAGE plpgsql STRICT IMMUTABLE AS
-$_$
-BEGIN
- ...
-END;
-$_$;
-
-CREATE OR REPLACE FUNCTION func_b(text)
- RETURNS boolean LANGUAGE plpgsql STRICT IMMUTABLE AS
-$_$
-BEGIN
- ...
-END;
-$_$;
-
-ALTER TABLE..... ;"""
- t = sqlparse.split(sql)
- assert len(t) == 3
-
-
-def test_comment_encoding_when_reindent():
- # There was an UnicodeEncodeError in the reindent filter that
- # casted every comment followed by a keyword to str.
- sql = u'select foo -- Comment containing Ümläuts\nfrom bar'
- formatted = sqlparse.format(sql, reindent=True)
- assert formatted == sql
-
-
-def test_parse_sql_with_binary():
- # See https://github.com/andialbrecht/sqlparse/pull/88
- digest = '\x82|\xcb\x0e\xea\x8aplL4\xa1h\x91\xf8N{'
- sql = 'select * from foo where bar = \'%s\'' % digest
- formatted = sqlparse.format(sql, reindent=True)
- tformatted = 'select *\nfrom foo\nwhere bar = \'%s\'' % digest
- if sys.version_info < (3,):
- tformatted = tformatted.decode('unicode-escape')
- assert formatted == tformatted
-
-
-def test_dont_alias_keywords():
- # The _group_left_right function had a bug where the check for the
- # left side wasn't handled correctly. In one case this resulted in
- # a keyword turning into an identifier.
- p = sqlparse.parse('FROM AS foo')[0]
- assert len(p.tokens) == 5
- assert p.tokens[0].ttype is T.Keyword
- assert p.tokens[2].ttype is T.Keyword
-
-
-def test_format_accepts_encoding(): # issue20
- sql = load_file('test_cp1251.sql', 'cp1251')
- formatted = sqlparse.format(sql, reindent=True, encoding='cp1251')
- if sys.version_info < (3,):
- tformatted = u'insert into foo\nvalues (1); -- Песня про надежду\n'
- else:
- tformatted = 'insert into foo\nvalues (1); -- Песня про надежду\n'
- assert formatted == tformatted
-
-
-def test_issue90():
- sql = ('UPDATE "gallery_photo" SET "owner_id" = 4018, "deleted_at" = NULL,'
- ' "width" = NULL, "height" = NULL, "rating_votes" = 0,'
- ' "rating_score" = 0, "thumbnail_width" = NULL,'
- ' "thumbnail_height" = NULL, "price" = 1, "description" = NULL')
- formatted = sqlparse.format(sql, reindent=True)
- tformatted = '\n'.join(['UPDATE "gallery_photo"',
- 'SET "owner_id" = 4018,',
- ' "deleted_at" = NULL,',
- ' "width" = NULL,',
- ' "height" = NULL,',
- ' "rating_votes" = 0,',
- ' "rating_score" = 0,',
- ' "thumbnail_width" = NULL,',
- ' "thumbnail_height" = NULL,',
- ' "price" = 1,',
- ' "description" = NULL'])
- assert formatted == tformatted
-
-
-def test_except_formatting():
- sql = 'SELECT 1 FROM foo WHERE 2 = 3 EXCEPT SELECT 2 FROM bar WHERE 1 = 2'
- formatted = sqlparse.format(sql, reindent=True)
- tformatted = '\n'.join([
- 'SELECT 1',
- 'FROM foo',
- 'WHERE 2 = 3',
- 'EXCEPT',
- 'SELECT 2',
- 'FROM bar',
- 'WHERE 1 = 2'
- ])
- assert formatted == tformatted
-
-
-def test_null_with_as():
- sql = 'SELECT NULL AS c1, NULL AS c2 FROM t1'
- formatted = sqlparse.format(sql, reindent=True)
- tformatted = '\n'.join([
- 'SELECT NULL AS c1,',
- ' NULL AS c2',
- 'FROM t1'
- ])
- assert formatted == tformatted
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/impala/blob/49413d9c/shell/ext-py/sqlparse-0.1.14/tests/test_split.py
----------------------------------------------------------------------
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
deleted file mode 100644
index 54e8d04..0000000
--- a/shell/ext-py/sqlparse-0.1.14/tests/test_split.py
+++ /dev/null
@@ -1,144 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Tests splitting functions.
-
-import unittest
-
-from tests.utils import load_file, TestCaseBase
-
-import sqlparse
-
-
-class SQLSplitTest(TestCaseBase):
- """Tests sqlparse.sqlsplit()."""
-
- _sql1 = 'select * from foo;'
- _sql2 = 'select * from bar;'
-
- def test_split_semicolon(self):
- sql2 = 'select * from foo where bar = \'foo;bar\';'
- stmts = sqlparse.parse(''.join([self._sql1, sql2]))
- self.assertEqual(len(stmts), 2)
- 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)
- self.assertEqual(len(stmts), 1)
- self.ndiffAssertEqual(unicode(stmts[0]), sql)
-
- def test_create_function_psql(self):
- sql = load_file('function_psql.sql')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 1)
- self.ndiffAssertEqual(unicode(stmts[0]), sql)
-
- def test_create_function_psql3(self):
- sql = load_file('function_psql3.sql')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 1)
- self.ndiffAssertEqual(unicode(stmts[0]), sql)
-
- def test_create_function_psql2(self):
- sql = load_file('function_psql2.sql')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 1)
- self.ndiffAssertEqual(unicode(stmts[0]), sql)
-
- def test_dashcomments(self):
- sql = load_file('dashcomment.sql')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 3)
- self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
-
- def test_dashcomments_eol(self):
- stmts = sqlparse.parse('select foo; -- comment\n')
- self.assertEqual(len(stmts), 1)
- stmts = sqlparse.parse('select foo; -- comment\r')
- self.assertEqual(len(stmts), 1)
- stmts = sqlparse.parse('select foo; -- comment\r\n')
- self.assertEqual(len(stmts), 1)
- stmts = sqlparse.parse('select foo; -- comment')
- self.assertEqual(len(stmts), 1)
-
- def test_begintag(self):
- sql = load_file('begintag.sql')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 3)
- self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
-
- def test_begintag_2(self):
- sql = load_file('begintag_2.sql')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 1)
- self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
-
- def test_dropif(self):
- sql = 'DROP TABLE IF EXISTS FOO;\n\nSELECT * FROM BAR;'
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 2)
- self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
-
- def test_comment_with_umlaut(self):
- sql = (u'select * from foo;\n'
- u'-- Testing an umlaut: ä\n'
- u'select * from bar;')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 2)
- self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
-
- def test_comment_end_of_line(self):
- sql = ('select * from foo; -- foo\n'
- 'select * from bar;')
- stmts = sqlparse.parse(sql)
- self.assertEqual(len(stmts), 2)
- self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
- # make sure the comment belongs to first query
- self.ndiffAssertEqual(unicode(stmts[0]), 'select * from foo; -- foo\n')
-
- def test_casewhen(self):
- sql = ('SELECT case when val = 1 then 2 else null end as foo;\n'
- 'comment on table actor is \'The actor table.\';')
- stmts = sqlparse.split(sql)
- self.assertEqual(len(stmts), 2)
-
- def test_cursor_declare(self):
- sql = ('DECLARE CURSOR "foo" AS SELECT 1;\n'
- 'SELECT 2;')
- stmts = sqlparse.split(sql)
- self.assertEqual(len(stmts), 2)
-
- def test_if_function(self): # see issue 33
- # don't let IF as a function confuse the splitter
- sql = ('CREATE TEMPORARY TABLE tmp '
- 'SELECT IF(a=1, a, b) AS o FROM one; '
- 'SELECT t FROM two')
- stmts = sqlparse.split(sql)
- self.assertEqual(len(stmts), 2)
-
- def test_split_stream(self):
- import types
- from cStringIO import StringIO
-
- stream = StringIO("SELECT 1; SELECT 2;")
- stmts = sqlparse.parsestream(stream)
- self.assertEqual(type(stmts), types.GeneratorType)
- self.assertEqual(len(list(stmts)), 2)
-
- def test_encoding_parsestream(self):
- from cStringIO import StringIO
- stream = StringIO("SELECT 1; SELECT 2;")
- stmts = list(sqlparse.parsestream(stream))
- self.assertEqual(type(stmts[0].tokens[0].value), unicode)
-
-
-def test_split_simple():
- stmts = sqlparse.split('select * from foo; select * from bar;')
- assert len(stmts) == 2
- assert stmts[0] == 'select * from foo;'
- assert stmts[1] == 'select * from bar;'