/** * * Gets the record writer from job's output format. Job's output format should * be a FileOutputFormat.If the record writer implements Syncable then returns * the current position as a value that may be passed to DataFileReader.seek(long) * otherwise returns -1. * Forces the end of the current block, emitting a synchronization marker. * * @param namedOutput the namedOutput * @param baseOutputPath base-output path to write the record to. Note: Framework will * generate unique filename for the baseOutputPath */ @SuppressWarnings("unchecked") public long sync(String namedOutput, String baseOutputPath) throws IOException, InterruptedException { checkNamedOutputName(context, namedOutput, false); checkBaseOutputPath(baseOutputPath); if (!namedOutputs.contains(namedOutput)) { throw new IllegalArgumentException("Undefined named output '" + namedOutput + "'"); } TaskAttemptContext taskContext = getContext(namedOutput); RecordWriter recordWriter = getRecordWriter(taskContext, baseOutputPath); long position = -1; if (recordWriter instanceof Syncable) { Syncable syncableWriter = (Syncable) recordWriter; position = syncableWriter.sync(); } return position; } // by being synchronized MultipleOutputTask can be use with a
/** * * Gets the record writer from job's output format. Job's output format should * be a FileOutputFormat.If the record writer implements Syncable then returns * the current position as a value that may be passed to DataFileReader.seek(long) * otherwise returns -1. * Forces the end of the current block, emitting a synchronization marker. * * @param namedOutput the namedOutput * @param baseOutputPath base-output path to write the record to. Note: Framework will * generate unique filename for the baseOutputPath */ @SuppressWarnings("unchecked") public long sync(String namedOutput, String baseOutputPath) throws IOException, InterruptedException { checkNamedOutputName(context, namedOutput, false); checkBaseOutputPath(baseOutputPath); if (!namedOutputs.contains(namedOutput)) { throw new IllegalArgumentException("Undefined named output '" + namedOutput + "'"); } TaskAttemptContext taskContext = getContext(namedOutput); RecordWriter recordWriter = getRecordWriter(taskContext, baseOutputPath); long position = -1; if (recordWriter instanceof Syncable) { Syncable syncableWriter = (Syncable) recordWriter; position = syncableWriter.sync(); } return position; } // by being synchronized MultipleOutputTask can be use with a