Search in sources :

Example 1 with RepeatedVarCharVector

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);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseRepeatedValueVector(org.apache.drill.exec.vector.complex.BaseRepeatedValueVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) RepeatedFixedWidthVectorLike(org.apache.drill.exec.vector.complex.RepeatedFixedWidthVectorLike) BaseRepeatedValueVector(org.apache.drill.exec.vector.complex.BaseRepeatedValueVector) VariableWidthVector(org.apache.drill.exec.vector.VariableWidthVector)

Example 2 with RepeatedVarCharVector

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();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) Test(org.junit.Test)

Example 3 with RepeatedVarCharVector

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();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorAccessible(org.apache.drill.exec.record.VectorAccessible) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) Test(org.junit.Test)

Example 4 with RepeatedVarCharVector

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();
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseRepeatedValueVector(org.apache.drill.exec.vector.complex.BaseRepeatedValueVector) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with RepeatedVarCharVector

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();
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RepeatedVarCharVector(org.apache.drill.exec.vector.RepeatedVarCharVector) 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

RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)10 Test (org.junit.Test)9 ValueVector (org.apache.drill.exec.vector.ValueVector)8 SubOperatorTest (org.apache.drill.test.SubOperatorTest)7 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)5 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)4 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)3 VectorContainer (org.apache.drill.exec.record.VectorContainer)3 VarCharVector (org.apache.drill.exec.vector.VarCharVector)3 BaseRepeatedValueVector (org.apache.drill.exec.vector.complex.BaseRepeatedValueVector)3 VectorTest (org.apache.drill.categories.VectorTest)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)2 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)2 BaseDataValueVector (org.apache.drill.exec.vector.BaseDataValueVector)2 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)2 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)2 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)2 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)1