@ -101,10 +101,15 @@ def move (**args):
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    client       =  bq . Client . from_service_account_json ( private_key ) 
 
					 
					 
					 
					    client       =  bq . Client . from_service_account_json ( private_key ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    config       =  Utils . get . config ( * * args ) 
 
					 
					 
					 
					    config       =  Utils . get . config ( * * args ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    dataset      =  args [ ' dataset ' ] 
 
					 
					 
					 
					    dataset      =  args [ ' dataset ' ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    SQL          =  [  ' ' . join ( [ " SELECT * FROM io. " , item [ ' context ' ] , ' _full_io ' ] )  for  item  in  config ] 
 
					 
					 
					 
					    if  ' contexts '  in  args  : 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    SQL          + =  [ Utils . get . sql ( * * args ) ] 
 
					 
					 
					 
					        SQL          =  [  ' ' . join ( [ " SELECT * FROM io. " , item [ ' context ' ] , ' _full_io ' ] )  for  item  in  config ] 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    SQL          =   ( ' \n  UNION ALL  \n ' . join ( SQL ) . replace ( ' :dataset ' , ' io ' ) ) 
 
					 
					 
					 
					        SQL          + =  [ Utils . get . sql ( * * args ) ] 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					        SQL          =   ( ' \n  UNION ALL  \n ' . join ( SQL ) . replace ( ' :dataset ' , ' io ' ) ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					    else : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        # 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        # moving a table to a designated location 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        tablename  =  args [ ' from ' ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        SQL  =  " SELECT * FROM :dataset.:table " . replace ( " :dataset " , dataset ) . replace ( " :table " , tablename ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # 
 
					 
					 
					 
					    # 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # At this point we have gathered all the tables in the io folder and we should now see if we need to merge with the remainder from the original table 
 
					 
					 
					 
					    # At this point we have gathered all the tables in the io folder and we should now see if we need to merge with the remainder from the original table 
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -128,7 +133,7 @@ def move (**args):
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    # print (SQL) 
 
					 
					 
					 
					    # print (SQL) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    out  =  client . query ( SQL , location = ' US ' , job_config = config ) 
 
					 
					 
					 
					    out  =  client . query ( SQL , location = ' US ' , job_config = config ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    print  ( ) 
 
					 
					 
					 
					    print  ( ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    print   ( out . job_id ) 
 
					 
					 
					 
					    return   ( out . job_id ) 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					    
 
					 
					 
					 
					    
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    
 
					 
					 
					 
					    
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -154,11 +159,24 @@ if __name__ == '__main__' :
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        finalize  - - < move | stats >  - - contexts  < c1 , c2 , . . . c3 >  - - from  < table > 
 
					 
					 
					 
					        finalize  - - < move | stats >  - - contexts  < c1 , c2 , . . . c3 >  - - from  < table > 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    """ 
 
					 
					 
					 
					    """ 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    if  ' move '  in  SYS_ARGS  : 
 
					 
					 
					 
					    if  ' move '  in  SYS_ARGS  : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        table  =  SYS_ARGS [ ' from ' ] 
 
					 
					 
					 
					        # table = SYS_ARGS['from'] 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        contexts  =  [ item [ ' context ' ]  for  item  in  config [ ' pipeline ' ]  if  item [ ' from ' ]  ==  SYS_ARGS [ ' from ' ] ] 
 
					 
					 
					 
					        # args = dict(config,**{"private_key":"../curation-prod.json"}) 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        args  =  dict ( config , * * { " private_key " : " ../curation-prod.json " } ) 
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        args  =  dict ( args , * * SYS_ARGS )         
 
					 
					 
					 
					        args  =  dict ( args , * * SYS_ARGS )         
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        args [ ' contexts ' ]  =  contexts 
 
					 
					 
					 
					        contexts  =  [ item [ ' context ' ]  for  item  in  config [ ' pipeline ' ]  if  item [ ' from ' ]  ==  SYS_ARGS [ ' from ' ] ] 
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					        move ( * * args ) 
 
					 
					 
					 
					        log  =  [ ] 
 
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        if  contexts  : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            args [ ' contexts ' ]  =  contexts 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            log  =  move ( * * args ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        else : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            tables  =  args [ ' from ' ] . split ( ' , ' ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					            for  name  in  tables  : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                name  =  name . strip ( ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                args [ ' from ' ]  =  name 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					                log  + =  [ move ( * * args ) ] 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        print  ( " \n " . join ( log ) ) 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					        
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    else : 
 
					 
					 
					 
					    else : 
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        print  ( " NOT YET READY ! " ) 
 
					 
					 
					 
					        print  ( " NOT YET READY ! " )