Search in sources :

Example 16 with NullableVarCharVector

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

the class BatchSizingMemoryUtil method getMemoryUsage.

/**
 * Load memory usage information for a variable length value vector
 *
 * @param sourceVector source value vector
 * @param currValueCount current value count
 * @param vectorMemoryUsage result object which contains source vector memory usage information
 */
public static void getMemoryUsage(ValueVector sourceVector, int currValueCount, VectorMemoryUsageInfo vectorMemoryUsage) {
    assert sourceVector instanceof VariableWidthVector;
    // reset result container
    vectorMemoryUsage.reset();
    final MajorType type = sourceVector.getField().getType();
    switch(type.getMinorType()) {
        case VARCHAR:
            {
                switch(type.getMode()) {
                    case REQUIRED:
                        {
                            VarCharVector vector = (VarCharVector) sourceVector;
                            vectorMemoryUsage.offsetsByteCapacity = vector.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = vector.getByteCapacity();
                            vectorMemoryUsage.offsetsBytesUsed = vector.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = vector.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    case OPTIONAL:
                        {
                            NullableVarCharVector vector = (NullableVarCharVector) sourceVector;
                            VarCharVector values = vector.getValuesVector();
                            vectorMemoryUsage.bitsBytesCapacity = vector.getBitsValueCapacity();
                            vectorMemoryUsage.offsetsByteCapacity = values.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = values.getByteCapacity();
                            vectorMemoryUsage.bitsBytesUsed = currValueCount * BYTE_VALUE_WIDTH;
                            vectorMemoryUsage.offsetsBytesUsed = values.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = values.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    default:
                        throw new IllegalArgumentException("Mode [" + type.getMode().name() + "] not supported..");
                }
                break;
            }
        case VARBINARY:
            {
                switch(type.getMode()) {
                    case REQUIRED:
                        {
                            VarBinaryVector vector = (VarBinaryVector) sourceVector;
                            vectorMemoryUsage.offsetsByteCapacity = vector.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = vector.getByteCapacity();
                            vectorMemoryUsage.offsetsBytesUsed = vector.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = vector.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    case OPTIONAL:
                        {
                            NullableVarBinaryVector vector = (NullableVarBinaryVector) sourceVector;
                            VarBinaryVector values = vector.getValuesVector();
                            vectorMemoryUsage.bitsBytesCapacity = vector.getBitsValueCapacity();
                            vectorMemoryUsage.offsetsByteCapacity = values.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = values.getByteCapacity();
                            vectorMemoryUsage.bitsBytesUsed = currValueCount * BYTE_VALUE_WIDTH;
                            vectorMemoryUsage.offsetsBytesUsed = values.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = values.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    default:
                        throw new IllegalArgumentException("Mode [" + type.getMode().name() + "] not supported..");
                }
                break;
            }
        case VARDECIMAL:
            {
                switch(type.getMode()) {
                    case REQUIRED:
                        {
                            VarDecimalVector vector = (VarDecimalVector) sourceVector;
                            vectorMemoryUsage.offsetsByteCapacity = vector.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = vector.getByteCapacity();
                            vectorMemoryUsage.offsetsBytesUsed = vector.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = vector.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    case OPTIONAL:
                        {
                            NullableVarDecimalVector vector = (NullableVarDecimalVector) sourceVector;
                            VarDecimalVector values = vector.getValuesVector();
                            vectorMemoryUsage.bitsBytesCapacity = vector.getBitsValueCapacity();
                            vectorMemoryUsage.offsetsByteCapacity = values.getOffsetVector().getValueCapacity() * INT_VALUE_WIDTH;
                            vectorMemoryUsage.dataByteCapacity = values.getByteCapacity();
                            vectorMemoryUsage.bitsBytesUsed = currValueCount * BYTE_VALUE_WIDTH;
                            vectorMemoryUsage.offsetsBytesUsed = values.getOffsetVector().getPayloadByteCount(currValueCount);
                            vectorMemoryUsage.dataBytesUsed = values.getPayloadByteCount(currValueCount) - vectorMemoryUsage.offsetsBytesUsed;
                            break;
                        }
                    default:
                        throw new IllegalArgumentException("Mode [" + type.getMode().name() + "] not supported..");
                }
                break;
            }
        default:
            throw new IllegalArgumentException("Type [" + type.getMinorType().name() + "] not supported..");
    }
    assert vectorMemoryUsage.bitsBytesCapacity >= 0;
    assert vectorMemoryUsage.bitsBytesUsed >= 0;
    assert vectorMemoryUsage.offsetsByteCapacity >= 0;
    assert vectorMemoryUsage.offsetsBytesUsed >= 0;
    assert vectorMemoryUsage.dataByteCapacity >= 0;
    assert vectorMemoryUsage.dataBytesUsed >= 0;
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) VariableWidthVector(org.apache.drill.exec.vector.VariableWidthVector) NullableVarDecimalVector(org.apache.drill.exec.vector.NullableVarDecimalVector) VarDecimalVector(org.apache.drill.exec.vector.VarDecimalVector) NullableVarDecimalVector(org.apache.drill.exec.vector.NullableVarDecimalVector) VarBinaryVector(org.apache.drill.exec.vector.VarBinaryVector) NullableVarBinaryVector(org.apache.drill.exec.vector.NullableVarBinaryVector)

Example 17 with NullableVarCharVector

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

the class TestVariantAccessors method testBuildRowSetUnionArray.

@Test
public void testBuildRowSetUnionArray() {
    final TupleMetadata schema = new SchemaBuilder().addList("list1").addType(MinorType.BIGINT).addMap().addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.FLOAT8).resumeUnion().resumeSchema().buildSchema();
    final ExtendableRowSet rowSet = fixture.rowSet(schema);
    final VectorContainer vc = rowSet.container();
    assertEquals(1, vc.getNumberOfColumns());
    // List with complex internal structure
    final ValueVector vector = vc.getValueVector(0).getValueVector();
    assertTrue(vector instanceof ListVector);
    final ListVector list = (ListVector) vector;
    assertTrue(list.getDataVector() instanceof UnionVector);
    final UnionVector union = (UnionVector) list.getDataVector();
    // Union inside the list
    final MajorType unionType = union.getField().getType();
    final List<MinorType> types = unionType.getSubTypeList();
    assertEquals(3, types.size());
    assertTrue(types.contains(MinorType.BIGINT));
    assertTrue(types.contains(MinorType.MAP));
    assertTrue(types.contains(MinorType.LIST));
    final MapVector typeMap = union.getTypeMap();
    ValueVector member = typeMap.getChild(MinorType.BIGINT.name());
    assertTrue(member instanceof NullableBigIntVector);
    // Map inside the list
    member = typeMap.getChild(MinorType.MAP.name());
    assertTrue(member instanceof MapVector);
    final MapVector childMap = (MapVector) member;
    ValueVector mapMember = childMap.getChild("a");
    assertNotNull(mapMember);
    assertTrue(mapMember instanceof NullableIntVector);
    mapMember = childMap.getChild("b");
    assertNotNull(mapMember);
    assertTrue(mapMember instanceof NullableVarCharVector);
    // Single-type list inside the outer list
    member = typeMap.getChild(MinorType.LIST.name());
    assertTrue(member instanceof ListVector);
    final ListVector childList = (ListVector) member;
    assertTrue(childList.getDataVector() instanceof NullableFloat8Vector);
    rowSet.clear();
}
Also used : NullableFloat8Vector(org.apache.drill.exec.vector.NullableFloat8Vector) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) UnionVector(org.apache.drill.exec.vector.complex.UnionVector) VectorContainer(org.apache.drill.exec.record.VectorContainer) ValueVector(org.apache.drill.exec.vector.ValueVector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) ListVector(org.apache.drill.exec.vector.complex.ListVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) MapVector(org.apache.drill.exec.vector.complex.MapVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 18 with NullableVarCharVector

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

the class TestVariantAccessors method testBuildRowSetUnion.

@Test
public void testBuildRowSetUnion() {
    final TupleMetadata schema = new SchemaBuilder().addUnion("u").addType(MinorType.INT).addMap().addNullable("c", MinorType.BIGINT).addNullable("d", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.VARCHAR).resumeUnion().resumeSchema().buildSchema();
    final ExtendableRowSet rowSet = fixture.rowSet(schema);
    final VectorContainer vc = rowSet.container();
    assertEquals(1, vc.getNumberOfColumns());
    // Single union
    final ValueVector vector = vc.getValueVector(0).getValueVector();
    assertTrue(vector instanceof UnionVector);
    final UnionVector union = (UnionVector) vector;
    final MapVector typeMap = union.getTypeMap();
    ValueVector member = typeMap.getChild(MinorType.INT.name());
    assertTrue(member instanceof NullableIntVector);
    // Inner map
    member = typeMap.getChild(MinorType.MAP.name());
    assertTrue(member instanceof MapVector);
    member = typeMap.getChild(MinorType.MAP.name());
    assertTrue(member instanceof MapVector);
    final MapVector childMap = (MapVector) member;
    ValueVector mapMember = childMap.getChild("c");
    assertNotNull(mapMember);
    assertTrue(mapMember instanceof NullableBigIntVector);
    mapMember = childMap.getChild("d");
    assertNotNull(mapMember);
    assertTrue(mapMember instanceof NullableVarCharVector);
    // Inner list
    member = typeMap.getChild(MinorType.LIST.name());
    assertTrue(member instanceof ListVector);
    final ListVector list = (ListVector) member;
    assertTrue(list.getDataVector() instanceof NullableVarCharVector);
    rowSet.clear();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableBigIntVector(org.apache.drill.exec.vector.NullableBigIntVector) ListVector(org.apache.drill.exec.vector.complex.ListVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) UnionVector(org.apache.drill.exec.vector.complex.UnionVector) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer) MapVector(org.apache.drill.exec.vector.complex.MapVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 19 with NullableVarCharVector

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

the class TestVariantAccessors method testBuildRowSetScalarList.

@Test
public void testBuildRowSetScalarList() {
    final TupleMetadata schema = new SchemaBuilder().addList("list2").addType(MinorType.VARCHAR).resumeSchema().buildSchema();
    final ExtendableRowSet rowSet = fixture.rowSet(schema);
    final VectorContainer vc = rowSet.container();
    assertEquals(1, vc.getNumberOfColumns());
    // Single-type list
    final ValueVector vector = vc.getValueVector(0).getValueVector();
    assertTrue(vector instanceof ListVector);
    final ListVector list = (ListVector) vector;
    assertTrue(list.getDataVector() instanceof NullableVarCharVector);
    rowSet.clear();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) ListVector(org.apache.drill.exec.vector.complex.ListVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 20 with NullableVarCharVector

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

the class TestScalarAccessors method testNullableVarchar.

@Test
public void testNullableVarchar() {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow("").addSingleCol(null).addRow("abcd").build();
    assertEquals(3, rs.rowCount());
    // Verify vector state
    VectorContainer container = rs.container();
    assertEquals(1, container.getNumberOfColumns());
    ValueVector v = container.getValueVector(0).getValueVector();
    assertTrue(v instanceof NullableVarCharVector);
    NullableVarCharVector nvcv = (NullableVarCharVector) v;
    assertEquals(3, nvcv.getAccessor().getValueCount());
    assertEquals(2, nvcv.getMutator().getLastSet());
    // Data vector: 3 values written above.
    VarCharVector vv = nvcv.getValuesVector();
    assertEquals(3, vv.getAccessor().getValueCount());
    // Offsets vector: one more than row count
    UInt4Vector ov = vv.getOffsetVector();
    assertEquals(4, ov.getAccessor().getValueCount());
    assertEquals(4 * 4, ov.getBuffer().writerIndex());
    // Last offset and bytes buf length must agree
    int lastIndex = ov.getAccessor().get(3);
    assertEquals(lastIndex, vv.getBuffer().writerIndex());
    // Verify using the reader
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals("", colReader.getString());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    assertTrue(reader.next());
    assertEquals("abcd", colReader.getString());
    assertEquals("abcd", colReader.getObject());
    assertEquals("\"abcd\"", colReader.getAsString());
    assertFalse(reader.next());
    rs.clear();
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)33 Test (org.junit.Test)25 ExecTest (org.apache.drill.exec.ExecTest)12 VectorTest (org.apache.drill.categories.VectorTest)10 MaterializedField (org.apache.drill.exec.record.MaterializedField)10 SchemaPath (org.apache.drill.common.expression.SchemaPath)9 VarCharVector (org.apache.drill.exec.vector.VarCharVector)9 SubOperatorTest (org.apache.drill.test.SubOperatorTest)9 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)6 ValueVector (org.apache.drill.exec.vector.ValueVector)6 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)5 NullableVarCharHolder (org.apache.drill.exec.expr.holders.NullableVarCharHolder)5 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)5 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)5 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)5 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)5 NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)5 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)5