Search in sources :

Example 6 with ExtendableRowSet

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

the class TestFillEmpties method doFillEmptiesScalar.

private void doFillEmptiesScalar(MajorType majorType) {
    TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
    ExtendableRowSet rs = fixture.rowSet(schema);
    RowSetWriter writer = rs.writer();
    ScalarWriter colWriter = writer.scalar(0);
    ValueType valueType = colWriter.valueType();
    boolean nullable = majorType.getMode() == DataMode.OPTIONAL;
    for (int i = 0; i < ROW_COUNT; i++) {
        if (i % 5 == 0) {
            colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
        }
        writer.save();
    }
    SingleRowSet result = writer.done();
    RowSetReader reader = result.reader();
    ScalarReader colReader = reader.scalar(0);
    MinorType type = majorType.getMinorType();
    boolean isVariable = (type == MinorType.VARCHAR || type == MinorType.VAR16CHAR || type == MinorType.VARBINARY);
    for (int i = 0; i < ROW_COUNT; i++) {
        assertTrue(reader.next());
        if (i % 5 != 0) {
            if (nullable) {
                // Nullable types fill with nulls.
                assertTrue(colReader.isNull());
                continue;
            }
            if (isVariable) {
                // Variable width types fill with a zero-length value.
                assertEquals(0, colReader.getBytes().length);
                continue;
            }
        }
        // All other types fill with zero-bytes, interpreted as some form
        // of zero for each type.
        Object actual = colReader.getObject();
        Object expected = RowSetUtilities.testDataFromInt(valueType, majorType, i % 5 == 0 ? i : 0);
        RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "]", 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) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)

Example 7 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet 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 8 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet 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 9 with ExtendableRowSet

use of org.apache.drill.test.rowSet.RowSet.ExtendableRowSet 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 10 with ExtendableRowSet

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

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