Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rishibarve/8320684b372e830c0ddf367d996caf71 to your computer and use it in GitHub Desktop.
Save rishibarve/8320684b372e830c0ddf367d996caf71 to your computer and use it in GitHub Desktop.
Remove comments in hive query (and optionally do clean formatting)
#Requires sqlparse library to be installed
import sqlparse
def remove_hive_comments( query, format = False):
if format is True:
qry = sqlparse.format(query, reindent=True)
new_qry = '''
'''
for line in iter(qry.splitlines()):
index = line.find('--')
line1 = line
if index is not -1:
line1 = line[0:index]
new_qry = new_qry + line1 + '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment