Search in sources :

Example 16 with QueryData

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

the class TestMergingReceiver method handleEmptyBatch.

@Test
public void handleEmptyBatch() 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.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 17 with QueryData

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

the class SingleRowListener method dataArrived.

@Override
public void dataArrived(final QueryDataBatch result, final ConnectionThrottle throttle) {
    final QueryData queryData = result.getHeader();
    if (result.hasData()) {
        final int nRows = this.nRows.addAndGet(queryData.getRowCount());
        if (nRows > 1) {
            throw new IllegalStateException("Expected exactly one row, but got " + nRows);
        }
        rowArrived(result);
    }
    result.release();
}
Also used : QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData)

Example 18 with QueryData

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

the class TestDrillbitResilience method assertDrillbitsOk.

/**
 * Check that all the drillbits are ok.
 * <p/>
 * <p>The current implementation does this by counting the number of drillbits using a query.
 */
private static void assertDrillbitsOk() {
    final SingleRowListener listener = new SingleRowListener() {

        private final BufferAllocator bufferAllocator = RootAllocatorFactory.newRoot(zkHelper.getConfig());

        private final RecordBatchLoader loader = new RecordBatchLoader(bufferAllocator);

        @Override
        public void rowArrived(final QueryDataBatch queryResultBatch) {
            // load the single record
            final QueryData queryData = queryResultBatch.getHeader();
            try {
                loader.load(queryData.getDef(), queryResultBatch.getData());
            // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
            // SchemaChangeException, so check/clean catch clause below.
            } catch (final SchemaChangeException e) {
                fail(e.toString());
            }
            assertEquals(1, loader.getRecordCount());
            // there should only be one column
            final BatchSchema batchSchema = loader.getSchema();
            assertEquals(1, batchSchema.getFieldCount());
            // the column should be an integer
            final MaterializedField countField = batchSchema.getColumn(0);
            final MinorType fieldType = countField.getType().getMinorType();
            assertEquals(MinorType.BIGINT, fieldType);
            // get the column value
            final VectorWrapper<?> vw = loader.iterator().next();
            final Object obj = vw.getValueVector().getAccessor().getObject(0);
            assertTrue(obj instanceof Long);
            final Long countValue = (Long) obj;
            // assume this means all the drillbits are still ok
            assertEquals(drillbits.size(), countValue.intValue());
            loader.clear();
        }

        @Override
        public void cleanup() {
            DrillAutoCloseables.closeNoChecked(bufferAllocator);
        }
    };
    try {
        QueryTestUtil.testWithListener(drillClient, QueryType.SQL, "select count(*) from sys.memory", listener);
        listener.waitForCompletion();
        final QueryState state = listener.getQueryState();
        assertTrue(String.format("QueryState should be COMPLETED (and not %s).", state), state == QueryState.COMPLETED);
    } catch (final Exception e) {
        throw new RuntimeException("Couldn't query active drillbits", e);
    }
    final List<DrillPBError> errorList = listener.getErrorList();
    assertTrue("There should not be any errors when checking if Drillbits are OK.", errorList.isEmpty());
}
Also used : SingleRowListener(org.apache.drill.SingleRowListener) DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) MaterializedField(org.apache.drill.exec.record.MaterializedField) 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) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 19 with QueryData

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

the class TestMergingReceiver method handleEmptyBatch.

@Test
public void handleEmptyBatch() throws Exception {
    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.asCharSource(DrillFileUtils.getResourceAsFile("/mergerecv/empty_batch.json"), Charsets.UTF_8).read());
        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) SlowTest(org.apache.drill.categories.SlowTest)

Example 20 with QueryData

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

the class LoggingResultsListener method dataArrived.

@Override
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());
            loader.load(header.getDef(), data);
            try {
                switch(format) {
                    case TABLE:
                        VectorUtil.logVectorAccessibleContent(loader, columnWidth);
                        break;
                    case TSV:
                        VectorUtil.logVectorAccessibleContent(loader, "\t");
                        break;
                    case CSV:
                        VectorUtil.logVectorAccessibleContent(loader, ",");
                        break;
                    default:
                        throw new IllegalStateException(format.toString());
                }
            } finally {
                loader.clear();
            }
        }
    } finally {
        result.release();
    }
}
Also used : QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) DrillBuf(io.netty.buffer.DrillBuf)

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