mirror of
https://github.com/apache/impala.git
synced 2025-12-20 02:20:11 -05:00
sqlparse-0.1.19 is the last version of sqlparse that supports Python 2.6. Testing: - Ran all end-to-end tests Change-Id: Ide51ef3ac52d25a96b0fa832e29b6535197d23cb Reviewed-on: http://gerrit.cloudera.org:8080/10354 Reviewed-by: David Knupp <dknupp@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
45 lines
991 B
Python
45 lines
991 B
Python
'''
|
|
Created on 17/05/2012
|
|
|
|
@author: piranna
|
|
|
|
Several utility functions to extract info from the SQL sentences
|
|
'''
|
|
|
|
from sqlparse.filters import ColumnsSelect, Limit
|
|
from sqlparse.pipeline import Pipeline
|
|
from sqlparse.tokens import Keyword, Whitespace
|
|
|
|
|
|
def getlimit(stream):
|
|
"""Function that return the LIMIT of a input SQL """
|
|
pipe = Pipeline()
|
|
|
|
pipe.append(Limit())
|
|
|
|
result = pipe(stream)
|
|
try:
|
|
return int(result)
|
|
except ValueError:
|
|
return result
|
|
|
|
|
|
def getcolumns(stream):
|
|
"""Function that return the colums of a SELECT query"""
|
|
pipe = Pipeline()
|
|
|
|
pipe.append(ColumnsSelect())
|
|
|
|
return pipe(stream)
|
|
|
|
|
|
class IsType(object):
|
|
"""Functor that return is the statement is of a specific type"""
|
|
def __init__(self, type):
|
|
self.type = type
|
|
|
|
def __call__(self, stream):
|
|
for token_type, value in stream:
|
|
if token_type not in Whitespace:
|
|
return token_type in Keyword and value == self.type
|