Guest User

Untitled

a guest
Feb 4th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. def change_table_location(**kwargs):
  2.     cur = hive.Connection(host='hiveserver.oyorooms.io', port=10000, username='hadoop', password=Variable.get('hive_pass'), auth='CUSTOM').cursor()
  3.     db, table = kwargs['db'], kwargs['table']
  4.     cur.execute("show create table {db}.{table}".format(**locals()))
  5.     location=""
  6.     for row in cur.fetchall():
  7.         if 'hdfs' in row[0]:
  8.             location = str(row[0].strip())[1:-1]
  9.  
  10.     if location is not None:
  11.         if location[-2:] == '-1' or location[-2:] == '-2':
  12.             temp_location = location[:-2]
  13.             commands.getstatusoutput("ssh -i  /home/airflowclient/DataPlatform.pem hadoop@dp-emr.oyorooms.io \"hdfs dfs -cp {location} {temp_location}\"".format(**locals()))
  14.             cur.execute('alter table {db}.{table} set location "{temp_location}"'.format(**locals()))
  15.             commands.getstatusoutput("ssh -i  /home/airflowclient/DataPlatform.pem hadoop@dp-emr.oyorooms.io \"hdfs dfs -rm -r {location}\"".format(**locals()))
  16.             location=temp_location
  17.  
  18.         if location[-1] != '1':
  19.             new_location=location+str(1)
  20.             commands.getstatusoutput("ssh -i  /home/airflowclient/DataPlatform.pem hadoop@dp-emr.oyorooms.io \"hdfs dfs -cp {location} {new_location}\"".format(**locals()))
  21.             cur.execute('alter table {db}.{table} set location "{new_location}"'.format(**locals()))
Add Comment
Please, Sign In to add comment