use of io.cdap.cdap.internal.app.runtime.batch.dataset.ForwardingSplitReader in project cdap by caskdata.
the class BasicMapReduceTaskContext method getBatchReadable.
/**
* Returns a {@link BatchReadable} that reads data from the given dataset.
*/
<K, V> BatchReadable<K, V> getBatchReadable(@Nullable String datasetNamespace, String datasetName, Map<String, String> datasetArgs) {
Dataset dataset;
if (datasetNamespace == null) {
dataset = getDataset(datasetName, datasetArgs, AccessType.READ);
} else {
dataset = getDataset(datasetNamespace, datasetName, datasetArgs, AccessType.READ);
}
// Must be BatchReadable.
Preconditions.checkArgument(dataset instanceof BatchReadable, "Dataset '%s' is not a BatchReadable.", datasetName);
@SuppressWarnings("unchecked") final BatchReadable<K, V> delegate = (BatchReadable<K, V>) dataset;
return new BatchReadable<K, V>() {
@Override
public List<Split> getSplits() {
try {
try {
return delegate.getSplits();
} finally {
flushOperations();
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@Override
public SplitReader<K, V> createSplitReader(Split split) {
return new ForwardingSplitReader<K, V>(delegate.createSplitReader(split)) {
@Override
public void close() {
try {
try {
super.close();
} finally {
flushOperations();
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
};
}
};
}
Aggregations