Search in sources :

Example 1 with QueryData

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

the class PrintingResultsListener method dataArrived.

@Override
@SuppressWarnings("resource")
public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
    final QueryData header = result.getHeader();
    final DrillBuf data = result.getData();
    try {
        if (data != null) {
            count.addAndGet(header.getRowCount());
            try {
                loader.load(header.getDef(), data);
            // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
            // SchemaChangeException, so check/clean catch clause below.
            } catch (SchemaChangeException e) {
                submissionFailed(UserException.systemError(e).build(logger));
            }
            try {
                switch(format) {
                    case TABLE:
                        VectorUtil.showVectorAccessibleContent(loader, columnWidth);
                        break;
                    case TSV:
                        VectorUtil.showVectorAccessibleContent(loader, "\t");
                        break;
                    case CSV:
                        VectorUtil.showVectorAccessibleContent(loader, ",");
                        break;
                    default:
                        throw new IllegalStateException(format.toString());
                }
            } finally {
                loader.clear();
            }
        }
    } finally {
        result.release();
    }
}
Also used : SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) DrillBuf(io.netty.buffer.DrillBuf)

Example 2 with QueryData

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

the class VectorRecordMaterializer method convertNext.

public QueryWritableBatch convertNext() {
    // batch.getWritableBatch().getDef().getRecordCount()
    WritableBatch w = batch.getWritableBatch().transfer(allocator);
    QueryData header = // 
    QueryData.newBuilder().setQueryId(// 
    queryId).setRowCount(// 
    batch.getRecordCount()).setDef(w.getDef()).build();
    QueryWritableBatch batch = new QueryWritableBatch(header, w.getBuffers());
    return batch;
}
Also used : QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) WritableBatch(org.apache.drill.exec.record.WritableBatch)

Example 3 with QueryData

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

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 QueryData

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

the class TestMergingReceiver method handleEmptyBatchNoSchema.

@Test
public void handleEmptyBatchNoSchema() throws Exception {
    @SuppressWarnings("resource") final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    try (final Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        final Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        bit1.run();
        bit2.run();
        client.connect();
        final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(DrillFileUtils.getResourceAsFile("/mergerecv/empty_batch_noschema.json"), Charsets.UTF_8));
        int count = 0;
        final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
        // print the results
        for (final QueryDataBatch b : results) {
            final QueryData queryData = b.getHeader();
            // loaded but not used, for testing
            batchLoader.load(queryData.getDef(), b.getData());
            count += queryData.getRowCount();
            b.release();
            batchLoader.clear();
        }
        assertEquals(100000, count);
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 5 with QueryData

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

the class TestMergingReceiver method twoBitTwoExchange.

// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMergingReceiver.class);
@Test
public void twoBitTwoExchange() throws Exception {
    @SuppressWarnings("resource") final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    try (final Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        final Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
        bit1.run();
        bit2.run();
        client.connect();
        final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(DrillFileUtils.getResourceAsFile("/mergerecv/merging_receiver.json"), Charsets.UTF_8));
        int count = 0;
        final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
        // print the results
        for (final QueryDataBatch b : results) {
            final QueryData queryData = b.getHeader();
            final int rowCount = queryData.getRowCount();
            count += rowCount;
            // loaded but not used, just to test
            batchLoader.load(queryData.getDef(), b.getData());
            b.release();
            batchLoader.clear();
        }
        assertEquals(200000, count);
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) DrillClient(org.apache.drill.exec.client.DrillClient) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)20 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)12 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)12 OperatorTest (org.apache.drill.categories.OperatorTest)10 DrillClient (org.apache.drill.exec.client.DrillClient)10 Drillbit (org.apache.drill.exec.server.Drillbit)10 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)10 Test (org.junit.Test)10 MaterializedField (org.apache.drill.exec.record.MaterializedField)6 DrillBuf (io.netty.buffer.DrillBuf)5 SlowTest (org.apache.drill.categories.SlowTest)5 UserException (org.apache.drill.common.exceptions.UserException)4 RpcException (org.apache.drill.exec.rpc.RpcException)4 ValueVector (org.apache.drill.exec.vector.ValueVector)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)3 IOException (java.io.IOException)2 SingleRowListener (org.apache.drill.SingleRowListener)2 UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)2