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.");
}
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();
}
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();
}
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);
}
}
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);
}
}
Aggregations