Search in sources :

Example 36 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.

the class ExploreExecutorHttpHandler method updateDataset.

/**
 * Enable ad-hoc exploration of a dataset instance.
 */
@POST
@Path("datasets/{dataset}/update")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void updateDataset(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName) throws BadRequestException {
    final DatasetId datasetId = new DatasetId(namespace, datasetName);
    try {
        UpdateExploreParameters params = readUpdateParameters(request);
        final DatasetSpecification oldSpec = params.getOldSpec();
        final DatasetSpecification datasetSpec = params.getNewSpec();
        QueryHandle handle;
        if (oldSpec.equals(datasetSpec)) {
            handle = QueryHandle.NO_OP;
        } else {
            handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {

                @Override
                public QueryHandle call() throws Exception {
                    return exploreTableManager.updateDataset(datasetId, datasetSpec, oldSpec);
                }
            });
        }
        JsonObject json = new JsonObject();
        json.addProperty("handle", handle.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json.toString());
    } catch (IllegalArgumentException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (ExploreException e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error updating explore on dataset " + datasetId);
    } catch (SQLException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "SQL exception while trying to update explore on dataset " + datasetId);
    } catch (UnsupportedTypeException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "Schema for dataset " + datasetId + " is not supported for exploration: " + e.getMessage());
    } catch (Throwable e) {
        LOG.error("Got exception:", e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : UpdateExploreParameters(io.cdap.cdap.explore.client.UpdateExploreParameters) SQLException(java.sql.SQLException) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) JsonObject(com.google.gson.JsonObject) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) QueryHandle(io.cdap.cdap.proto.QueryHandle) Callable(java.util.concurrent.Callable) DatasetId(io.cdap.cdap.proto.id.DatasetId) ExploreException(io.cdap.cdap.explore.service.ExploreException) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 37 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.

the class ExploreExecutorHttpHandler method dropPartition.

// this should really be a DELETE request. However, the partition key must be passed in the body
// of the request, and that does not work with many HTTP clients, including Java's URLConnection.
@POST
@Path("datasets/{dataset}/deletePartition")
public void dropPartition(final FullHttpRequest request, final HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dataset") String datasetName, @HeaderParam(Constants.Security.Headers.PROGRAM_ID) String programId) throws Exception {
    final DatasetId datasetId = new DatasetId(namespace, datasetName);
    propagateUserId(request);
    impersonator.doAs(getEntityToImpersonate(datasetId, programId), new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            doPartitionOperation(request, responder, datasetId, new PartitionOperation() {

                @Override
                public QueryHandle submitOperation(PartitionKey partitionKey, Map<String, String> properties) throws ExploreException, SQLException {
                    return exploreTableManager.dropPartition(datasetId, properties, partitionKey);
                }
            });
            return null;
        }
    });
}
Also used : PartitionKey(io.cdap.cdap.api.dataset.lib.PartitionKey) Map(java.util.Map) ExploreException(io.cdap.cdap.explore.service.ExploreException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) SQLException(java.sql.SQLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) DatasetId(io.cdap.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 38 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.

the class ExploreHttpClient method doPartitionOperation.

private QueryHandle doPartitionOperation(DatasetId datasetId, DatasetSpecification spec, PartitionKey key, String endpoint, String operationName, Map<String, String> additionalArguments) throws ExploreException {
    Map<String, String> args = new HashMap<>(additionalArguments);
    PartitionedFileSetArguments.setOutputPartitionKey(args, key);
    String tableName = ExploreProperties.getExploreTableName(spec.getProperties());
    String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties());
    if (tableName != null) {
        args.put(ExploreProperties.PROPERTY_EXPLORE_TABLE_NAME, tableName);
    }
    if (databaseName != null) {
        args.put(ExploreProperties.PROPERTY_EXPLORE_DATABASE_NAME, databaseName);
    }
    HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/%s", datasetId.getNamespace(), datasetId.getEntityName(), endpoint), GSON.toJson(args), null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException(String.format("Cannot %s partition with key %s in dataset %s. Reason: %s", operationName, key, datasetId.toString(), response));
}
Also used : HashMap(java.util.HashMap) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 39 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.

the class ExploreHttpClient method getFunctions.

@Override
public QueryHandle getFunctions(@Nullable String catalog, @Nullable String schemaPattern, String functionNamePattern) throws ExploreException, SQLException {
    String body = GSON.toJson(new FunctionsArgs(catalog, schemaPattern, functionNamePattern));
    String resource = String.format("namespaces/%s/data/explore/jdbc/functions", schemaPattern);
    HttpResponse response = doPost(resource, body, null);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
    }
    throw new ExploreException("Cannot get the functions. Reason: " + response);
}
Also used : FunctionsArgs(io.cdap.cdap.explore.utils.FunctionsArgs) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 40 with ExploreException

use of io.cdap.cdap.explore.service.ExploreException in project cdap by cdapio.

the class ExploreHttpClient method getTableInfo.

@Override
public TableInfo getTableInfo(String namespace, @Nullable String databaseName, String table) throws ExploreException, TableNotFoundException {
    String url = String.format("namespaces/%s/data/explore/tables/%s/info", namespace, table);
    if (databaseName != null) {
        url += "?database=" + databaseName;
    }
    HttpResponse response = doGet(url);
    if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return parseJson(response, TableInfo.class);
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new TableNotFoundException(String.format("Namespace %s, table %s not found.", namespace, table));
    }
    throw new ExploreException(String.format("Cannot get the schema of namespace %s, table %s. Reason: %s", namespace, table, response));
}
Also used : TableNotFoundException(io.cdap.cdap.explore.service.TableNotFoundException) HttpResponse(io.cdap.common.http.HttpResponse) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Aggregations

ExploreException (io.cdap.cdap.explore.service.ExploreException)88 QueryHandle (io.cdap.cdap.proto.QueryHandle)34 SQLException (java.sql.SQLException)30 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)30 IOException (java.io.IOException)26 OperationHandle (org.apache.hive.service.cli.OperationHandle)24 SessionHandle (org.apache.hive.service.cli.SessionHandle)24 HttpResponse (io.cdap.common.http.HttpResponse)22 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)14 Path (javax.ws.rs.Path)14 UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)10 TableNotFoundException (io.cdap.cdap.explore.service.TableNotFoundException)10 POST (javax.ws.rs.POST)10 TException (org.apache.thrift.TException)10 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)8 BadRequestException (io.cdap.cdap.common.BadRequestException)8 DatasetId (io.cdap.cdap.proto.id.DatasetId)8 FileNotFoundException (java.io.FileNotFoundException)8 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)8