Search in sources :

Example 11 with UnionVector

use of org.apache.drill.exec.vector.complex.UnionVector in project drill by apache.

the class SchemaUtil method coerceVector.

private static ValueVector coerceVector(ValueVector v, VectorContainer c, MaterializedField field, int recordCount, BufferAllocator allocator) {
    if (v != null) {
        int valueCount = v.getAccessor().getValueCount();
        TransferPair tp = v.getTransferPair(allocator);
        tp.transfer();
        if (v.getField().getType().getMinorType().equals(field.getType().getMinorType())) {
            if (field.getType().getMinorType() == MinorType.UNION) {
                UnionVector u = (UnionVector) tp.getTo();
                for (MinorType t : field.getType().getSubTypeList()) {
                    u.addSubType(t);
                }
            }
            return tp.getTo();
        } else {
            ValueVector newVector = TypeHelper.getNewVector(field, allocator);
            Preconditions.checkState(field.getType().getMinorType() == MinorType.UNION, "Can only convert vector to Union vector");
            UnionVector u = (UnionVector) newVector;
            u.setFirstType(tp.getTo(), valueCount);
            return u;
        }
    } else {
        v = TypeHelper.getNewVector(field, allocator);
        v.allocateNew();
        v.getMutator().setValueCount(recordCount);
        return v;
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) UnionVector(org.apache.drill.exec.vector.complex.UnionVector)

Aggregations

UnionVector (org.apache.drill.exec.vector.complex.UnionVector)11 ValueVector (org.apache.drill.exec.vector.ValueVector)5 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)3 TransferPair (org.apache.drill.exec.record.TransferPair)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)3 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)3 UnionWriterImpl (org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl)3 ListVector (org.apache.drill.exec.vector.complex.ListVector)3 SubOperatorTest (org.apache.drill.test.SubOperatorTest)3 Test (org.junit.Test)3 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)2 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)2 VectorContainer (org.apache.drill.exec.record.VectorContainer)2 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)2 NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)2 SimpleListShim (org.apache.drill.exec.vector.accessor.writer.SimpleListShim)2 UnionVectorShim (org.apache.drill.exec.vector.accessor.writer.UnionVectorShim)2 MapVector (org.apache.drill.exec.vector.complex.MapVector)2 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1