Search in sources :

Example 6 with ExploreException

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

the class ExploreQueryExecutorHttpHandler method downloadQueryResults.

@POST
@Path("data/explore/queries/{id}/download")
public void downloadQueryResults(HttpRequest request, final HttpResponder responder, @PathParam("id") final String id) throws ExploreException, IOException, SQLException, HandleNotFoundException {
    // NOTE: this call is a POST because it is not idempotent: cursor of results is moved
    final QueryHandle handle = QueryHandle.fromId(id);
    doAs(handle, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            doDownloadQueryResults(responder, handle);
            return null;
        }
    });
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle) ExploreException(io.cdap.cdap.explore.service.ExploreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) HandleNotFoundException(io.cdap.cdap.explore.service.HandleNotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 7 with ExploreException

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

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) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) 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 8 with ExploreException

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

the class ExploreExecutorHttpHandler method enableDataset.

private void enableDataset(HttpResponder responder, final DatasetId datasetId, final DatasetSpecification datasetSpec, final boolean truncating) {
    LOG.debug("Enabling explore for dataset instance {}", datasetId);
    try {
        QueryHandle handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {

            @Override
            public QueryHandle call() throws Exception {
                return exploreTableManager.enableDataset(datasetId, datasetSpec, truncating);
            }
        });
        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 enabling explore on dataset " + datasetId);
    } catch (SQLException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "SQL exception while trying to enable 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 : SQLException(java.sql.SQLException) JsonObject(com.google.gson.JsonObject) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) QueryHandle(io.cdap.cdap.proto.QueryHandle) ExploreException(io.cdap.cdap.explore.service.ExploreException) UnsupportedTypeException(io.cdap.cdap.api.data.schema.UnsupportedTypeException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) 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) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Example 9 with ExploreException

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

the class ExploreExecutorHttpHandler method addPartition.

@POST
@Path("datasets/{dataset}/partitions")
public void addPartition(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 {
                    String fsPath = properties.get("path");
                    if (fsPath == null) {
                        responder.sendString(HttpResponseStatus.BAD_REQUEST, "path was not specified.");
                        return null;
                    }
                    return exploreTableManager.addPartition(datasetId, properties, partitionKey, fsPath);
                }
            });
            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) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) 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 10 with ExploreException

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

the class BaseHiveExploreService method getFunctions.

@Override
public QueryHandle getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws ExploreException, SQLException {
    startAndWait();
    try {
        SessionHandle sessionHandle = null;
        OperationHandle operationHandle = null;
        Map<String, String> sessionConf = startSession();
        String database = getHiveDatabase(schemaPattern);
        try {
            sessionHandle = openHiveSession(sessionConf);
            operationHandle = cliService.getFunctions(sessionHandle, catalog, database, functionNamePattern);
            QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", database);
            LOG.trace("Retrieving functions: catalog {}, schema {}, function {}", catalog, database, functionNamePattern);
            return handle;
        } catch (Throwable e) {
            closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
            throw e;
        }
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    } catch (Throwable e) {
        throw new ExploreException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryHandle(io.cdap.cdap.proto.QueryHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) ExploreException(io.cdap.cdap.explore.service.ExploreException)

Aggregations

ExploreException (io.cdap.cdap.explore.service.ExploreException)86 QueryHandle (io.cdap.cdap.proto.QueryHandle)32 SQLException (java.sql.SQLException)28 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)28 IOException (java.io.IOException)24 OperationHandle (org.apache.hive.service.cli.OperationHandle)24 SessionHandle (org.apache.hive.service.cli.SessionHandle)24 HttpResponse (io.cdap.common.http.HttpResponse)22 Path (javax.ws.rs.Path)14 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)12 UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)10 POST (javax.ws.rs.POST)10 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)8 BadRequestException (io.cdap.cdap.common.BadRequestException)8 TableNotFoundException (io.cdap.cdap.explore.service.TableNotFoundException)8 DatasetId (io.cdap.cdap.proto.id.DatasetId)8 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)8 TException (org.apache.thrift.TException)8 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)6