question: public static void mergeOutput ( String table , String tablePrefix , int numberOfPartitions , Connection connection ) { StringBuilder mergeOutputQuery = new StringBuilder ( ) ; mergeOutputQuery . append ( "INSERT INTO " ) ; mergeOutputQuery . append ( table ) ; for ( int i = 0 ; i < numberOfPartitions ; i ++ ) { mergeOutputQuery . append ( "\n" ) ; mergeOutputQuery . append ( "SELECT * FROM " ) ; mergeOutputQuery . append ( tablePrefix ) ; mergeOutputQuery . append ( table ) ; mergeOutputQuery . append ( "_" ) ; mergeOutputQuery . append ( i ) ; if ( i != numberOfPartitions - 1 ) { mergeOutputQuery . append ( "\n" ) ; mergeOutputQuery . append ( "UNION ALL" ) ; } } LOG . info ( "Merge output: " ) ; LOG . info ( mergeOutputQuery ) ; executeStatement ( mergeOutputQuery . toString ( ) , connection ) ; }
target:  Merges multiple temporary tables into the final output table, structure must be the same, uses "UNION ALL" for merging.