Search in sources :

Example 41 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.

the class ExploreExecutorHttpHandler method disableDataset.

private void disableDataset(HttpResponder responder, final DatasetId datasetId, final DatasetSpecification spec) {
    try {
        QueryHandle handle = impersonator.doAs(datasetId, new Callable<QueryHandle>() {

            @Override
            public QueryHandle call() throws Exception {
                return exploreTableManager.disableDataset(datasetId, spec);
            }
        });
        JsonObject json = new JsonObject();
        json.addProperty("handle", handle.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json.toString());
    } catch (Throwable e) {
        LOG.error("Got exception while trying to disable explore on dataset {}", datasetId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : JsonObject(com.google.gson.JsonObject) 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)

Example 42 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.

the class ExploreQueryExecutorHttpHandler method closeQuery.

@DELETE
@Path("data/explore/queries/{id}")
public void closeQuery(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException, SQLException {
    try {
        final QueryHandle handle = QueryHandle.fromId(id);
        if (!handle.equals(QueryHandle.NO_OP)) {
            doAs(handle, new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    exploreService.close(handle);
                    return null;
                }
            });
        }
        responder.sendStatus(HttpResponseStatus.OK);
    } catch (IllegalArgumentException e) {
        LOG.debug("Got exception:", e);
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (HandleNotFoundException e) {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    }
}
Also used : HandleNotFoundException(io.cdap.cdap.explore.service.HandleNotFoundException) 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) DELETE(javax.ws.rs.DELETE)

Example 43 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.

the class AbstractExploreClient method getFutureResultsFromHandle.

/**
 * Create a {@link ListenableFuture} object by polling the Explore service using the
 * {@link ListenableFuture} containing a {@link QueryHandle}.
 */
private ListenableFuture<ExploreExecutionResult> getFutureResultsFromHandle(final ListenableFuture<QueryHandle> futureHandle) {
    final StatementExecutionFuture resultFuture = new StatementExecutionFuture(this, futureHandle);
    Futures.addCallback(futureHandle, new FutureCallback<QueryHandle>() {

        @Override
        public void onSuccess(final QueryHandle handle) {
            boolean mustCloseHandle;
            try {
                QueryStatus status = getStatus(handle);
                if (!status.getStatus().isDone()) {
                    final String userId = SecurityRequestContext.getUserId();
                    final String userIp = SecurityRequestContext.getUserIP();
                    executor.schedule(new Runnable() {

                        @Override
                        public void run() {
                            SecurityRequestContext.setUserId(userId);
                            SecurityRequestContext.setUserIP(userIp);
                            onSuccess(handle);
                        }
                    }, 300, TimeUnit.MILLISECONDS);
                    return;
                }
                if (QueryStatus.OpStatus.ERROR.equals(status.getStatus())) {
                    throw new SQLException(status.getErrorMessage(), status.getSqlState());
                }
                ExploreExecutionResult result = new ClientExploreExecutionResult(AbstractExploreClient.this, handle, status);
                mustCloseHandle = !resultFuture.set(result) || !status.hasResults();
            } catch (Exception e) {
                mustCloseHandle = true;
                resultFuture.setException(e);
            }
            if (mustCloseHandle) {
                try {
                    close(handle);
                } catch (Throwable t) {
                    LOG.warn("Failed to close handle {}", handle, t);
                }
            }
        }

        @Override
        public void onFailure(Throwable t) {
            resultFuture.setException(t);
        }
    }, executor);
    return resultFuture;
}
Also used : SQLException(java.sql.SQLException) QueryHandle(io.cdap.cdap.proto.QueryHandle) QueryStatus(io.cdap.cdap.proto.QueryStatus) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) ExploreException(io.cdap.cdap.explore.service.ExploreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) HandleNotFoundException(io.cdap.cdap.explore.service.HandleNotFoundException)

Example 44 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.

the class InMemoryExploreServiceTest method runCommand.

private static void runCommand(String namespace, String command, boolean expectedHasResult, List<ColumnDesc> expectedColumnDescs, List<QueryResult> expectedResults) throws Exception {
    QueryHandle handle = exploreService.execute(new NamespaceId(namespace), command);
    QueryStatus status = waitForCompletionStatus(handle);
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
    Assert.assertEquals(expectedHasResult, status.hasResults());
    Assert.assertEquals(expectedColumnDescs, exploreService.getResultSchema(handle));
    Assert.assertEquals(expectedResults.toString(), trimColumnValues(exploreService.nextResults(handle, 100)).toString());
    exploreService.close(handle);
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) QueryHandle(io.cdap.cdap.proto.QueryHandle) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 45 with QueryHandle

use of io.cdap.cdap.proto.QueryHandle in project cdap by caskdata.

the class BaseHiveExploreServiceTest method deleteNamespace.

/**
 * Delete a namespace because app fabric is not started in explore tests.
 */
protected static void deleteNamespace(NamespaceId namespaceId) throws Exception {
    namespacePathLocator.get(namespaceId).delete(true);
    if (!NamespaceId.DEFAULT.equals(namespaceId)) {
        QueryHandle handle = exploreService.deleteNamespace(namespaceId);
        waitForCompletionStatus(handle, 50, TimeUnit.MILLISECONDS, 40);
    }
    namespaceAdmin.delete(namespaceId);
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle)

Aggregations

QueryHandle (io.cdap.cdap.proto.QueryHandle)70 ExploreException (io.cdap.cdap.explore.service.ExploreException)40 SQLException (java.sql.SQLException)26 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)22 OperationHandle (org.apache.hive.service.cli.OperationHandle)22 SessionHandle (org.apache.hive.service.cli.SessionHandle)22 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)18 QueryStatus (io.cdap.cdap.proto.QueryStatus)16 Path (javax.ws.rs.Path)16 IOException (java.io.IOException)14 Callable (java.util.concurrent.Callable)10 POST (javax.ws.rs.POST)10 Test (org.junit.Test)10 JsonObject (com.google.gson.JsonObject)8 UnsupportedTypeException (io.cdap.cdap.api.data.schema.UnsupportedTypeException)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)6 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)6 BadRequestException (io.cdap.cdap.common.BadRequestException)6 ColumnDesc (io.cdap.cdap.proto.ColumnDesc)6 QueryResult (io.cdap.cdap.proto.QueryResult)6