Search in sources :

Example 1 with SingleRowListener

use of org.apache.drill.SingleRowListener 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 2 with SingleRowListener

use of org.apache.drill.SingleRowListener in project drill by axbaretto.

the class TestSimpleJson method testPushdownStringEqual.

@Test
public void testPushdownStringEqual() throws Exception {
    setColumnWidths(new int[] { 25, 40, 40, 40 });
    final String sql = "SELECT\n" + "  _id, name, business.hours.Monday.`open`, categories[1], years[2], full_address\n" + "FROM\n" + "  hbase.`business` business\n" + "WHERE\n" + " name = 'Sprint'";
    final Document queryResult = MapRDB.newDocument();
    SingleRowListener listener = new SingleRowListener() {

        @Override
        protected void rowArrived(QueryDataBatch result) {
            try {
                final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
                loader.load(result.getHeader().getDef(), result.getData());
                StringBuilder sb = new StringBuilder();
                VectorUtil.appendVectorAccessibleContent(loader, sb, "|", false);
                loader.clear();
                queryResult.set("result", sb.toString());
            } catch (SchemaChangeException e) {
                queryResult.set("error", "true");
            }
        }
    };
    testWithListener(QueryType.SQL, sql, listener);
    listener.waitForCompletion();
    assertNull(queryResult.getString("error"));
    assertNotNull(queryResult.getString("result"));
    String[] fields = queryResult.getString("result").split("\\|");
    assertEquals("1970-01-01T11:00:00.000", fields[2]);
    assertEquals("Mobile Phones", fields[3]);
    assertEquals("2016.0", fields[4]);
    final String[] expectedPlan = { "condition=\\(name = \"Sprint\"\\)" };
    final String[] excludedPlan = {};
    PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
Also used : SingleRowListener(org.apache.drill.SingleRowListener) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) Document(org.ojai.Document) Test(org.junit.Test) ClusterTest(com.mapr.tests.annotations.ClusterTest)

Example 3 with SingleRowListener

use of org.apache.drill.SingleRowListener 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 4 with SingleRowListener

use of org.apache.drill.SingleRowListener in project drill by apache.

the class TestSimpleJson method testPushdownStringEqual.

@Test
public void testPushdownStringEqual() throws Exception {
    setColumnWidths(new int[] { 25, 40, 40, 40 });
    final String sql = format("SELECT\n" + "  _id, name, business.hours.Monday.`open`, categories[1], years[2], full_address\n" + "FROM\n" + "  %s.`%s` business\n" + "WHERE\n" + " name = 'Sprint'");
    final Document queryResult = MapRDBImpl.newDocument();
    SingleRowListener listener = new SingleRowListener() {

        @Override
        protected void rowArrived(QueryDataBatch result) {
            final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
            loader.load(result.getHeader().getDef(), result.getData());
            StringBuilder sb = new StringBuilder();
            VectorUtil.appendVectorAccessibleContent(loader, sb, "|", false);
            loader.clear();
            queryResult.set("result", sb.toString());
        }
    };
    testWithListener(QueryType.SQL, sql, listener);
    listener.waitForCompletion();
    assertNull(queryResult.getString("error"));
    assertNotNull(queryResult.getString("result"));
    String[] fields = queryResult.getString("result").split("\\|");
    assertEquals("1970-01-01T11:00:00.000", fields[2]);
    assertEquals("Mobile Phones", fields[3]);
    assertEquals("2016.0", fields[4]);
    final String[] expectedPlan = { "condition=\\(name = \"Sprint\"\\)" };
    final String[] excludedPlan = {};
    PlanTestBase.testPlanMatchingPatterns(sql, expectedPlan, excludedPlan);
}
Also used : SingleRowListener(org.apache.drill.SingleRowListener) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) Document(org.ojai.Document) Test(org.junit.Test) ClusterTest(com.mapr.tests.annotations.ClusterTest)

Aggregations

SingleRowListener (org.apache.drill.SingleRowListener)4 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)4 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)4 ClusterTest (com.mapr.tests.annotations.ClusterTest)2 IOException (java.io.IOException)2 UserException (org.apache.drill.common.exceptions.UserException)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)2 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)2 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)2 QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)2 MaterializedField (org.apache.drill.exec.record.MaterializedField)2 RpcException (org.apache.drill.exec.rpc.RpcException)2 ForemanException (org.apache.drill.exec.work.foreman.ForemanException)2 ForemanSetupException (org.apache.drill.exec.work.foreman.ForemanSetupException)2 Test (org.junit.Test)2 Document (org.ojai.Document)2 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)1 DrillPBError (org.apache.drill.exec.proto.UserBitShared.DrillPBError)1