use of org.apache.drill.exec.vector.RepeatedVarCharVector in project drill by axbaretto.
the class BatchValidator method validateRepeatedVector.
private void validateRepeatedVector(String name, BaseRepeatedValueVector vector) {
int dataLength = Integer.MAX_VALUE;
if (vector instanceof RepeatedVarCharVector) {
dataLength = ((RepeatedVarCharVector) vector).getOffsetVector().getValueCapacity();
} else if (vector instanceof RepeatedFixedWidthVectorLike) {
dataLength = ((BaseDataValueVector) ((BaseRepeatedValueVector) vector).getDataVector()).getBuffer().capacity();
}
int itemCount = validateOffsetVector(name + "-offsets", vector.getOffsetVector(), rowCount, dataLength);
// Special handling of repeated VarChar vectors
// The nested data vectors are not quite exactly like top-level vectors.
@SuppressWarnings("resource") ValueVector dataVector = vector.getDataVector();
if (dataVector instanceof VariableWidthVector) {
validateVariableWidthVector(name + "-data", (VariableWidthVector) dataVector, itemCount);
}
}
use of org.apache.drill.exec.vector.RepeatedVarCharVector in project drill by axbaretto.
the class TestBatchValidator method testRepeatedBadValueOffset.
@Test
public void testRepeatedBadValueOffset() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR, DataMode.REPEATED).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow((Object) strArray()).addRow((Object) strArray("fred", "barney", "wilma")).addRow((Object) strArray("dino")).build();
VectorAccessible va = batch.vectorAccessible();
ValueVector v = va.iterator().next().getValueVector();
RepeatedVarCharVector rvc = (RepeatedVarCharVector) v;
VarCharVector vc = rvc.getDataVector();
UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(4, 100_000);
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
List<String> errors = validator.errors();
assertEquals(1, errors.size());
assertTrue(errors.get(0).contains("Invalid offset"));
batch.clear();
}
use of org.apache.drill.exec.vector.RepeatedVarCharVector in project drill by axbaretto.
the class TestBatchValidator method testRepeatedBadArrayOffset.
@Test
public void testRepeatedBadArrayOffset() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR, DataMode.REPEATED).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow((Object) strArray()).addRow((Object) strArray("fred", "barney", "wilma")).addRow((Object) strArray("dino")).build();
VectorAccessible va = batch.vectorAccessible();
ValueVector v = va.iterator().next().getValueVector();
RepeatedVarCharVector vc = (RepeatedVarCharVector) v;
UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(3, 1);
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
List<String> errors = validator.errors();
assertEquals(1, errors.size());
assertTrue(errors.get(0).contains("Decreasing offsets"));
batch.clear();
}
use of org.apache.drill.exec.vector.RepeatedVarCharVector in project drill by apache.
the class TestRepeatedListAccessors method testSchema2DVector.
@Test
public void testSchema2DVector() {
final TupleMetadata schema = new SchemaBuilder().add("id", MinorType.INT).addRepeatedList("list2").addArray(MinorType.VARCHAR).resumeSchema().buildSchema();
final DirectRowSet rowSet = DirectRowSet.fromSchema(fixture.allocator(), schema);
final VectorContainer container = rowSet.container();
assertEquals(2, container.getNumberOfColumns());
assertTrue(container.getValueVector(1).getValueVector() instanceof RepeatedListVector);
final RepeatedListVector list = (RepeatedListVector) container.getValueVector(1).getValueVector();
assertEquals(1, list.getField().getChildren().size());
final ValueVector child = list.getDataVector();
assertTrue(child instanceof RepeatedVarCharVector);
assertSame(list.getField().getChildren().iterator().next(), child.getField());
rowSet.clear();
}
use of org.apache.drill.exec.vector.RepeatedVarCharVector in project drill by apache.
the class TestScalarAccessors method testEmptyVarcharArray.
/**
* Test for the special case for the "inner" offset vector
* as explained in the Javadoc for
* @{link org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl}
*/
@Test
public void testEmptyVarcharArray() {
TupleMetadata schema = new SchemaBuilder().addArray("col", MinorType.VARCHAR).add("b", MinorType.VARCHAR).buildSchema();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(strArray(), "first").addRow(strArray(), "second").addRow(strArray(), "third").build();
assertEquals(3, rs.rowCount());
// Verify vector state
VectorContainer container = rs.container();
assertEquals(2, container.getNumberOfColumns());
ValueVector v = container.getValueVector(0).getValueVector();
assertTrue(v instanceof RepeatedVarCharVector);
RepeatedVarCharVector rvc = (RepeatedVarCharVector) v;
assertEquals(3, rvc.getAccessor().getValueCount());
// Verify outer offsets vector
UInt4Vector oov = rvc.getOffsetVector();
assertEquals(4, oov.getAccessor().getValueCount());
assertEquals(4 * 4, oov.getBuffer().writerIndex());
// Inner vector
VarCharVector iv = rvc.getDataVector();
assertEquals(0, iv.getAccessor().getValueCount());
assertEquals(0, iv.getBuffer().writerIndex());
// Inner offset vector. Has 0 entries, not 1 as would be
// expected according to the general rule:
// offset vector length = value length + 1
UInt4Vector iov = iv.getOffsetVector();
assertEquals(0, iov.getAccessor().getValueCount());
assertEquals(0, iov.getBuffer().writerIndex());
rs.clear();
}
Aggregations