Search in sources :

Example 11 with QueryData

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

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() {
    SingleRowListener listener = new SingleRowListener() {

        private final BufferAllocator bufferAllocator = RootAllocatorFactory.newRoot(cluster.config());

        private final RecordBatchLoader loader = new RecordBatchLoader(bufferAllocator);

        @Override
        public void rowArrived(QueryDataBatch queryResultBatch) {
            // load the single record
            final QueryData queryData = queryResultBatch.getHeader();
            loader.load(queryData.getDef(), queryResultBatch.getData());
            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(cluster.drillbits().size(), countValue.intValue());
            loader.clear();
        }

        @Override
        public void cleanup() {
            loader.clear();
            DrillAutoCloseables.closeNoChecked(bufferAllocator);
        }
    };
    try {
        QueryTestUtil.testWithListener(client.client(), QueryType.SQL, "select count(*) from sys.memory", listener);
        listener.waitForCompletion();
        QueryState state = listener.getQueryState();
        assertSame(state, QueryState.COMPLETED, () -> String.format("QueryState should be COMPLETED (and not %s).", state));
        assertTrue(listener.getErrorList().isEmpty(), "There should not be any errors when checking if Drillbits are OK");
    } catch (final Exception e) {
        throw new RuntimeException("Couldn't query active drillbits", e);
    } finally {
        logger.debug("Cleanup listener");
        listener.cleanup();
    }
    logger.debug("Drillbits are ok.");
}
Also used : SingleRowListener(org.apache.drill.SingleRowListener) 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) ForemanException(org.apache.drill.exec.work.foreman.ForemanException) TestInstantiationException(org.junit.jupiter.api.extension.TestInstantiationException) IOException(java.io.IOException) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 12 with QueryData

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

the class SingleRowListener method dataArrived.

@Override
public void dataArrived(QueryDataBatch result, 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 13 with QueryData

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

the class PrintingResultsListener method dataArrived.

@Override
public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
    final QueryData header = result.getHeader();
    final DrillBuf data = result.getData();
    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));
        }
        switch(format) {
            case TABLE:
                VectorUtil.showVectorAccessibleContent(loader, columnWidth);
                break;
            case TSV:
                VectorUtil.showVectorAccessibleContent(loader, "\t");
                break;
            case CSV:
                VectorUtil.showVectorAccessibleContent(loader, ",");
                break;
        }
        loader.clear();
    }
    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 14 with QueryData

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

the class TestMergingReceiver method testMultipleProvidersMixedSizes.

@Test
public void testMultipleProvidersMixedSizes() 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/multiple_providers.json"), Charsets.UTF_8));
        int count = 0;
        final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
        // print the results
        Long lastBlueValue = null;
        for (final QueryDataBatch b : results) {
            final QueryData queryData = b.getHeader();
            final int batchRowCount = queryData.getRowCount();
            count += batchRowCount;
            batchLoader.load(queryData.getDef(), b.getData());
            for (final VectorWrapper<?> vw : batchLoader) {
                @SuppressWarnings("resource") final ValueVector vv = vw.getValueVector();
                final ValueVector.Accessor va = vv.getAccessor();
                final MaterializedField materializedField = vv.getField();
                final int numValues = va.getValueCount();
                for (int valueIdx = 0; valueIdx < numValues; ++valueIdx) {
                    if (materializedField.getName().equals("blue")) {
                        final long longValue = (Long) va.getObject(valueIdx);
                        // check that order is ascending
                        if (lastBlueValue != null) {
                            assertTrue(longValue >= lastBlueValue);
                        }
                        lastBlueValue = longValue;
                    }
                }
            }
            b.release();
            batchLoader.clear();
        }
        assertEquals(400000, count);
    }
}
Also used : QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) MaterializedField(org.apache.drill.exec.record.MaterializedField) ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) DrillClient(org.apache.drill.exec.client.DrillClient) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 15 with QueryData

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

the class TestMergingReceiver method testMultipleProvidersEmptyBatches.

@Test
public void testMultipleProvidersEmptyBatches() 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/multiple_providers_empty_batches.json"), Charsets.UTF_8));
        int count = 0;
        final RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
        // print the results
        Long lastBlueValue = null;
        for (final QueryDataBatch b : results) {
            final QueryData queryData = b.getHeader();
            final int batchRowCount = queryData.getRowCount();
            count += batchRowCount;
            batchLoader.load(queryData.getDef(), b.getData());
            for (final VectorWrapper<?> vw : batchLoader) {
                @SuppressWarnings("resource") final ValueVector vv = vw.getValueVector();
                final ValueVector.Accessor va = vv.getAccessor();
                final MaterializedField materializedField = vv.getField();
                final int numValues = va.getValueCount();
                for (int valueIdx = 0; valueIdx < numValues; ++valueIdx) {
                    if (materializedField.getName().equals("blue")) {
                        final long longValue = (Long) va.getObject(valueIdx);
                        // check that order is ascending
                        if (lastBlueValue != null) {
                            assertTrue(longValue >= lastBlueValue);
                        }
                        lastBlueValue = longValue;
                    }
                }
            }
            b.release();
            batchLoader.clear();
        }
        assertEquals(300000, count);
    }
}
Also used : QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) MaterializedField(org.apache.drill.exec.record.MaterializedField) ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) Drillbit(org.apache.drill.exec.server.Drillbit) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) 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