use of co.cask.cdap.internal.app.runtime.batch.dataset.CloseableBatchWritable in project cdap by caskdata.
the class BasicMapReduceTaskContext method getBatchWritable.
/**
* Returns a {@link CloseableBatchWritable} that writes data to the given dataset.
*/
<K, V> CloseableBatchWritable<K, V> getBatchWritable(String namespace, String datasetName, Map<String, String> datasetArgs) {
Dataset dataset = getDataset(namespace, datasetName, datasetArgs, AccessType.WRITE);
// Must be BatchWritable.
Preconditions.checkArgument(dataset instanceof BatchWritable, "Dataset '%s:%s' is not a BatchWritable.", namespace, datasetName);
@SuppressWarnings("unchecked") final BatchWritable<K, V> delegate = (BatchWritable<K, V>) dataset;
return new CloseableBatchWritable<K, V>() {
@Override
public void write(K k, V v) {
delegate.write(k, v);
}
@Override
public void close() throws IOException {
try {
flushOperations();
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, IOException.class);
throw new IOException(e);
}
}
};
}
Aggregations