use of org.apache.drill.exec.record.RecordBatchLoader in project drill by apache.
the class MergingRecordBatch method close.
@Override
public void close() {
outgoingContainer.clear();
if (batchLoaders != null) {
for (final RecordBatchLoader rbl : batchLoaders) {
if (rbl != null) {
rbl.clear();
}
}
}
super.close();
}
use of org.apache.drill.exec.record.RecordBatchLoader in project drill by apache.
the class BaseTestQuery method printResult.
protected int printResult(List<QueryDataBatch> results) throws SchemaChangeException {
int rowCount = 0;
final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
for (final QueryDataBatch result : results) {
rowCount += result.getHeader().getRowCount();
loader.load(result.getHeader().getDef(), result.getData());
// TODO: Clean: DRILL-2933: That load(...) no longer throws
// SchemaChangeException, so check/clean throw clause above.
VectorUtil.showVectorAccessibleContent(loader, columnWidths);
loader.clear();
result.release();
}
System.out.println("Total record count: " + rowCount);
return rowCount;
}
use of org.apache.drill.exec.record.RecordBatchLoader in project drill by apache.
the class BaseTestQuery method getResultString.
protected static String getResultString(List<QueryDataBatch> results, String delimiter) throws SchemaChangeException {
final StringBuilder formattedResults = new StringBuilder();
boolean includeHeader = true;
final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
for (final QueryDataBatch result : results) {
loader.load(result.getHeader().getDef(), result.getData());
if (loader.getRecordCount() <= 0) {
continue;
}
VectorUtil.appendVectorAccessibleContent(loader, formattedResults, delimiter, includeHeader);
if (!includeHeader) {
includeHeader = false;
}
loader.clear();
result.release();
}
return formattedResults.toString();
}
use of org.apache.drill.exec.record.RecordBatchLoader in project drill by apache.
the class DrillTestWrapper method compareResultsHyperVector.
public void compareResultsHyperVector() throws Exception {
RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
test(testOptionSettingQueries);
List<QueryDataBatch> results = testRunAndReturn(queryType, query);
checkNumBatches(results);
// To avoid extra work for test writers, types can optionally be inferred from the test query
addTypeInfoIfMissing(results.get(0), testBuilder);
Map<String, HyperVectorValueIterator> actualSuperVectors = addToHyperVectorMap(results, loader);
test(baselineOptionSettingQueries);
List<QueryDataBatch> expected = testRunAndReturn(baselineQueryType, testBuilder.getValidationQuery());
Map<String, HyperVectorValueIterator> expectedSuperVectors = addToHyperVectorMap(expected, loader);
compareHyperVectors(expectedSuperVectors, actualSuperVectors);
cleanupBatches(results, expected);
}
use of org.apache.drill.exec.record.RecordBatchLoader in project drill by apache.
the class DrillTestWrapper method compareSchemaOnly.
protected void compareSchemaOnly() throws Exception {
RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
List<QueryDataBatch> actual;
QueryDataBatch batch = null;
try {
test(testOptionSettingQueries);
actual = testRunAndReturn(queryType, query);
batch = actual.get(0);
loader.load(batch.getHeader().getDef(), batch.getData());
final BatchSchema schema = loader.getSchema();
final List<Pair<SchemaPath, TypeProtos.MajorType>> expectedSchema = testBuilder.getExpectedSchema();
if (schema.getFieldCount() != expectedSchema.size()) {
throw new Exception("Expected and actual numbers of columns do not match.");
}
for (int i = 0; i < schema.getFieldCount(); ++i) {
final String actualSchemaPath = schema.getColumn(i).getPath();
final TypeProtos.MajorType actualMajorType = schema.getColumn(i).getType();
final String expectedSchemaPath = expectedSchema.get(i).getLeft().getAsUnescapedPath();
final TypeProtos.MajorType expectedMajorType = expectedSchema.get(i).getValue();
if (!actualSchemaPath.equals(expectedSchemaPath) || !actualMajorType.equals(expectedMajorType)) {
throw new Exception(String.format("Schema path or type mismatch for column #%d:\n" + "Expected schema path: %s\nActual schema path: %s\nExpected type: %s\nActual type: %s", i, expectedSchemaPath, actualSchemaPath, Types.toString(expectedMajorType), Types.toString(actualMajorType)));
}
}
} finally {
if (batch != null) {
batch.release();
}
loader.clear();
}
}
Aggregations