Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def change_table_location(**kwargs):
- cur = hive.Connection(host='hiveserver.oyorooms.io', port=10000, username='hadoop', password=Variable.get('hive_pass'), auth='CUSTOM').cursor()
- db, table = kwargs['db'], kwargs['table']
- cur.execute("show create table {db}.{table}".format(**locals()))
- location=""
- for row in cur.fetchall():
- if 'hdfs' in row[0]:
- location = str(row[0].strip())[1:-1]
- if location is not None:
- if location[-2:] == '-1' or location[-2:] == '-2':
- temp_location = location[:-2]
- commands.getstatusoutput("ssh -i /home/airflowclient/DataPlatform.pem hadoop@dp-emr.oyorooms.io \"hdfs dfs -cp {location} {temp_location}\"".format(**locals()))
- cur.execute('alter table {db}.{table} set location "{temp_location}"'.format(**locals()))
- commands.getstatusoutput("ssh -i /home/airflowclient/DataPlatform.pem hadoop@dp-emr.oyorooms.io \"hdfs dfs -rm -r {location}\"".format(**locals()))
- location=temp_location
- if location[-1] != '1':
- new_location=location+str(1)
- commands.getstatusoutput("ssh -i /home/airflowclient/DataPlatform.pem hadoop@dp-emr.oyorooms.io \"hdfs dfs -cp {location} {new_location}\"".format(**locals()))
- cur.execute('alter table {db}.{table} set location "{new_location}"'.format(**locals()))
Add Comment
Please, Sign In to add comment