Search in sources :

Example 1 with UInt1Vector

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

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

the class TestScalarAccessors method testNullableBitRW.

@Test
public void testNullableBitRW() {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", MinorType.BIT).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(true).addSingleCol(false).addSingleCol(null).addSingleCol(1).addSingleCol(2).addSingleCol(null).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 NullableBitVector);
    NullableBitVector nv = (NullableBitVector) v;
    assertEquals(6, nv.getAccessor().getValueCount());
    BitVector dv = nv.getValuesVector();
    assertEquals(6, dv.getAccessor().getValueCount());
    assertEquals(1, dv.getBuffer().writerIndex());
    // Verify bits vector. (Assumes UInt1 implementation.)
    UInt1Vector bv = nv.getBitsVector();
    assertEquals(6, bv.getAccessor().getValueCount());
    assertEquals(6, bv.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());
    assertFalse(colReader.isNull());
    assertTrue(reader.next());
    assertEquals(false, colReader.getBoolean());
    assertEquals(0, colReader.getInt());
    assertFalse(colReader.isNull());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertFalse(colReader.isNull());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    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) NullableBitVector(org.apache.drill.exec.vector.NullableBitVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) UInt1Vector(org.apache.drill.exec.vector.UInt1Vector) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)2 VectorContainer (org.apache.drill.exec.record.VectorContainer)2 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)2 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)2 BaseDataValueVector (org.apache.drill.exec.vector.BaseDataValueVector)2 UInt1Vector (org.apache.drill.exec.vector.UInt1Vector)2 ValueVector (org.apache.drill.exec.vector.ValueVector)2 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)2 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)2 BitVector (org.apache.drill.exec.vector.BitVector)1 NullableBitVector (org.apache.drill.exec.vector.NullableBitVector)1 NullableVector (org.apache.drill.exec.vector.NullableVector)1 SubOperatorTest (org.apache.drill.test.SubOperatorTest)1 Test (org.junit.Test)1