public static String generateTableCopy ( String inputTblName , String outputTblName , String inputDbName , String outputDbName , Optional < Map < String , String > > optionalPartitionDMLInfo ) { Preconditions . checkArgument ( StringUtils . isNotBlank ( inputTblName ) ) ; Preconditions . checkArgument ( StringUtils . isNotBlank ( outputTblName ) ) ; Preconditions . checkArgument ( StringUtils . isNotBlank ( inputDbName ) ) ; Preconditions . checkArgument ( StringUtils . isNotBlank ( outputDbName ) ) ; StringBuilder dmlQuery = new StringBuilder ( ) ; // Insert query dmlQuery . append ( String . format ( "INSERT OVERWRITE TABLE `%s`.`%s` %n" , outputDbName , outputTblName ) ) ; if ( optionalPartitionDMLInfo . isPresent ( ) && optionalPartitionDMLInfo . get ( ) . size ( ) > 0 ) { // Partition details dmlQuery . append ( partitionKeyValues ( optionalPartitionDMLInfo ) ) ; } dmlQuery . append ( String . format ( "SELECT * FROM `%s`.`%s`" , inputDbName , inputTblName ) ) ; if ( optionalPartitionDMLInfo . isPresent ( ) ) { if ( optionalPartitionDMLInfo . get ( ) . size ( ) > 0 ) { dmlQuery . append ( " WHERE " ) ; String partitionsAndValues = optionalPartitionDMLInfo . get ( ) . entrySet ( ) . stream ( ) . map ( e -> "`" + e . getKey ( ) + "`='" + e . getValue ( ) + "'" ) . collect ( joining ( " AND " ) ) ; dmlQuery . append ( partitionsAndValues ) ; } } return dmlQuery . toString ( ) ; }
Fills data from input table into output table .