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);
}
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);
}
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));
}
}
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));
}
}
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);
}
Aggregations