private void setUseNewAPI ( ) throws IOException { int numReduces = conf . getNumReduceTasks ( ) ; String oldMapperClass = "mapred.mapper.class" ; String oldReduceClass = "mapred.reducer.class" ; conf . setBooleanIfUnset ( "mapred.mapper.new-api" , conf . get ( oldMapperClass ) == null ) ; if ( conf . getUseNewMapper ( ) ) { String mode = "new map API" ; ensureNotSet ( "mapred.input.format.class" , mode ) ; ensureNotSet ( oldMapperClass , mode ) ; if ( numReduces != 0 ) { ensureNotSet ( "mapred.partitioner.class" , mode ) ; } else { ensureNotSet ( "mapred.output.format.class" , mode ) ; } } else { String mode = "map compatability" ; ensureNotSet ( JobContext . INPUT_FORMAT_CLASS_ATTR , mode ) ; ensureNotSet ( JobContext . MAP_CLASS_ATTR , mode ) ; if ( numReduces != 0 ) { ensureNotSet ( JobContext . PARTITIONER_CLASS_ATTR , mode ) ; } else { ensureNotSet ( JobContext . OUTPUT_FORMAT_CLASS_ATTR , mode ) ; } } if ( numReduces != 0 ) { conf . setBooleanIfUnset ( "mapred.reducer.new-api" , conf . get ( oldReduceClass ) == null ) ; if ( conf . getUseNewReducer ( ) ) { String mode = "new reduce API" ; ensureNotSet ( "mapred.output.format.class" , mode ) ; ensureNotSet ( oldReduceClass , mode ) ; } else { String mode = "reduce compatability" ; ensureNotSet ( JobContext . OUTPUT_FORMAT_CLASS_ATTR , mode ) ; ensureNotSet ( JobContext . REDUCE_CLASS_ATTR , mode ) ; } } }
Default to the new APIs unless they are explicitly set or the old mapper or reduce attributes are used .