Search in sources :

Example 6 with HyperRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet in project drill by apache.

the class TestHyperVectorReaders method testVarWidth.

@Test
public void testVarWidth() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.VARCHAR).buildSchema();
    SingleRowSet rowSet1 = fixture.rowSetBuilder(schema).addSingleCol("second").addSingleCol("fourth").build();
    SingleRowSet rowSet2 = fixture.rowSetBuilder(schema).addSingleCol("first").addSingleCol("third").build();
    // Build the hyper batch
    HyperRowSet hyperSet = HyperRowSetImpl.fromRowSets(fixture.allocator(), rowSet1, rowSet2);
    assertEquals(4, hyperSet.rowCount());
    SelectionVector4 sv4 = hyperSet.getSv4();
    sv4.set(0, 1, 0);
    sv4.set(1, 0, 0);
    sv4.set(2, 1, 1);
    sv4.set(3, 0, 1);
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow("first").addRow("second").addRow("third").addRow("fourth").build();
    RowSetUtilities.verify(expected, hyperSet);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) HyperRowSet(org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 7 with HyperRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet in project drill by apache.

the class TestHyperVectorReaders method testRequired.

/**
 * Test the simplest case: a top-level required vector. Has no contained vectors.
 * This test focuses on the SV4 indirection mechanism itself.
 */
@Test
public void testRequired() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
    SingleRowSet rowSet1;
    {
        ExtendableRowSet rowSet = fixture.rowSet(schema);
        RowSetWriter writer = rowSet.writer();
        for (int i = 0; i < 10; i++) {
            writer.scalar(0).setInt(i * 10);
            writer.save();
        }
        rowSet1 = writer.done();
    }
    SingleRowSet rowSet2;
    {
        ExtendableRowSet rowSet = fixture.rowSet(schema);
        RowSetWriter writer = rowSet.writer();
        for (int i = 10; i < 20; i++) {
            writer.scalar(0).setInt(i * 10);
            writer.save();
        }
        rowSet2 = writer.done();
    }
    // Build the hyper batch
    // [0, 10, 20, ... 190]
    HyperRowSet hyperSet = HyperRowSetImpl.fromRowSets(fixture.allocator(), rowSet1, rowSet2);
    assertEquals(20, hyperSet.rowCount());
    // Populate the indirection vector:
    // (1, 9), (0, 9), (1, 8), (0, 8), ... (0, 0)
    SelectionVector4 sv4 = hyperSet.getSv4();
    for (int i = 0; i < 20; i++) {
        int batch = i % 2;
        int offset = 9 - i / 2;
        sv4.set(i, batch, offset);
    }
    // Sanity check.
    for (int i = 0; i < 20; i++) {
        int batch = i % 2;
        int offset = 9 - i / 2;
        int encoded = sv4.get(i);
        assertEquals(batch, SelectionVector4.getBatchIndex(encoded));
        assertEquals(offset, SelectionVector4.getRecordIndex(encoded));
    }
    // Verify reader
    // Expected: [190, 90, 180, 80, ... 0]
    RowSetReader reader = hyperSet.reader();
    for (int i = 0; i < 20; i++) {
        assertTrue(reader.next());
        int batch = i % 2;
        int offset = 9 - i / 2;
        int expected = batch * 100 + offset * 10;
        assertEquals(expected, reader.scalar(0).getInt());
    }
    assertFalse(reader.next());
    // Validate using an expected result set.
    RowSetBuilder rsBuilder = fixture.rowSetBuilder(schema);
    for (int i = 0; i < 20; i++) {
        int batch = i % 2;
        int offset = 9 - i / 2;
        int expected = batch * 100 + offset * 10;
        rsBuilder.addRow(expected);
    }
    RowSetUtilities.verify(rsBuilder.build(), hyperSet);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) HyperRowSet(org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with HyperRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet in project drill by apache.

the class TestHyperVectorReaders method testUnion.

@Test
public void testUnion() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addUnion("u").addType(MinorType.INT).addType(MinorType.VARCHAR).resumeSchema().buildSchema();
    SingleRowSet rowSet1 = fixture.rowSetBuilder(schema).addRow(2, 20).addRow(4, "fourth").build();
    SingleRowSet rowSet2 = fixture.rowSetBuilder(schema).addRow(1, "first").addRow(3, 30).build();
    // Build the hyper batch
    HyperRowSet hyperSet = HyperRowSetImpl.fromRowSets(fixture.allocator(), rowSet1, rowSet2);
    assertEquals(4, hyperSet.rowCount());
    SelectionVector4 sv4 = hyperSet.getSv4();
    sv4.set(0, 1, 0);
    sv4.set(1, 0, 0);
    sv4.set(2, 1, 1);
    sv4.set(3, 0, 1);
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(1, "first").addRow(2, 20).addRow(3, 30).addRow(4, "fourth").build();
    RowSetUtilities.verify(expected, hyperSet);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) HyperRowSet(org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 9 with HyperRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet in project drill by apache.

the class TestHyperVectorReaders method testUnionList.

@Test
public void testUnionList() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addList("list").addType(MinorType.INT).addType(MinorType.VARCHAR).resumeSchema().buildSchema();
    SingleRowSet rowSet1 = fixture.rowSetBuilder(schema).addRow(6, variantArray("sixth", 61, "6.2")).addRow(2, variantArray("second", "2.1", 22, "2.3")).addRow(4, variantArray("fourth", 41)).build();
    SingleRowSet rowSet2 = fixture.rowSetBuilder(schema).addRow(5, variantArray("fifth", "5.1", 52)).addRow(1, variantArray("first", 11, "1.2", 13)).addRow(3, variantArray("third", 31)).build();
    // Build the hyper batch
    HyperRowSet hyperSet = HyperRowSetImpl.fromRowSets(fixture.allocator(), rowSet1, rowSet2);
    assertEquals(6, hyperSet.rowCount());
    SelectionVector4 sv4 = hyperSet.getSv4();
    sv4.set(0, 1, 1);
    sv4.set(1, 0, 1);
    sv4.set(2, 1, 2);
    sv4.set(3, 0, 2);
    sv4.set(4, 1, 0);
    sv4.set(5, 0, 0);
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(1, variantArray("first", 11, "1.2", 13)).addRow(2, variantArray("second", "2.1", 22, "2.3")).addRow(3, variantArray("third", 31)).addRow(4, variantArray("fourth", 41)).addRow(5, variantArray("fifth", "5.1", 52)).addRow(6, variantArray("sixth", 61, "6.2")).build();
    RowSetUtilities.verify(expected, hyperSet);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) HyperRowSet(org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

HyperRowSet (org.apache.drill.exec.physical.rowSet.RowSet.HyperRowSet)9 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)9 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)9 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)9 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)9 SubOperatorTest (org.apache.drill.test.SubOperatorTest)9 Test (org.junit.Test)9 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)1