Search in sources :

Example 1 with ForwardingSplitReader

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);
                    }
                }
            };
        }
    };
}
Also used : ForwardingSplitReader(io.cdap.cdap.internal.app.runtime.batch.dataset.ForwardingSplitReader) Dataset(io.cdap.cdap.api.dataset.Dataset) BatchReadable(io.cdap.cdap.api.data.batch.BatchReadable) Split(io.cdap.cdap.api.data.batch.Split) FileNotFoundException(java.io.FileNotFoundException) DatasetInstantiationException(io.cdap.cdap.api.data.DatasetInstantiationException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException)

Aggregations

DatasetInstantiationException (io.cdap.cdap.api.data.DatasetInstantiationException)1 BatchReadable (io.cdap.cdap.api.data.batch.BatchReadable)1 Split (io.cdap.cdap.api.data.batch.Split)1 Dataset (io.cdap.cdap.api.dataset.Dataset)1 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)1 ForwardingSplitReader (io.cdap.cdap.internal.app.runtime.batch.dataset.ForwardingSplitReader)1 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1