Search in sources :

Example 26 with SchemaBuilder

use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.

the class TestBatchValidator method testVariableMissingLast.

@Test
public void testVariableMissingLast() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).add("x").add("y").add("z").build();
    // Here we are evil: stomp on the last offset to simulate corruption.
    // Don't do this in real code!
    VectorAccessible va = batch.vectorAccessible();
    @SuppressWarnings("resource") ValueVector v = va.iterator().next().getValueVector();
    VarCharVector vc = (VarCharVector) v;
    @SuppressWarnings("resource") UInt4Vector ov = vc.getOffsetVector();
    assertTrue(ov.getAccessor().get(3) > 0);
    ov.getMutator().set(3, 0);
    // Validator should catch the error.
    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();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) BatchValidator(org.apache.drill.exec.physical.impl.validate.BatchValidator) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) Test(org.junit.Test)

Aggregations

BatchSchema (org.apache.drill.exec.record.BatchSchema)26 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)26 Test (org.junit.Test)20 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)18 BatchValidator (org.apache.drill.exec.physical.impl.validate.BatchValidator)10 RowSetReader (org.apache.drill.test.rowSet.RowSet.RowSetReader)8 RecordBatch (org.apache.drill.exec.record.RecordBatch)4 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)3 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)3 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)3 ValueVector (org.apache.drill.exec.vector.ValueVector)3 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)3 Filter (org.apache.drill.exec.physical.config.Filter)2 UnionAll (org.apache.drill.exec.physical.config.UnionAll)2 VarCharVector (org.apache.drill.exec.vector.VarCharVector)2 ClusterTest (org.apache.drill.test.ClusterTest)2 RowSet (org.apache.drill.test.rowSet.RowSet)2 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)2 RowSetSchema (org.apache.drill.test.rowSet.RowSetSchema)2 PhysicalSchema (org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema)2