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