MCPcopy Create free account
hub / github.com/apache/impala / parse_query_text

Function parse_query_text

shell/impala_shell/impala_shell.py:2047–2065  ·  view source on GitHub ↗

Parse query file text to extract queries

(query_text)

Source from the content-addressed store, hash-verified

2045
2046
2047def parse_query_text(query_text):
2048 """Parse query file text to extract queries"""
2049 query_list = sqlparse.split(query_text)
2050 # Remove trailing comments in the input, if any. We do this because sqlparse splits the
2051 # input at query boundaries and associates the query only with preceding comments
2052 # (following comments are associated with the next query). This is a problem with
2053 # trailing comments. For example, consider the following input:
2054 # -------------
2055 # -- comment1
2056 # select 1;
2057 # -- comment2
2058 # -------------
2059 # When sqlparse splits the query, "comment1" is associated with the query "select 1" and
2060 # "--comment2" is sent as is. Impala's parser however doesn't consider it a valid SQL
2061 # and throws an exception. We identify such trailing comments and ignore them (do not
2062 # send them to Impala).
2063 if query_list and not strip_comments(query_list[-1]).strip("\n"):
2064 query_list.pop()
2065 return query_list
2066
2067
2068def parse_variables(keyvals):

Callers 2

do_sourceMethod · 0.85

Calls 1

strip_commentsFunction · 0.85

Tested by

no test coverage detected