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)
| 93 | |
| 94 | |
| 95 | def 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 | |
| 108 | class CmdStatus: |
no test coverage detected