Search in sources :

Example 1 with SingleMapWriter

use of org.apache.drill.exec.vector.complex.impl.SingleMapWriter in project drill by apache.

the class VectorTest method testRepeatedMapWriter.

@Test
public void testRepeatedMapWriter() throws Exception {
    // The writers will create a nullable int inner vector.
    MaterializedField field = MaterializedField.create("repeated_map", Types.repeated(TypeProtos.MinorType.MAP));
    try (RepeatedMapVector v = new RepeatedMapVector(field, allocator, null)) {
        SpecialMapVector mapVector = new SpecialMapVector(v);
        @SuppressWarnings("resource") SingleMapWriter mapRoot = new SingleMapWriter(mapVector, null, false);
        ListWriter lw = mapRoot.list("repeated_map");
        MapWriter mw = lw.map();
        // Record 1: [10, 20]
        lw.setPosition(0);
        lw.startList();
        mw.start();
        IntWriter iw = mw.integer("inner");
        iw.writeInt(10);
        mw.end();
        mw.start();
        iw.writeInt(20);
        mw.end();
        lw.endList();
        // Record 2: [30, 40, 50]
        lw.setPosition(1);
        lw.startList();
        mw.start();
        iw.writeInt(30);
        mw.end();
        mw.start();
        iw.writeInt(40);
        mw.end();
        mw.start();
        iw.writeInt(50);
        mw.end();
        lw.endList();
        // Record 3: []
        lw.setPosition(2);
        lw.startList();
        lw.endList();
        v.getMutator().setValueCount(3);
        assertEquals(3, v.getAccessor().getValueCount());
        UInt4Vector.Accessor oa = v.getOffsetVector().getAccessor();
        assertEquals(4, oa.getValueCount());
        assertEquals(0, oa.get(0));
        assertEquals(2, oa.get(1));
        assertEquals(5, oa.get(2));
        assertEquals(5, oa.get(3));
        // Past end
        assertEquals(0, oa.get(4));
        NullableIntVector inner = v.addOrGet("inner", Types.optional(TypeProtos.MinorType.INT), NullableIntVector.class);
        UInt1Vector.Accessor ba = inner.getBitsVector().getAccessor();
        assertEquals(1, ba.get(0));
        assertEquals(1, ba.get(1));
        assertEquals(1, ba.get(2));
        assertEquals(1, ba.get(3));
        assertEquals(1, ba.get(4));
        // Past end
        assertEquals(0, ba.get(5));
        NullableIntVector.Accessor ia = inner.getAccessor();
        assertEquals(10, ia.get(0));
        assertEquals(20, ia.get(1));
        assertEquals(30, ia.get(2));
        assertEquals(40, ia.get(3));
        assertEquals(50, ia.get(4));
    }
}
Also used : SingleMapWriter(org.apache.drill.exec.vector.complex.impl.SingleMapWriter) MapWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter) SingleMapWriter(org.apache.drill.exec.vector.complex.impl.SingleMapWriter) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) IntWriter(org.apache.drill.exec.vector.complex.writer.IntWriter) MaterializedField(org.apache.drill.exec.record.MaterializedField) ListWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Aggregations

MaterializedField (org.apache.drill.exec.record.MaterializedField)1 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)1 SingleMapWriter (org.apache.drill.exec.vector.complex.impl.SingleMapWriter)1 ListWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter)1 MapWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter)1 IntWriter (org.apache.drill.exec.vector.complex.writer.IntWriter)1 BaseTest (org.apache.drill.test.BaseTest)1 Test (org.junit.Test)1