Search in sources :

Example 6 with QueryState

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

the class QueryBuilder method produceSummary.

private QuerySummary produceSummary(BufferingQueryEventListener listener) throws Exception {
    long start = System.currentTimeMillis();
    int recordCount = 0;
    int batchCount = 0;
    QueryId queryId = null;
    QueryState state = null;
    loop: for (; ; ) {
        QueryEvent event = listener.get();
        switch(event.type) {
            case BATCH:
                batchCount++;
                recordCount += event.batch.getHeader().getRowCount();
                event.batch.release();
                break;
            case EOF:
                state = event.state;
                break loop;
            case ERROR:
                throw event.error;
            case QUERY_ID:
                queryId = event.queryId;
                break;
            default:
                throw new IllegalStateException("Unexpected event: " + event.type);
        }
    }
    long end = System.currentTimeMillis();
    long elapsed = end - start;
    return new QuerySummary(queryId, recordCount, batchCount, elapsed, state);
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) QueryEvent(org.apache.drill.test.BufferingQueryEventListener.QueryEvent)

Example 7 with QueryState

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

the class TestDrillbitResilience method passThrough.

// To test pause and resume. Test hangs and times out if resume did not happen.
@Test
public void passThrough() {
    final long before = countAllocatedMemory();
    final WaitUntilCompleteListener listener = new WaitUntilCompleteListener() {

        @Override
        public void queryIdArrived(final QueryId queryId) {
            super.queryIdArrived(queryId);
            final ExtendedLatch trigger = new ExtendedLatch(1);
            (new ResumingThread(queryId, ex, trigger)).start();
            trigger.countDown();
        }
    };
    final String controls = Controls.newBuilder().addPause(PojoRecordReader.class, "read-next").build();
    setControls(controls);
    QueryTestUtil.testWithListener(drillClient, QueryType.SQL, TEST_QUERY, listener);
    final Pair<QueryState, Exception> result = listener.waitForCompletion();
    assertStateCompleted(result, QueryState.COMPLETED);
    final long after = countAllocatedMemory();
    assertEquals(String.format("We are leaking %d bytes", after - before), before, after);
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) PojoRecordReader(org.apache.drill.exec.store.pojo.PojoRecordReader) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) ForemanException(org.apache.drill.exec.work.foreman.ForemanException) IOException(java.io.IOException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) ExtendedLatch(org.apache.drill.common.concurrent.ExtendedLatch) DrillTest(org.apache.drill.test.DrillTest) Test(org.junit.Test)

Aggregations

QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)7 UserException (org.apache.drill.common.exceptions.UserException)5 RpcException (org.apache.drill.exec.rpc.RpcException)5 IOException (java.io.IOException)4 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)4 ForemanException (org.apache.drill.exec.work.foreman.ForemanException)4 ForemanSetupException (org.apache.drill.exec.work.foreman.ForemanSetupException)4 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)2 SingleRowListener (org.apache.drill.SingleRowListener)1 ExtendedLatch (org.apache.drill.common.concurrent.ExtendedLatch)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)1 DrillPBError (org.apache.drill.exec.proto.UserBitShared.DrillPBError)1 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)1 QueryResult (org.apache.drill.exec.proto.UserBitShared.QueryResult)1 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 MaterializedField (org.apache.drill.exec.record.MaterializedField)1 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)1