Search in sources :

Example 31 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class RemoteDatasetOpExecutor method create.

@Override
public DatasetSpecification create(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props) throws Exception {
    InternalDatasetCreationParams creationParams = new InternalDatasetCreationParams(typeMeta, props);
    HttpResponse response = doRequest(datasetInstanceId, "create", GSON.toJson(creationParams));
    return ObjectResponse.fromJsonBody(response, DatasetSpecification.class).getResponseObject();
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) HttpResponse(co.cask.common.http.HttpResponse)

Example 32 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class CubeDatasetAdmin method update.

@Override
public void update(DatasetSpecification oldSpec) throws IOException {
    // update all existing resolution tables, create all new resolutions
    for (Map.Entry<String, DatasetSpecification> entry : spec.getSpecifications().entrySet()) {
        DatasetSpecification oldSubSpec = spec.getSpecification(entry.getKey());
        DatasetAdmin subAdmin = delegates.get(entry.getKey());
        if (oldSubSpec != null && subAdmin instanceof Updatable) {
            ((Updatable) subAdmin).update(oldSubSpec);
        } else if (oldSubSpec == null) {
            subAdmin.create();
        }
    }
// TODO (CDAP-6342) delete all resolutions that were removed as part of the update
}
Also used : Updatable(co.cask.cdap.api.dataset.Updatable) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) CompositeDatasetAdmin(co.cask.cdap.api.dataset.lib.CompositeDatasetAdmin) Map(java.util.Map)

Example 33 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class DatasetSerDe method getDatasetSchema.

private void getDatasetSchema(Configuration conf, DatasetId datasetId) throws SerDeException {
    try (ContextManager.Context hiveContext = ContextManager.getContext(conf)) {
        // Because it calls initialize just to get the object inspector
        if (hiveContext == null) {
            LOG.info("Hive provided a null conf, will not be able to get dataset schema.");
            return;
        }
        // some datasets like Table and ObjectMappedTable have schema in the dataset properties
        try {
            DatasetSpecification datasetSpec = hiveContext.getDatasetSpec(datasetId);
            String schemaStr = datasetSpec.getProperty("schema");
            if (schemaStr != null) {
                schema = Schema.parseJson(schemaStr);
                return;
            }
        } catch (DatasetManagementException | ServiceUnavailableException e) {
            throw new SerDeException("Could not instantiate dataset " + datasetId, e);
        } catch (IOException e) {
            throw new SerDeException("Exception getting schema for dataset " + datasetId, e);
        }
        // other datasets must be instantiated to get their schema
        // conf is null if this is a query that writes to a dataset
        ClassLoader parentClassLoader = conf == null ? null : conf.getClassLoader();
        try (SystemDatasetInstantiator datasetInstantiator = hiveContext.createDatasetInstantiator(parentClassLoader)) {
            Dataset dataset = datasetInstantiator.getDataset(datasetId);
            if (dataset == null) {
                throw new SerDeException("Could not find dataset " + datasetId);
            }
            Type recordType;
            if (dataset instanceof RecordScannable) {
                recordType = ((RecordScannable) dataset).getRecordType();
            } else if (dataset instanceof RecordWritable) {
                recordType = ((RecordWritable) dataset).getRecordType();
            } else {
                throw new SerDeException("Dataset " + datasetId + " is not explorable.");
            }
            schema = schemaGenerator.generate(recordType);
        } catch (UnsupportedTypeException e) {
            throw new SerDeException("Dataset " + datasetId + " has an unsupported schema.", e);
        } catch (IOException e) {
            throw new SerDeException("Exception while trying to instantiate dataset " + datasetId, e);
        }
    } catch (IOException e) {
        throw new SerDeException("Could not get hive context from configuration.", e);
    }
}
Also used : RecordWritable(co.cask.cdap.api.data.batch.RecordWritable) Dataset(co.cask.cdap.api.dataset.Dataset) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) IOException(java.io.IOException) RecordScannable(co.cask.cdap.api.data.batch.RecordScannable) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) Type(java.lang.reflect.Type) SystemDatasetInstantiator(co.cask.cdap.data.dataset.SystemDatasetInstantiator) ContextManager(co.cask.cdap.hive.context.ContextManager) UnsupportedTypeException(co.cask.cdap.api.data.schema.UnsupportedTypeException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 34 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class ExploreExecutorHttpHandler method disableDataset.

/**
 * Disable ad-hoc exploration of a dataset instance.
 */
@POST
@Path("datasets/{dataset}/disable")
public void disableDataset(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) {
    final DatasetId datasetId = new DatasetId(namespace, datasetName);
    DatasetSpecification datasetSpec = retrieveDatasetSpec(responder, datasetId);
    if (datasetSpec == null) {
        // this means the spec could not be retrieved and retrievedDatasetSpec() already responded
        return;
    }
    disableDataset(responder, datasetId, datasetSpec);
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 35 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class ExploreExecutorHttpHandler method enableDataset.

/**
 * Enable ad-hoc exploration of a dataset instance.
 */
@POST
@Path("datasets/{dataset}/enable")
public void enableDataset(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) {
    DatasetId datasetId = new DatasetId(namespace, datasetName);
    DatasetSpecification datasetSpec = retrieveDatasetSpec(responder, datasetId);
    if (datasetSpec == null) {
        // this means the spec could not be retrieved and retrievedDatasetSpec() already responded
        return;
    }
    enableDataset(responder, datasetId, datasetSpec, false);
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)72 DatasetId (co.cask.cdap.proto.id.DatasetId)21 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)17 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)15 Test (org.junit.Test)14 DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)11 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)10 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)9 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 AbstractDatasetDefinition (co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition)7 BadRequestException (co.cask.cdap.common.BadRequestException)7 IOException (java.io.IOException)7 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)6 Map (java.util.Map)6 DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)5 Reconfigurable (co.cask.cdap.api.dataset.Reconfigurable)4 Updatable (co.cask.cdap.api.dataset.Updatable)4