Created
May 16, 2017 07:08
-
-
Save rishibarve/8320684b372e830c0ddf367d996caf71 to your computer and use it in GitHub Desktop.
Remove comments in hive query (and optionally do clean formatting)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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