Search in sources :

Example 96 with ValueVector

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

the class BatchPrinter method printBatch.

public static void printBatch(VectorAccessible batch, SelectionVector2 sv2) {
    List<String> columns = Lists.newArrayList();
    List<ValueVector> vectors = Lists.newArrayList();
    for (VectorWrapper vw : batch) {
        columns.add(vw.getValueVector().getField().getPath());
        vectors.add(vw.getValueVector());
    }
    int width = columns.size();
    int rows = vectors.get(0).getMetadata().getValueCount();
    for (int i = 0; i < rows; i++) {
        if (i % 50 == 0) {
            System.out.println(StringUtils.repeat("-", width * 17 + 1));
            for (String column : columns) {
                System.out.printf("| %-15s", width <= 15 ? column : column.substring(0, 14));
            }
            System.out.printf("|\n");
            System.out.println(StringUtils.repeat("-", width * 17 + 1));
        }
        int row = sv2.getIndex(i);
        for (ValueVector vv : vectors) {
            Object o = vv.getAccessor().getObject(row);
            String value;
            if (o == null) {
                value = "null";
            } else if (o instanceof byte[]) {
                value = new String((byte[]) o);
            } else {
                value = o.toString();
            }
            System.out.printf("| %-15s", value.length() <= 15 ? value : value.substring(0, 14));
        }
        System.out.printf("|\n");
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VectorWrapper(org.apache.drill.exec.record.VectorWrapper)

Example 97 with ValueVector

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

the class BatchPrinter method printBatch.

public static void printBatch(VectorAccessible batch) {
    List<String> columns = Lists.newArrayList();
    List<ValueVector> vectors = Lists.newArrayList();
    for (VectorWrapper vw : batch) {
        columns.add(vw.getValueVector().getField().getPath());
        vectors.add(vw.getValueVector());
    }
    int width = columns.size();
    int rows = vectors.get(0).getMetadata().getValueCount();
    for (int row = 0; row < rows; row++) {
        if (row % 50 == 0) {
            System.out.println(StringUtils.repeat("-", width * 17 + 1));
            for (String column : columns) {
                System.out.printf("| %-15s", width <= 15 ? column : column.substring(0, 14));
            }
            System.out.printf("|\n");
            System.out.println(StringUtils.repeat("-", width * 17 + 1));
        }
        for (ValueVector vv : vectors) {
            Object o = vv.getAccessor().getObject(row);
            String value;
            if (o == null) {
                value = "null";
            } else if (o instanceof byte[]) {
                value = new String((byte[]) o);
            } else {
                value = o.toString();
            }
            System.out.printf("| %-15s", value.length() <= 15 ? value : value.substring(0, 14));
        }
        System.out.printf("|\n");
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VectorWrapper(org.apache.drill.exec.record.VectorWrapper)

Example 98 with ValueVector

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

the class DrillParquetReader method next.

@Override
public int next() {
    int count = 0;
    // No columns found in the file were selected, simply return a full batch of null records for each column requested
    if (noColumnsFound) {
        if (mockRecordsRead == footer.getBlocks().get(entry.getRowGroupIndex()).getRowCount()) {
            return 0;
        }
        long recordsToRead = 0;
        recordsToRead = Math.min(DEFAULT_RECORDS_TO_READ, footer.getBlocks().get(entry.getRowGroupIndex()).getRowCount() - mockRecordsRead);
        for (ValueVector vv : nullFilledVectors) {
            vv.getMutator().setValueCount((int) recordsToRead);
        }
        mockRecordsRead += recordsToRead;
        return (int) recordsToRead;
    }
    while (count < 4000 && totalRead < recordCount) {
        recordMaterializer.setPosition(count);
        recordReader.read();
        count++;
        totalRead++;
    }
    writer.setValueCount(count);
    // (by simply setting the value counts inside of them, as they start null filled)
    if (nullFilledVectors != null) {
        for (final ValueVector vv : nullFilledVectors) {
            vv.getMutator().setValueCount(count);
        }
    }
    return count;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector)

Example 99 with ValueVector

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

the class HBaseRecordReader method next.

@Override
public int next() {
    Stopwatch watch = Stopwatch.createStarted();
    if (rowKeyVector != null) {
        rowKeyVector.clear();
        rowKeyVector.allocateNew();
    }
    for (ValueVector v : familyVectorMap.values()) {
        v.clear();
        v.allocateNew();
    }
    int rowCount = 0;
    // if allocated memory for the first row is larger than allowed max in batch, it will be added anyway
    do {
        Result result = null;
        final OperatorStats operatorStats = operatorContext == null ? null : operatorContext.getStats();
        try {
            if (operatorStats != null) {
                operatorStats.startWait();
            }
            try {
                result = resultScanner.next();
            } finally {
                if (operatorStats != null) {
                    operatorStats.stopWait();
                }
            }
        } catch (IOException e) {
            throw new DrillRuntimeException(e);
        }
        if (result == null) {
            break;
        }
        // parse the result and populate the value vectors
        Cell[] cells = result.rawCells();
        if (rowKeyVector != null) {
            rowKeyVector.getMutator().setSafe(rowCount, cells[0].getRowArray(), cells[0].getRowOffset(), cells[0].getRowLength());
        }
        if (!rowKeyOnly) {
            for (final Cell cell : cells) {
                final int familyOffset = cell.getFamilyOffset();
                final int familyLength = cell.getFamilyLength();
                final byte[] familyArray = cell.getFamilyArray();
                final MapVector mv = getOrCreateFamilyVector(new String(familyArray, familyOffset, familyLength), true);
                final int qualifierOffset = cell.getQualifierOffset();
                final int qualifierLength = cell.getQualifierLength();
                final byte[] qualifierArray = cell.getQualifierArray();
                final NullableVarBinaryVector v = getOrCreateColumnVector(mv, new String(qualifierArray, qualifierOffset, qualifierLength));
                final int valueOffset = cell.getValueOffset();
                final int valueLength = cell.getValueLength();
                final byte[] valueArray = cell.getValueArray();
                v.getMutator().setSafe(rowCount, valueArray, valueOffset, valueLength);
            }
        }
        rowCount++;
    } while (canAddNewRow(rowCount));
    setOutputRowCount(rowCount);
    logger.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), rowCount);
    return rowCount;
}
Also used : NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector) Stopwatch(com.google.common.base.Stopwatch) OperatorStats(org.apache.drill.exec.ops.OperatorStats) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) ValueVector(org.apache.drill.exec.vector.ValueVector) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Cell(org.apache.hadoop.hbase.Cell) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 100 with ValueVector

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

the class TestOrderedBytesConvertFunctions method getRunResult.

protected Object[] getRunResult(QueryType queryType, String planString) throws Exception {
    List<QueryDataBatch> resultList = testRunAndReturn(queryType, planString);
    List<Object> res = new ArrayList<Object>();
    RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
    for (QueryDataBatch result : resultList) {
        if (result.getData() != null) {
            loader.load(result.getHeader().getDef(), result.getData());
            ValueVector v = loader.iterator().next().getValueVector();
            for (int j = 0; j < v.getAccessor().getValueCount(); j++) {
                if (v instanceof VarCharVector) {
                    res.add(new String(((VarCharVector) v).getAccessor().get(j)));
                } else {
                    res.add(v.getAccessor().getObject(j));
                }
            }
            loader.clear();
            result.release();
        }
    }
    return res.toArray();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) ArrayList(java.util.ArrayList) VarCharVector(org.apache.drill.exec.vector.VarCharVector)

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