Parse query file text to extract queries
(query_text)
| 2045 | |
| 2046 | |
| 2047 | def 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 | |
| 2068 | def parse_variables(keyvals): |
no test coverage detected