Search in sources :

Example 1 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class ProfileResources method getQueryProfile.

private QueryProfile getQueryProfile(String queryId) {
    QueryId id = QueryIdHelper.getQueryIdFromString(queryId);
    // first check local running
    Foreman f = work.getBee().getForemanForQueryId(id);
    if (f != null) {
        QueryProfile queryProfile = f.getQueryManager().getQueryProfile();
        checkOrThrowProfileViewAuthorization(queryProfile);
        return queryProfile;
    }
    // then check remote running
    try {
        final TransientStore<QueryInfo> running = work.getContext().getProfileStoreContext().getRunningProfileStore();
        final QueryInfo info = running.get(queryId);
        if (info != null) {
            QueryProfile queryProfile = work.getContext().getController().getTunnel(info.getForeman()).requestQueryProfile(id).checkedGet(2, TimeUnit.SECONDS);
            checkOrThrowProfileViewAuthorization(queryProfile);
            return queryProfile;
        }
    } catch (Exception e) {
        logger.trace("Failed to find query as running profile.", e);
    }
    // then check blob store
    try {
        final PersistentStore<QueryProfile> profiles = work.getContext().getProfileStoreContext().getCompletedProfileStore();
        final QueryProfile queryProfile = profiles.get(queryId);
        if (queryProfile != null) {
            checkOrThrowProfileViewAuthorization(queryProfile);
            return queryProfile;
        }
    } catch (final Exception e) {
        throw new DrillRuntimeException("error while retrieving profile", e);
    }
    throw UserException.validationError().message("No profile with given query id '%s' exists. Please verify the query id.", queryId).build(logger);
}
Also used : QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Foreman(org.apache.drill.exec.work.foreman.Foreman) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 2 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class QueryWrapper method run.

public QueryResult run(final WorkManager workManager, final WebUserConnection webUserConnection) throws Exception {
    final RunQuery runQuery = RunQuery.newBuilder().setType(getType()).setPlan(getQuery()).setResultsMode(QueryResultsMode.STREAM_FULL).build();
    // Submit user query to Drillbit work queue.
    final QueryId queryId = workManager.getUserWorker().submitWork(webUserConnection, runQuery);
    // Wait until the query execution is complete or there is error submitting the query
    webUserConnection.await();
    if (logger.isTraceEnabled()) {
        logger.trace("Query {} is completed ", queryId);
    }
    if (webUserConnection.results.isEmpty()) {
        webUserConnection.results.add(Maps.<String, String>newHashMap());
    }
    // Return the QueryResult.
    return new QueryResult(webUserConnection.columns, webUserConnection.results);
}
Also used : RunQuery(org.apache.drill.exec.proto.UserProtos.RunQuery) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId)

Example 3 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class QueryResultHandler method batchArrived.

/**
   * Maps internal low-level API protocol to {@link UserResultsListener}-level API protocol.
   * handles query data messages
   */
public void batchArrived(ConnectionThrottle throttle, ByteBuf pBody, ByteBuf dBody) throws RpcException {
    final QueryData queryData = RpcBus.get(pBody, QueryData.PARSER);
    // Current batch coming in.
    final DrillBuf drillBuf = (DrillBuf) dBody;
    final QueryDataBatch batch = new QueryDataBatch(queryData, drillBuf);
    final QueryId queryId = queryData.getQueryId();
    if (logger.isDebugEnabled()) {
        logger.debug("batchArrived: queryId = {}", QueryIdHelper.getQueryId(queryId));
    }
    logger.trace("batchArrived: batch = {}", batch);
    final UserResultsListener resultsListener = newUserResultsListener(queryId);
    // A data case--pass on via dataArrived
    try {
        resultsListener.dataArrived(batch, throttle);
    // That releases batch if successful.
    } catch (Exception e) {
        batch.release();
        resultsListener.submissionFailed(UserException.systemError(e).build(logger));
    }
}
Also used : QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) DrillBuf(io.netty.buffer.DrillBuf)

Example 4 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class UserServerRequestHandler method handle.

@Override
public void handle(BitToUserConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender responseSender) throws RpcException {
    switch(rpcType) {
        case RpcType.RUN_QUERY_VALUE:
            logger.debug("Received query to run.  Returning query handle.");
            try {
                final RunQuery query = RunQuery.PARSER.parseFrom(new ByteBufInputStream(pBody));
                final QueryId queryId = worker.submitWork(connection, query);
                responseSender.send(new Response(RpcType.QUERY_HANDLE, queryId));
                break;
            } catch (InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding RunQuery body.", e);
            }
        case RpcType.CANCEL_QUERY_VALUE:
            try {
                final QueryId queryId = QueryId.PARSER.parseFrom(new ByteBufInputStream(pBody));
                final Ack ack = worker.cancelQuery(queryId);
                responseSender.send(new Response(RpcType.ACK, ack));
                break;
            } catch (InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding QueryId body.", e);
            }
        case RpcType.RESUME_PAUSED_QUERY_VALUE:
            try {
                final QueryId queryId = QueryId.PARSER.parseFrom(new ByteBufInputStream(pBody));
                final Ack ack = worker.resumeQuery(queryId);
                responseSender.send(new Response(RpcType.ACK, ack));
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding QueryId body.", e);
            }
        case RpcType.GET_QUERY_PLAN_FRAGMENTS_VALUE:
            try {
                final GetQueryPlanFragments req = GetQueryPlanFragments.PARSER.parseFrom(new ByteBufInputStream(pBody));
                responseSender.send(new Response(RpcType.QUERY_PLAN_FRAGMENTS, worker.getQueryPlan(connection, req)));
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding GetQueryPlanFragments body.", e);
            }
        case RpcType.GET_CATALOGS_VALUE:
            try {
                final GetCatalogsReq req = GetCatalogsReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
                worker.submitCatalogMetadataWork(connection.getSession(), req, responseSender);
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding GetCatalogsReq body.", e);
            }
        case RpcType.GET_SCHEMAS_VALUE:
            try {
                final GetSchemasReq req = GetSchemasReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
                worker.submitSchemasMetadataWork(connection.getSession(), req, responseSender);
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding GetSchemasReq body.", e);
            }
        case RpcType.GET_TABLES_VALUE:
            try {
                final GetTablesReq req = GetTablesReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
                worker.submitTablesMetadataWork(connection.getSession(), req, responseSender);
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding GetTablesReq body.", e);
            }
        case RpcType.GET_COLUMNS_VALUE:
            try {
                final GetColumnsReq req = GetColumnsReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
                worker.submitColumnsMetadataWork(connection.getSession(), req, responseSender);
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding GetColumnsReq body.", e);
            }
        case RpcType.CREATE_PREPARED_STATEMENT_VALUE:
            try {
                final CreatePreparedStatementReq req = CreatePreparedStatementReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
                worker.submitPreparedStatementWork(connection, req, responseSender);
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding CreatePreparedStatementReq body.", e);
            }
        case RpcType.GET_SERVER_META_VALUE:
            try {
                final GetServerMetaReq req = GetServerMetaReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
                worker.submitServerMetadataWork(connection.getSession(), req, responseSender);
                break;
            } catch (final InvalidProtocolBufferException e) {
                throw new RpcException("Failure while decoding CreatePreparedStatementReq body.", e);
            }
        default:
            throw new UnsupportedOperationException(String.format("UserServerRequestHandler received rpc of unknown type. Type was %d.", rpcType));
    }
}
Also used : RunQuery(org.apache.drill.exec.proto.UserProtos.RunQuery) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Ack(org.apache.drill.exec.proto.GeneralRPCProtos.Ack) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) CreatePreparedStatementReq(org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq) GetCatalogsReq(org.apache.drill.exec.proto.UserProtos.GetCatalogsReq) Response(org.apache.drill.exec.rpc.Response) GetSchemasReq(org.apache.drill.exec.proto.UserProtos.GetSchemasReq) GetServerMetaReq(org.apache.drill.exec.proto.UserProtos.GetServerMetaReq) RpcException(org.apache.drill.exec.rpc.RpcException) GetColumnsReq(org.apache.drill.exec.proto.UserProtos.GetColumnsReq) GetTablesReq(org.apache.drill.exec.proto.UserProtos.GetTablesReq)

Example 5 with QueryId

use of org.apache.drill.exec.proto.UserBitShared.QueryId in project drill by apache.

the class AbstractDisposableUserClientConnection method sendResult.

@Override
public void sendResult(RpcOutcomeListener<Ack> listener, QueryResult result) {
    Preconditions.checkState(result.hasQueryState());
    // Release the wait latch if the query is terminated.
    final QueryState state = result.getQueryState();
    final QueryId queryId = result.getQueryId();
    if (logger.isDebugEnabled()) {
        logger.debug("Result arrived for QueryId: {} with QueryState: {}", QueryIdHelper.getQueryId(queryId), state);
    }
    switch(state) {
        case FAILED:
            error = result.getError(0);
            exception = new UserRemoteException(error);
            latch.countDown();
            break;
        case CANCELED:
        case COMPLETED:
            Preconditions.checkState(result.getErrorCount() == 0);
            latch.countDown();
            break;
        default:
            logger.error("Query with QueryId: {} is in unexpected state: {}", queryId, state);
    }
    // Notify the listener with ACK
    listener.success(Acks.OK, null);
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)

Aggregations

QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)15 UserException (org.apache.drill.common.exceptions.UserException)5 RpcException (org.apache.drill.exec.rpc.RpcException)5 QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)4 Foreman (org.apache.drill.exec.work.foreman.Foreman)4 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)3 Test (org.junit.Test)3 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)2 Ack (org.apache.drill.exec.proto.GeneralRPCProtos.Ack)2 QueryInfo (org.apache.drill.exec.proto.UserBitShared.QueryInfo)2 QueryProfile (org.apache.drill.exec.proto.UserBitShared.QueryProfile)2 GetQueryPlanFragments (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)2 RunQuery (org.apache.drill.exec.proto.UserProtos.RunQuery)2 Response (org.apache.drill.exec.rpc.Response)2 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 DrillBuf (io.netty.buffer.DrillBuf)1 IOException (java.io.IOException)1