VariableTable variables = new VariableTable(VariableTable.RedefineStrategy.IGNORE);
variables.defineVariables(arguments);
String path = variables.parse(rawBasePath, false);
String id = repository.getRelatedId(path);
OutputAttemptContext outputContext = HadoopDataSourceUtil.createContext(context, id);
DataFormat<? super T> format = ReflectionUtils.newInstance(dataFormatClass, context.getConfiguration());
DirectDataSource datasource = repository.getRelatedDataSource(path);
String basePath = repository.getComponentPath(path);
String unresolvedResourcePath = rawResourcePath.replaceAll(
Pattern.quote("*"),
String.format("%04d", context.getTaskAttemptID().getTaskID().getId()));
String resourcePath = variables.parse(unresolvedResourcePath);
DataDefinition<? super T> definition = SimpleDataDefinition.newInstance(dataType, format);
if (log.isDebugEnabled()) {
log.debug(MessageFormat.format(
"Open mapper output (id={0}, basePath={1}, resourcePath={2})",
id,
basePath,
resourcePath));
}
int records = 0;
ModelOutput<? super T> output = datasource.openOutput(
outputContext,
definition,
basePath,
resourcePath,
outputContext.getCounter());
try {
do {
output.write(context.getCurrentValue());
records++;
} while (context.nextKeyValue());
} finally {
if (log.isDebugEnabled()) {
log.debug(MessageFormat.format(
"Start cleanup directly output Mapper {0}@{1}",
getClass().getName(),
context.getTaskAttemptID()));
}
output.close();
}
org.apache.hadoop.mapreduce.Counter recordCounter = JobCompatibility.getTaskOutputRecordCounter(context);
recordCounter.increment(records);
context.getCounter(COUNTER_GROUP, id + ".files").increment(1);
context.getCounter(COUNTER_GROUP, id + ".records").increment(records);
context.getCounter(COUNTER_GROUP, id + ".size").increment(outputContext.getCounter().get());
}
}