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

Function strip_comments

shell/impala_shell/impala_shell.py:95–105  ·  view source on GitHub ↗

sqlparse default implementation of strip comments has a bad performance when parsing very large SQL due to the grouping. This is because the default implementation tries to format the SQL for pretty-printing. Impala shell use of strip comments is mostly for checking and not for altering the ac

(sql)

Source from the content-addressed store, hash-verified

93
94
95def strip_comments(sql):
96 """sqlparse default implementation of strip comments has a bad performance when parsing
97 very large SQL due to the grouping. This is because the default implementation tries to
98 format the SQL for pretty-printing. Impala shell use of strip comments is mostly for
99 checking and not for altering the actual SQL, so having a pretty-formatted SQL is
100 irrelevant in Impala shell. Removing the grouping gives a significant performance boost.
101 """
102 stack = sqlparse.engine.FilterStack()
103 stack.stmtprocess.append(sqlparse.filters.StripCommentsFilter())
104 stack.postprocess.append(sqlparse.filters.SerializerUnicode())
105 return ''.join(stack.run(sql, 'utf-8')).strip()
106
107
108class CmdStatus:

Callers 2

_cmd_ends_with_delimMethod · 0.85
parse_query_textFunction · 0.85

Calls 3

appendMethod · 0.45
joinMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected