Search in sources :

Example 11 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.

the class RowSetTest method testRowBounds.

/**
 * Test filling a row set up to the maximum number of rows.
 * Values are small enough to prevent filling to the
 * maximum buffer size.
 */
@Test
public void testRowBounds() {
    BatchSchema batchSchema = new SchemaBuilder().add("a", MinorType.INT).build();
    ExtendableRowSet rs = fixture.rowSet(batchSchema);
    RowSetWriter writer = rs.writer();
    int count = 0;
    while (!writer.isFull()) {
        writer.scalar(0).setInt(count++);
        writer.save();
    }
    writer.done();
    assertEquals(ValueVector.MAX_ROW_COUNT, count);
    // The writer index points past the writable area.
    // But, this is fine, the valid() method says we can't
    // write at this location.
    assertEquals(ValueVector.MAX_ROW_COUNT, writer.rowIndex());
    assertEquals(ValueVector.MAX_ROW_COUNT, rs.rowCount());
    rs.clear();
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 12 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.

the class RowSetTest method testScalarStructure.

/**
 * Test the simplest constructs: a row with top-level scalar
 * columns.
 * <p>
 * The focus here is the structure of the readers and writers, along
 * with the row set loader and verifier that use those constructs.
 * That is, while this test uses the int vector, this test is not
 * focused on that vector.
 */
@Test
public void testScalarStructure() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer();
    // Required Int
    // Verify the invariants of the "full" and "simple" access paths
    assertEquals(ObjectType.SCALAR, writer.column("a").type());
    assertSame(writer.column("a"), writer.column(0));
    assertSame(writer.scalar("a"), writer.scalar(0));
    assertSame(writer.column("a").scalar(), writer.scalar("a"));
    assertSame(writer.column(0).scalar(), writer.scalar(0));
    assertEquals(ValueType.INTEGER, writer.scalar(0).valueType());
    try {
        writer.column(0).array();
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    try {
        writer.column(0).tuple();
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    // Test the various ways to get at the scalar writer.
    writer.column("a").scalar().setInt(10);
    writer.save();
    writer.scalar("a").setInt(20);
    writer.save();
    writer.column(0).scalar().setInt(30);
    writer.save();
    writer.scalar(0).setInt(40);
    writer.save();
    // Finish the row set and get a reader.
    SingleRowSet actual = writer.done();
    RowSetReader reader = actual.reader();
    // Verify invariants
    assertEquals(ObjectType.SCALAR, reader.column(0).type());
    assertSame(reader.column("a"), reader.column(0));
    assertSame(reader.scalar("a"), reader.scalar(0));
    assertSame(reader.column("a").scalar(), reader.scalar("a"));
    assertSame(reader.column(0).scalar(), reader.scalar(0));
    assertEquals(ValueType.INTEGER, reader.scalar(0).valueType());
    // Test various accessors: full and simple
    assertTrue(reader.next());
    assertEquals(10, reader.column("a").scalar().getInt());
    assertTrue(reader.next());
    assertEquals(20, reader.scalar("a").getInt());
    assertTrue(reader.next());
    assertEquals(30, reader.column(0).scalar().getInt());
    assertTrue(reader.next());
    assertEquals(40, reader.scalar(0).getInt());
    assertFalse(reader.next());
    // Test the above again via the writer and reader
    // utility classes.
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10).addRow(20).addRow(30).addRow(40).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 13 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.

the class RowSetTest method testScalarArrayStructure.

/**
 * Test a record with a top level array. The focus here is on the
 * scalar array structure.
 *
 * @throws VectorOverflowException should never occur
 */
@Test
public void testScalarArrayStructure() {
    TupleMetadata schema = new SchemaBuilder().addArray("a", MinorType.INT).buildSchema();
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer();
    // Repeated Int
    // Verify the invariants of the "full" and "simple" access paths
    assertEquals(ObjectType.ARRAY, writer.column("a").type());
    assertSame(writer.column("a"), writer.column(0));
    assertSame(writer.array("a"), writer.array(0));
    assertSame(writer.column("a").array(), writer.array("a"));
    assertSame(writer.column(0).array(), writer.array(0));
    assertEquals(ObjectType.SCALAR, writer.column("a").array().entry().type());
    assertEquals(ObjectType.SCALAR, writer.column("a").array().entryType());
    assertSame(writer.array(0).entry().scalar(), writer.array(0).scalar());
    assertEquals(ValueType.INTEGER, writer.array(0).scalar().valueType());
    try {
        writer.column(0).scalar();
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    try {
        writer.column(0).tuple();
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    // Write some data
    ScalarWriter intWriter = writer.array("a").scalar();
    intWriter.setInt(10);
    intWriter.setInt(11);
    writer.save();
    intWriter.setInt(20);
    intWriter.setInt(21);
    intWriter.setInt(22);
    writer.save();
    intWriter.setInt(30);
    writer.save();
    intWriter.setInt(40);
    intWriter.setInt(41);
    writer.save();
    // Finish the row set and get a reader.
    SingleRowSet actual = writer.done();
    RowSetReader reader = actual.reader();
    // Verify the invariants of the "full" and "simple" access paths
    assertEquals(ObjectType.ARRAY, writer.column("a").type());
    assertSame(reader.column("a"), reader.column(0));
    assertSame(reader.array("a"), reader.array(0));
    assertSame(reader.column("a").array(), reader.array("a"));
    assertSame(reader.column(0).array(), reader.array(0));
    assertEquals(ObjectType.SCALAR, reader.column("a").array().entryType());
    assertEquals(ValueType.INTEGER, reader.array(0).elements().valueType());
    // Read and verify the rows
    ScalarElementReader intReader = reader.array(0).elements();
    assertTrue(reader.next());
    assertEquals(2, intReader.size());
    assertEquals(10, intReader.getInt(0));
    assertEquals(11, intReader.getInt(1));
    assertTrue(reader.next());
    assertEquals(3, intReader.size());
    assertEquals(20, intReader.getInt(0));
    assertEquals(21, intReader.getInt(1));
    assertEquals(22, intReader.getInt(2));
    assertTrue(reader.next());
    assertEquals(1, intReader.size());
    assertEquals(30, intReader.getInt(0));
    assertTrue(reader.next());
    assertEquals(2, intReader.size());
    assertEquals(40, intReader.getInt(0));
    assertEquals(41, intReader.getInt(1));
    assertFalse(reader.next());
    // Test the above again via the writer and reader
    // utility classes.
    SingleRowSet expected = fixture.rowSetBuilder(schema).addSingleCol(intArray(10, 11)).addSingleCol(intArray(20, 21, 22)).addSingleCol(intArray(30)).addSingleCol(intArray(40, 41)).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ScalarElementReader(org.apache.drill.exec.vector.accessor.ScalarElementReader) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 14 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet in project drill by axbaretto.

the class TestFillEmpties method dofillEmptiesRepeated.

private void dofillEmptiesRepeated(MajorType majorType) {
    TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
    ExtendableRowSet rs = fixture.rowSet(schema);
    RowSetWriter writer = rs.writer();
    ScalarWriter colWriter = writer.array(0).scalar();
    ValueType valueType = colWriter.valueType();
    for (int i = 0; i < ROW_COUNT; i++) {
        if (i % 5 == 0) {
            // Write two values so we can exercise a bit of the array logic.
            colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
            colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i + 1));
        }
        writer.save();
    }
    SingleRowSet result = writer.done();
    RowSetReader reader = result.reader();
    ScalarElementReader colReader = reader.array(0).elements();
    for (int i = 0; i < ROW_COUNT; i++) {
        assertTrue(reader.next());
        if (i % 5 != 0) {
            // Empty arrays are defined to be the same as a zero-length array.
            assertEquals(0, colReader.size());
        } else {
            for (int j = 0; j < 2; j++) {
                Object actual = colReader.getObject(j);
                Object expected = RowSetUtilities.testDataFromInt(valueType, majorType, i + j);
                RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "][" + j + "]", valueType, expected, actual);
            }
        }
    }
    result.clear();
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) ValueType(org.apache.drill.exec.vector.accessor.ValueType) ScalarElementReader(org.apache.drill.exec.vector.accessor.ScalarElementReader) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)

Aggregations

ExtendableRowSet (org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)14 RowSetWriter (org.apache.drill.test.rowSet.RowSetWriter)13 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)10 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)8 Test (org.junit.Test)8 SubOperatorTest (org.apache.drill.test.SubOperatorTest)7 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)7 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)6 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)6 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)6 BatchSchema (org.apache.drill.exec.record.BatchSchema)5 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)4 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)3 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)2 ArrayWriter (org.apache.drill.exec.vector.accessor.ArrayWriter)2 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)2 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)2 ValueType (org.apache.drill.exec.vector.accessor.ValueType)2 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1