Search in sources :

Example 56 with ValueVector

use of org.apache.drill.exec.vector.ValueVector in project drill by apache.

the class ExpressionInterpreterTest method doTest.

protected void doTest(String expressionStr, String[] colNames, TypeProtos.MajorType[] colTypes, String[] expectFirstTwoValues, BitControl.PlanFragment planFragment) throws Exception {
    @SuppressWarnings("resource") final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
    @SuppressWarnings("resource") final Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
    bit1.run();
    // Create a mock scan batch as input for evaluation.
    assertEquals(colNames.length, colTypes.length);
    final MockTableDef.MockColumn[] columns = new MockTableDef.MockColumn[colNames.length];
    for (int i = 0; i < colNames.length; i++) {
        columns[i] = new MockTableDef.MockColumn(colNames[i], colTypes[i].getMinorType(), colTypes[i].getMode(), 0, 0, 0, null, null, null);
    }
    final MockTableDef.MockScanEntry entry = new MockTableDef.MockScanEntry(10, false, 0, 1, columns);
    final MockSubScanPOP scanPOP = new MockSubScanPOP("testTable", false, java.util.Collections.singletonList(entry));
    @SuppressWarnings("resource") final ScanBatch batch = createMockScanBatch(bit1, scanPOP, planFragment);
    batch.next();
    @SuppressWarnings("resource") final ValueVector vv = evalExprWithInterpreter(expressionStr, batch, bit1);
    // Verify the first 2 values in the output of evaluation.
    assertEquals(2, expectFirstTwoValues.length);
    assertEquals(expectFirstTwoValues[0], getValueFromVector(vv, 0));
    assertEquals(expectFirstTwoValues[1], getValueFromVector(vv, 1));
    showValueVectorContent(vv);
    vv.clear();
    batch.close();
    batch.getContext().close();
    bit1.close();
}
Also used : MockSubScanPOP(org.apache.drill.exec.store.mock.MockSubScanPOP) ValueVector(org.apache.drill.exec.vector.ValueVector) Drillbit(org.apache.drill.exec.server.Drillbit) MockTableDef(org.apache.drill.exec.store.mock.MockTableDef) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) ScanBatch(org.apache.drill.exec.physical.impl.ScanBatch)

Example 57 with ValueVector

use of org.apache.drill.exec.vector.ValueVector in project drill by apache.

the class ParquetResultListener method dataArrived.

@Override
public synchronized void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
    logger.debug("result arrived in test batch listener.");
    int columnValCounter = 0;
    FieldInfo currentField;
    count += result.getHeader().getRowCount();
    boolean schemaChanged = false;
    final RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
    try {
        schemaChanged = batchLoader.load(result.getHeader().getDef(), result.getData());
    // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
    // SchemaChangeException, so check/clean catch clause below.
    } catch (SchemaChangeException e) {
        throw new RuntimeException(e);
    }
    // used to make sure each vector in the batch has the same number of records
    int valueCount = batchLoader.getRecordCount();
    // print headers.
    if (schemaChanged) {
    }
    for (final VectorWrapper vw : batchLoader) {
        final ValueVector vv = vw.getValueVector();
        currentField = props.fields.get(vv.getField().getPath());
        if (!valuesChecked.containsKey(vv.getField().getPath())) {
            valuesChecked.put(vv.getField().getPath(), 0);
            columnValCounter = 0;
        } else {
            columnValCounter = valuesChecked.get(vv.getField().getPath());
        }
        printColumnMajor(vv);
        if (testValues) {
            for (int j = 0; j < vv.getAccessor().getValueCount(); j++) {
                assertField(vv, j, currentField.type, currentField.values[columnValCounter % 3], currentField.name + "/");
                columnValCounter++;
            }
        } else {
            columnValCounter += vv.getAccessor().getValueCount();
        }
        valuesChecked.remove(vv.getField().getPath());
        assertEquals("Mismatched value count for vectors in the same batch.", valueCount, vv.getAccessor().getValueCount());
        valuesChecked.put(vv.getField().getPath(), columnValCounter);
    }
    if (ParquetRecordReaderTest.VERBOSE_DEBUG) {
        printRowMajor(batchLoader);
    }
    batchCounter++;
    batchLoader.clear();
    result.release();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) VectorWrapper(org.apache.drill.exec.record.VectorWrapper)

Example 58 with ValueVector

use of org.apache.drill.exec.vector.ValueVector in project drill by apache.

the class TestOutputMutator method replace.

private void replace(ValueVector newVector, SchemaPath schemaPath) {
    List<ValueVector> vectors = Lists.newArrayList();
    for (VectorWrapper w : container) {
        ValueVector vector = w.getValueVector();
        if (vector.getField().getPath().equals(schemaPath)) {
            vectors.add(newVector);
        } else {
            vectors.add(w.getValueVector());
        }
        container.remove(vector);
    }
    container.addCollection(vectors);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VectorWrapper(org.apache.drill.exec.record.VectorWrapper)

Example 59 with ValueVector

use of org.apache.drill.exec.vector.ValueVector in project drill by apache.

the class AbstractContainerVector method getLastPathType.

MajorType getLastPathType() {
    if ((this.getField().getType().getMinorType() == MinorType.LIST && this.getField().getType().getMode() == DataMode.REPEATED)) {
        // Use Repeated scalar type instead of Required List.
        VectorWithOrdinal vord = getChildVectorWithOrdinal(null);
        ValueVector v = vord.vector;
        if (!(v instanceof AbstractContainerVector)) {
            return v.getField().getType();
        }
    } else if (this.getField().getType().getMinorType() == MinorType.MAP && this.getField().getType().getMode() == DataMode.REPEATED) {
        // Use Required Map
        return this.getField().getType().toBuilder().setMode(DataMode.REQUIRED).build();
    }
    return this.getField().getType();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector)

Example 60 with ValueVector

use of org.apache.drill.exec.vector.ValueVector in project drill by apache.

the class AbstractMapVector method close.

@Override
public void close() {
    for (final ValueVector valueVector : vectors.values()) {
        valueVector.close();
    }
    vectors.clear();
    super.close();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector)

Aggregations

ValueVector (org.apache.drill.exec.vector.ValueVector)130 MaterializedField (org.apache.drill.exec.record.MaterializedField)29 Test (org.junit.Test)21 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)18 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)13 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)13 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)12 ExecTest (org.apache.drill.exec.ExecTest)11 IOException (java.io.IOException)10 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)10 VectorContainer (org.apache.drill.exec.record.VectorContainer)10 Drillbit (org.apache.drill.exec.server.Drillbit)10 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)9 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)9 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)9 SchemaPath (org.apache.drill.common.expression.SchemaPath)8 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)8 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)8 FragmentContext (org.apache.drill.exec.ops.FragmentContext)8 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)8