Search in sources :

Example 6 with RowSetWriter

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

the class TestCopier method makeDataSet.

public static SingleRowSet makeDataSet(BatchSchema schema, int first, int step, int count) {
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer(count);
    int value = first;
    for (int i = 0; i < count; i++, value += step) {
        RowSetUtilities.setFromInt(writer, 0, value);
        writer.scalar(1).setString(Integer.toString(value));
        writer.save();
    }
    writer.done();
    return rowSet;
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)

Example 7 with RowSetWriter

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

the class TestSortImpl method runWideRowsTest.

/**
 * Run a test using wide rows. This stresses the "copier" portion of the sort
 * and allows us to test the original generated copier and the revised "generic"
 * copier.
 *
 * @param fixture operator test fixture
 * @param colCount number of data (non-key) columns
 * @param rowCount number of rows to generate
 */
public void runWideRowsTest(OperatorFixture fixture, int colCount, int rowCount) {
    SchemaBuilder builder = new SchemaBuilder().add("key", MinorType.INT);
    for (int i = 0; i < colCount; i++) {
        builder.add("col" + (i + 1), MinorType.INT);
    }
    BatchSchema schema = builder.build();
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer(rowCount);
    for (int i = 0; i < rowCount; i++) {
        writer.set(0, i);
        for (int j = 0; j < colCount; j++) {
            writer.set(j + 1, i * 100_000 + j);
        }
        writer.save();
    }
    writer.done();
    VectorContainer dest = new VectorContainer();
    SortImpl sort = makeSortImpl(fixture, Ordering.ORDER_ASC, Ordering.NULLS_UNSPECIFIED, dest);
    sort.setSchema(rowSet.container().getSchema());
    sort.addBatch(rowSet.vectorAccessible());
    SortResults results = sort.startMerge();
    if (results.getContainer() != dest) {
        dest.clear();
        dest = results.getContainer();
    }
    assertTrue(results.next());
    assertFalse(results.next());
    results.close();
    dest.clear();
    sort.close();
    sort.opContext().close();
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SortResults(org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 8 with RowSetWriter

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

the class TestBatchSerialization method makeRowSet.

public SingleRowSet makeRowSet(BatchSchema schema, int rowCount) {
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer(rowCount);
    for (int i = 0; i < rowCount; i++) {
        RowSetUtilities.setFromInt(writer, 0, i);
        writer.save();
    }
    writer.done();
    return rowSet;
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)

Example 9 with RowSetWriter

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

the class RowSetTest method testTopFixedWidthArray.

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

use of org.apache.drill.test.rowSet.RowSetWriter 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)

Aggregations

ExtendableRowSet (org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)13 RowSetWriter (org.apache.drill.test.rowSet.RowSetWriter)13 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)10 SubOperatorTest (org.apache.drill.test.SubOperatorTest)7 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)7 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)7 Test (org.junit.Test)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)5 BatchSchema (org.apache.drill.exec.record.BatchSchema)4 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)4 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)3 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 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 SortResults (org.apache.drill.exec.physical.impl.xsort.managed.SortImpl.SortResults)1