Search in sources :

Example 1 with RowSetWriter

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

the class TestBatchSerialization method makeRowSet.

public SingleRowSet makeRowSet(TupleMetadata 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.exec.physical.rowSet.RowSetWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)

Example 2 with RowSetWriter

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

the class TestBatchSerialization method makeNullableRowSet.

public SingleRowSet makeNullableRowSet(TupleMetadata schema, int rowCount) {
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer(rowCount);
    for (int i = 0; i < rowCount; i++) {
        if (i % 2 == 0) {
            RowSetUtilities.setFromInt(writer, 0, i);
        } else {
            writer.scalar(0).setNull();
        }
        writer.save();
    }
    writer.done();
    return rowSet;
}
Also used : RowSetWriter(org.apache.drill.exec.physical.rowSet.RowSetWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)

Example 3 with RowSetWriter

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

the class TestColumnConverter method testScalarConverter.

/**
 * Test doing type conversion using (ad-hoc) properties on the
 * column metadata to drive conversion. Verifies that the properties
 * are available to the converter.
 */
@Test
public void testScalarConverter() {
    // Defined schema for scan output
    TupleMetadata outputSchema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.INT).buildSchema();
    // Writer
    RowSetWriter writer = makeWriter(outputSchema);
    // Row and column formats
    TupleNameSpace<MockConverter> rowFormat = new TupleNameSpace<>();
    rowFormat.add(writer.column(0).schema().name(), new MockIntConverter(writer.column(0)));
    rowFormat.add(writer.column(1).schema().name(), new MockArrayConverter(writer.column(1)));
    // Write data as both a string as an integer
    MockSource source = new MockSource();
    for (int i = 0; i < 2; i++) {
        // Simulate a row
        source.rowNo = i + 1;
        for (int j = 0; j < rowFormat.count(); j++) {
            rowFormat.get(j).setColumn(source);
        }
        writer.save();
    }
    // Verify
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(10, intArray(101, 102, 103)).addRow(20, intArray(201, 202, 203)).build();
    RowSetUtilities.verify(expected, writer.done());
}
Also used : RowSetWriter(org.apache.drill.exec.physical.rowSet.RowSetWriter) 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) TupleNameSpace(org.apache.drill.exec.record.metadata.TupleNameSpace) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with RowSetWriter

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

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);
    }
    TupleMetadata schema = builder.buildSchema();
    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();
    SortImpl sort = makeSortImpl(fixture, Ordering.ORDER_ASC, Ordering.NULLS_UNSPECIFIED);
    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.exec.physical.rowSet.RowSetWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SortResults(org.apache.drill.exec.physical.impl.xsort.SortImpl.SortResults) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)

Example 5 with RowSetWriter

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

the class TestCopier method makeDataSet.

public static SingleRowSet makeDataSet(TupleMetadata 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.exec.physical.rowSet.RowSetWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)

Aggregations

RowSetWriter (org.apache.drill.exec.physical.rowSet.RowSetWriter)5 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)4 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)2 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)2 SortResults (org.apache.drill.exec.physical.impl.xsort.SortImpl.SortResults)1 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)1 TupleNameSpace (org.apache.drill.exec.record.metadata.TupleNameSpace)1 SubOperatorTest (org.apache.drill.test.SubOperatorTest)1 Test (org.junit.Test)1