Search in sources :

Example 31 with RecordBatchLoader

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();
}
Also used : RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader)

Example 32 with RecordBatchLoader

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;
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader)

Example 33 with RecordBatchLoader

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();
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader)

Example 34 with RecordBatchLoader

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);
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) HyperVectorValueIterator(org.apache.drill.exec.HyperVectorValueIterator)

Example 35 with RecordBatchLoader

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();
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) TypeProtos(org.apache.drill.common.types.TypeProtos) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)70 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)64 Test (org.junit.Test)45 DrillClient (org.apache.drill.exec.client.DrillClient)37 Drillbit (org.apache.drill.exec.server.Drillbit)36 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)36 ValueVector (org.apache.drill.exec.vector.ValueVector)34 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)17 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)8 BigIntVector (org.apache.drill.exec.vector.BigIntVector)8 ExecTest (org.apache.drill.exec.ExecTest)7 VarCharVector (org.apache.drill.exec.vector.VarCharVector)6 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)5 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)5 ArrayList (java.util.ArrayList)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)4 IOException (java.io.IOException)3 VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)3 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)3 QueryData (org.apache.drill.exec.proto.UserBitShared.QueryData)3