Search in sources :

Example 96 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet 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 97 with SingleRowSet

use of org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet 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 98 with SingleRowSet

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

the class TestMapAccessors method testBasicRepeatedMap.

@Test
public void testBasicRepeatedMap() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).resumeSchema().buildSchema();
    RowSetBuilder builder = fixture.rowSetBuilder(schema);
    RowSetWriter rootWriter = builder.writer();
    // Verify structure and schema
    TupleMetadata actualSchema = rootWriter.tupleSchema();
    assertEquals(2, actualSchema.size());
    assertTrue(actualSchema.metadata(1).isArray());
    assertTrue(actualSchema.metadata(1).isMap());
    assertEquals(2, actualSchema.metadata("m").tupleSchema().size());
    assertEquals(2, actualSchema.column("m").getChildren().size());
    TupleWriter mapWriter = rootWriter.array("m").tuple();
    assertSame(actualSchema.metadata("m").tupleSchema(), mapWriter.schema().tupleSchema());
    assertSame(mapWriter.tupleSchema(), mapWriter.schema().tupleSchema());
    assertSame(mapWriter.tupleSchema().metadata(0), mapWriter.scalar(0).schema());
    assertSame(mapWriter.tupleSchema().metadata(1), mapWriter.scalar(1).schema());
    // Write a couple of rows with arrays.
    rootWriter.addRow(10, mapArray(mapValue(110, "d1.1"), mapValue(120, "d2.2"))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, "d3.1"), mapValue(320, "d3.2"), mapValue(330, "d3.3")));
    // Verify the first batch
    RowSet actual = builder.build();
    RepeatedMapVector mapVector = (RepeatedMapVector) actual.container().getValueVector(1).getValueVector();
    MaterializedField mapField = mapVector.getField();
    assertEquals(2, mapField.getChildren().size());
    Iterator<MaterializedField> iter = mapField.getChildren().iterator();
    assertTrue(mapWriter.scalar(0).schema().schema().isEquivalent(iter.next()));
    assertTrue(mapWriter.scalar(1).schema().schema().isEquivalent(iter.next()));
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, mapArray(mapValue(110, "d1.1"), mapValue(120, "d2.2"))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, "d3.1"), mapValue(320, "d3.2"), mapValue(330, "d3.3"))).build();
    new RowSetComparison(expected).verify(actual);
    // Test that the row set rebuilds its internal structure from
    // a vector container.
    RowSet wrapped = fixture.wrap(actual.container());
    RowSetUtilities.verify(expected, wrapped);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 99 with SingleRowSet

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

the class TestMapAccessors method testNestedArray.

@Test
public void testNestedArray() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).addArray("d", MinorType.VARCHAR).resumeSchema().buildSchema();
    RowSetBuilder builder = fixture.rowSetBuilder(schema);
    RowSetWriter rootWriter = builder.writer();
    // Write a couple of rows with arrays within arrays.
    // (And, of course, the Varchar is actually an array of
    // bytes, so that's three array levels.)
    rootWriter.addRow(10, mapArray(mapValue(110, strArray("d1.1.1", "d1.1.2")), mapValue(120, strArray("d1.2.1", "d1.2.2")))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, strArray("d3.1.1", "d3.2.2")), mapValue(320, strArray()), mapValue(330, strArray("d3.3.1", "d1.2.2"))));
    // Verify the batch
    RowSet actual = builder.build();
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, mapArray(mapValue(110, strArray("d1.1.1", "d1.1.2")), mapValue(120, strArray("d1.2.1", "d1.2.2")))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, strArray("d3.1.1", "d3.2.2")), mapValue(320, strArray()), mapValue(330, strArray("d3.3.1", "d1.2.2")))).build();
    new RowSetComparison(expected).verify(actual);
    // Test that the row set rebuilds its internal structure from
    // a vector container.
    RowSet wrapped = fixture.wrap(actual.container());
    RowSetUtilities.verify(expected, wrapped);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 100 with SingleRowSet

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

the class TestRowSet method testTopFixedWidthArray.

/**
 * Test an array of ints (as an example fixed-width type)
 * at the top level of a schema.
 */
@Test
public void testTopFixedWidthArray() {
    final TupleMetadata schema = new SchemaBuilder().add("c", MinorType.INT).addArray("a", MinorType.INT).buildSchema();
    final ExtendableRowSet rs1 = fixture.rowSet(schema);
    final RowSetWriter writer = rs1.writer();
    writer.scalar(0).setInt(10);
    final ScalarWriter array = writer.array(1).scalar();
    array.setInt(100);
    array.setInt(110);
    writer.save();
    writer.scalar(0).setInt(20);
    array.setInt(200);
    array.setInt(120);
    array.setInt(220);
    writer.save();
    writer.scalar(0).setInt(30);
    writer.save();
    final SingleRowSet result = writer.done();
    final RowSetReader reader = result.reader();
    final ArrayReader arrayReader = reader.array(1);
    final ScalarReader elementReader = arrayReader.scalar();
    assertTrue(reader.next());
    assertEquals(10, reader.scalar(0).getInt());
    assertEquals(2, arrayReader.size());
    assertTrue(arrayReader.next());
    assertEquals(100, elementReader.getInt());
    assertTrue(arrayReader.next());
    assertEquals(110, elementReader.getInt());
    assertTrue(reader.next());
    assertEquals(20, reader.scalar(0).getInt());
    assertEquals(3, arrayReader.size());
    assertTrue(arrayReader.next());
    assertEquals(200, elementReader.getInt());
    assertTrue(arrayReader.next());
    assertEquals(120, elementReader.getInt());
    assertTrue(arrayReader.next());
    assertEquals(220, elementReader.getInt());
    assertTrue(reader.next());
    assertEquals(30, reader.scalar(0).getInt());
    assertEquals(0, arrayReader.size());
    assertFalse(reader.next());
    final SingleRowSet rs2 = fixture.rowSetBuilder(schema).addRow(10, intArray(100, 110)).addRow(20, intArray(200, 120, 220)).addRow(30, null).build();
    RowSetUtilities.verify(rs1, rs2);
}
Also used : 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) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)257 Test (org.junit.Test)241 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)237 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)234 SubOperatorTest (org.apache.drill.test.SubOperatorTest)207 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)69 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)62 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)61 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)54 ValueVector (org.apache.drill.exec.vector.ValueVector)32 EvfTest (org.apache.drill.categories.EvfTest)30 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)29 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)27 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)27 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)27 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)25 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)24 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)23 VectorContainer (org.apache.drill.exec.record.VectorContainer)22 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)22