Search in sources :

Example 11 with Dataset

use of io.cdap.cdap.api.dataset.Dataset 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);
            }
        }
    };
}
Also used : Dataset(io.cdap.cdap.api.dataset.Dataset) IOException(java.io.IOException) CloseableBatchWritable(io.cdap.cdap.internal.app.runtime.batch.dataset.CloseableBatchWritable) 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) CloseableBatchWritable(io.cdap.cdap.internal.app.runtime.batch.dataset.CloseableBatchWritable) BatchWritable(io.cdap.cdap.api.data.batch.BatchWritable)

Example 12 with Dataset

use of io.cdap.cdap.api.dataset.Dataset in project cdap by cdapio.

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);
            }
        }
    };
}
Also used : Dataset(io.cdap.cdap.api.dataset.Dataset) IOException(java.io.IOException) CloseableBatchWritable(io.cdap.cdap.internal.app.runtime.batch.dataset.CloseableBatchWritable) 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) CloseableBatchWritable(io.cdap.cdap.internal.app.runtime.batch.dataset.CloseableBatchWritable) BatchWritable(io.cdap.cdap.api.data.batch.BatchWritable)

Example 13 with Dataset

use of io.cdap.cdap.api.dataset.Dataset in project cdap by cdapio.

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)

Example 14 with Dataset

use of io.cdap.cdap.api.dataset.Dataset in project cdap by cdapio.

the class Outputs method transform.

public static ProvidedOutput transform(Output.DatasetOutput datasetOutput, AbstractContext abstractContext) {
    String datasetNamespace = datasetOutput.getNamespace();
    if (datasetNamespace == null) {
        datasetNamespace = abstractContext.getNamespace();
    }
    String datasetName = datasetOutput.getName();
    Map<String, String> args = datasetOutput.getArguments();
    Dataset dataset = abstractContext.getDataset(datasetNamespace, datasetName, args, AccessType.WRITE);
    DatasetOutputFormatProvider datasetOutputFormatProvider = new DatasetOutputFormatProvider(datasetNamespace, datasetName, args, dataset);
    return new ProvidedOutput(datasetOutput, datasetOutputFormatProvider);
}
Also used : Dataset(io.cdap.cdap.api.dataset.Dataset) DatasetOutputFormatProvider(io.cdap.cdap.internal.app.runtime.batch.dataset.DatasetOutputFormatProvider)

Example 15 with Dataset

use of io.cdap.cdap.api.dataset.Dataset in project cdap by cdapio.

the class SingleThreadDatasetCache method createDatasetInstance.

/**
 * Creates a new instance of a dataset based on the given information.
 */
private Dataset createDatasetInstance(DatasetCacheKey key, boolean recordLineage) {
    DatasetId datasetId = new DatasetId(key.getNamespace(), key.getName());
    Dataset dataset = instantiator.getDataset(datasetId, key.getArguments(), key.getAccessType());
    if (dataset instanceof MeteredDataset && metricsContext != null) {
        ((MeteredDataset) dataset).setMetricsCollector(metricsContext.childContext(Constants.Metrics.Tag.DATASET, key.getName()));
    }
    if (recordLineage) {
        instantiator.writeLineage(datasetId, key.getAccessType());
    }
    return dataset;
}
Also used : Dataset(io.cdap.cdap.api.dataset.Dataset) MeteredDataset(io.cdap.cdap.api.dataset.metrics.MeteredDataset) MeteredDataset(io.cdap.cdap.api.dataset.metrics.MeteredDataset) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Aggregations

Dataset (io.cdap.cdap.api.dataset.Dataset)40 IOException (java.io.IOException)20 DatasetInstantiationException (io.cdap.cdap.api.data.DatasetInstantiationException)10 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)10 SystemDatasetInstantiator (io.cdap.cdap.data.dataset.SystemDatasetInstantiator)8 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)8 UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)4 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)4 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)4 MeteredDataset (io.cdap.cdap.api.dataset.metrics.MeteredDataset)4 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)4 BadRequestException (io.cdap.cdap.common.BadRequestException)4 CustomDatasetApp (io.cdap.cdap.data2.dataset2.customds.CustomDatasetApp)4 CustomOperations (io.cdap.cdap.data2.dataset2.customds.CustomOperations)4 DefaultTopLevelExtendsDataset (io.cdap.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset)4 DelegatingDataset (io.cdap.cdap.data2.dataset2.customds.DelegatingDataset)4 TopLevelDataset (io.cdap.cdap.data2.dataset2.customds.TopLevelDataset)4 TopLevelDirectDataset (io.cdap.cdap.data2.dataset2.customds.TopLevelDirectDataset)4 TopLevelExtendsDataset (io.cdap.cdap.data2.dataset2.customds.TopLevelExtendsDataset)4 ByteCodeClassLoader (io.cdap.cdap.internal.asm.ByteCodeClassLoader)4