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;
}
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();
}
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();
}
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();
}
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();
}
Aggregations