Search in sources :

Example 1 with BaseDataValueVector

use of org.apache.drill.exec.vector.BaseDataValueVector 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 BaseDataValueVector

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

the class TestScalarAccessors method nullableIntTester.

private void nullableIntTester(MinorType type) {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", type).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10).addSingleCol(null).addRow(30).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 NullableVector);
    NullableVector nv = (NullableVector) v;
    assertEquals(3, nv.getAccessor().getValueCount());
    assertEquals(3 * BasicTypeHelper.getSize(Types.required(type)), ((BaseDataValueVector) v).getBuffer().writerIndex());
    // Verify bits vector. (Assumes UInt1 implementation.)
    UInt1Vector bv = (UInt1Vector) nv.getBitsVector();
    assertEquals(3, bv.getAccessor().getValueCount());
    assertEquals(3, bv.getBuffer().writerIndex());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(10, colReader.getInt());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    // Data value is undefined, may be garbage
    assertTrue(reader.next());
    assertEquals(30, colReader.getInt());
    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) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) NullableVector(org.apache.drill.exec.vector.NullableVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) UInt1Vector(org.apache.drill.exec.vector.UInt1Vector) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 3 with BaseDataValueVector

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

the class TestScalarAccessors method testBitRW.

@Test
public void testBitRW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.BIT).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(true).addSingleCol(false).addSingleCol(0).addSingleCol(1).addSingleCol(2).addSingleCol(3).build();
    assertEquals(6, rs.rowCount());
    // Verify vector state
    VectorContainer container = rs.container();
    assertEquals(1, container.getNumberOfColumns());
    ValueVector v = container.getValueVector(0).getValueVector();
    assertTrue(v instanceof BitVector);
    BitVector bv = (BitVector) v;
    assertEquals(6, bv.getAccessor().getValueCount());
    assertEquals(1, ((BaseDataValueVector) v).getBuffer().writerIndex());
    // Verify using a reader
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(false, colReader.getBoolean());
    assertEquals(0, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(false, colReader.getBoolean());
    assertEquals(0, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    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) BitVector(org.apache.drill.exec.vector.BitVector) NullableBitVector(org.apache.drill.exec.vector.NullableBitVector) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with BaseDataValueVector

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

the class TestScalarAccessors method intArrayTester.

private void intArrayTester(MinorType type) {
    TupleMetadata schema = new SchemaBuilder().addArray("col", type).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(new int[] {}).addSingleCol(new int[] { 0, 20, 30 }).build();
    assertEquals(2, rs.rowCount());
    // Verify vector state
    VectorContainer container = rs.container();
    assertEquals(1, container.getNumberOfColumns());
    ValueVector v = container.getValueVector(0).getValueVector();
    assertTrue(v instanceof RepeatedValueVector);
    RepeatedValueVector rv = (RepeatedValueVector) v;
    assertEquals(2, rv.getAccessor().getValueCount());
    // Data vector: 3 values written above.
    ValueVector vv = rv.getDataVector();
    assertEquals(3, vv.getAccessor().getValueCount());
    assertEquals(3 * BasicTypeHelper.getSize(Types.required(type)), ((BaseDataValueVector) vv).getBuffer().writerIndex());
    // Offsets vector: one more than row count
    UInt4Vector ov = rv.getOffsetVector();
    assertEquals(3, ov.getAccessor().getValueCount());
    assertEquals(3 * 4, ov.getBuffer().writerIndex());
    RowSetReader reader = rs.reader();
    ArrayReader arrayReader = reader.array(0);
    ScalarReader colReader = arrayReader.scalar();
    assertEquals(ValueType.INTEGER, colReader.valueType());
    assertTrue(reader.next());
    assertEquals(0, arrayReader.size());
    assertTrue(reader.next());
    assertEquals(3, arrayReader.size());
    assertTrue(arrayReader.next());
    assertFalse(colReader.isNull());
    assertEquals(0, colReader.getInt());
    assertEquals(0, colReader.getObject());
    assertEquals("0", colReader.getAsString());
    assertTrue(arrayReader.next());
    assertFalse(colReader.isNull());
    assertEquals(20, colReader.getInt());
    assertEquals(20, colReader.getObject());
    assertEquals("20", colReader.getAsString());
    assertTrue(arrayReader.next());
    assertFalse(colReader.isNull());
    assertEquals(30, colReader.getInt());
    assertEquals(30, colReader.getObject());
    assertEquals("30", colReader.getAsString());
    assertFalse(arrayReader.next());
    assertEquals("[0, 20, 30]", arrayReader.getAsString());
    assertEquals(Arrays.asList(0, 20, 30), arrayReader.getObject());
    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) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

BaseDataValueVector (org.apache.drill.exec.vector.BaseDataValueVector)4 ValueVector (org.apache.drill.exec.vector.ValueVector)4 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)3 VectorContainer (org.apache.drill.exec.record.VectorContainer)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)3 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)3 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)3 BitVector (org.apache.drill.exec.vector.BitVector)1 NullableBitVector (org.apache.drill.exec.vector.NullableBitVector)1 NullableVector (org.apache.drill.exec.vector.NullableVector)1 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)1 UInt1Vector (org.apache.drill.exec.vector.UInt1Vector)1 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)1 VariableWidthVector (org.apache.drill.exec.vector.VariableWidthVector)1 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)1 BaseRepeatedValueVector (org.apache.drill.exec.vector.complex.BaseRepeatedValueVector)1 RepeatedFixedWidthVectorLike (org.apache.drill.exec.vector.complex.RepeatedFixedWidthVectorLike)1 SubOperatorTest (org.apache.drill.test.SubOperatorTest)1 Test (org.junit.Test)1