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