Search in sources :

Example 46 with SingleRowSet

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

the class RowSetTest method testFloatRW.

private void testFloatRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT4).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0F).add(Float.MAX_VALUE).add(Float.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getDouble(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Float.MAX_VALUE, reader.column(0).getDouble(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Float.MIN_VALUE, reader.column(0).getDouble(), 0.000001);
    assertFalse(reader.next());
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader)

Example 47 with SingleRowSet

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

the class TestOperatorRecordBatch method testSchemaChange.

@Test
public void testSchemaChange() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").build();
    VectorContainer container = rs.container();
    MockOperatorExec opExec = new MockOperatorExec(container);
    int schemaVersion = opExec.batchAccessor().schemaVersion();
    // Be tidy: start at 1.
    assertEquals(1, schemaVersion);
    // Changing data does not trigger schema change
    container.zeroVectors();
    opExec.batchAccessor.setContainer(container);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Different container, same vectors, does not trigger a change
    VectorContainer c2 = new VectorContainer(fixture.allocator());
    for (VectorWrapper<?> vw : container) {
        c2.add(vw.getValueVector());
    }
    c2.buildSchema(SelectionVectorMode.NONE);
    opExec.batchAccessor.setContainer(c2);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    opExec.batchAccessor.setContainer(container);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Replacing a vector with another of the same type does trigger
    // a change.
    VectorContainer c3 = new VectorContainer(fixture.allocator());
    c3.add(container.getValueVector(0).getValueVector());
    c3.add(TypeHelper.getNewVector(container.getValueVector(1).getValueVector().getField(), fixture.allocator(), null));
    c3.buildSchema(SelectionVectorMode.NONE);
    opExec.batchAccessor.setContainer(c3);
    assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
    schemaVersion = opExec.batchAccessor().schemaVersion();
    // No change if same schema again
    opExec.batchAccessor.setContainer(c3);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Adding a vector triggers a change
    MaterializedField c = SchemaBuilder.columnSchema("c", MinorType.INT, DataMode.OPTIONAL);
    c3.add(TypeHelper.getNewVector(c, fixture.allocator(), null));
    c3.buildSchema(SelectionVectorMode.NONE);
    opExec.batchAccessor.setContainer(c3);
    assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
    schemaVersion = opExec.batchAccessor().schemaVersion();
    // No change if same schema again
    opExec.batchAccessor.setContainer(c3);
    assertEquals(schemaVersion, opExec.batchAccessor().schemaVersion());
    // Removing a vector triggers a change
    c3.remove(c3.getValueVector(2).getValueVector());
    c3.buildSchema(SelectionVectorMode.NONE);
    assertEquals(2, c3.getNumberOfColumns());
    opExec.batchAccessor.setContainer(c3);
    assertEquals(schemaVersion + 1, opExec.batchAccessor().schemaVersion());
    schemaVersion = opExec.batchAccessor().schemaVersion();
    // Clean up
    opExec.close();
    c2.clear();
    c3.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 48 with SingleRowSet

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

the class TestResultSetLoaderMaps method testMapEvolution.

/**
 * Create schema with a map, then add columns to the map
 * after delivering the first batch. The new columns should appear
 * in the second-batch output.
 */
@Test
public void testMapEvolution() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("b", MinorType.VARCHAR).resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    assertEquals(3, rsLoader.schemaVersion());
    RowSetLoader rootWriter = rsLoader.writer();
    rsLoader.startBatch();
    rootWriter.addRow(10, objArray("fred")).addRow(20, objArray("barney"));
    RowSet actual = fixture.wrap(rsLoader.harvest());
    assertEquals(3, rsLoader.schemaVersion());
    assertEquals(2, actual.rowCount());
    // Validate first batch
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray("fred")).addRow(20, objArray("barney")).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
    // Add three columns in the second batch. One before
    // the batch starts, one before the first row, and one after
    // the first row.
    TupleWriter mapWriter = rootWriter.tuple("m");
    mapWriter.addColumn(SchemaBuilder.columnSchema("c", MinorType.INT, DataMode.REQUIRED));
    rsLoader.startBatch();
    mapWriter.addColumn(SchemaBuilder.columnSchema("d", MinorType.BIGINT, DataMode.REQUIRED));
    rootWriter.addRow(30, objArray("wilma", 130, 130_000L));
    mapWriter.addColumn(SchemaBuilder.columnSchema("e", MinorType.VARCHAR, DataMode.REQUIRED));
    rootWriter.addRow(40, objArray("betty", 140, 140_000L, "bam-bam"));
    actual = fixture.wrap(rsLoader.harvest());
    assertEquals(6, rsLoader.schemaVersion());
    assertEquals(2, actual.rowCount());
    // Validate first batch
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("b", MinorType.VARCHAR).add("c", MinorType.INT).add("d", MinorType.BIGINT).add("e", MinorType.VARCHAR).resumeSchema().buildSchema();
    expected = fixture.rowSetBuilder(expectedSchema).addRow(30, objArray("wilma", 130, 130_000L, "")).addRow(40, objArray("betty", 140, 140_000L, "bam-bam")).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
    rsLoader.close();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.rowSet.ResultSetLoader) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetLoader(org.apache.drill.exec.physical.rowSet.RowSetLoader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 49 with SingleRowSet

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

the class TestResultSetLoaderMaps method testBasics.

@Test
public void testBasics() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).resumeSchema().add("e", MinorType.VARCHAR).buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    // Verify structure and schema
    assertEquals(5, rsLoader.schemaVersion());
    TupleMetadata actualSchema = rootWriter.schema();
    assertEquals(3, actualSchema.size());
    assertTrue(actualSchema.metadata(1).isMap());
    assertEquals(2, actualSchema.metadata("m").mapSchema().size());
    assertEquals(2, actualSchema.column("m").getChildren().size());
    rsLoader.startBatch();
    // Write a row the way that clients will do.
    ScalarWriter aWriter = rootWriter.scalar("a");
    TupleWriter mWriter = rootWriter.tuple("m");
    ScalarWriter cWriter = mWriter.scalar("c");
    ScalarWriter dWriter = mWriter.scalar("d");
    ScalarWriter eWriter = rootWriter.scalar("e");
    rootWriter.start();
    aWriter.setInt(10);
    cWriter.setInt(110);
    dWriter.setString("fred");
    eWriter.setString("pebbles");
    rootWriter.save();
    try {
        mWriter.addColumn(SchemaBuilder.columnSchema("c", MinorType.INT, DataMode.OPTIONAL));
        fail();
    } catch (IllegalArgumentException e) {
    // Expected
    }
    // Write another using the test-time conveniences
    rootWriter.addRow(20, objArray(210, "barney"), "bam-bam");
    // Harvest the batch
    RowSet actual = fixture.wrap(rsLoader.harvest());
    assertEquals(5, rsLoader.schemaVersion());
    assertEquals(2, actual.rowCount());
    // Validate data
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(110, "fred"), "pebbles").addRow(20, objArray(210, "barney"), "bam-bam").build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
    rsLoader.close();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.rowSet.ResultSetLoader) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetLoader(org.apache.drill.exec.physical.rowSet.RowSetLoader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 50 with SingleRowSet

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

the class TestResultSetLoaderMaps method testNestedMapsNullable.

/**
 * Create nested maps. Then, add columns to each map
 * on the fly. This time, with nullable types.
 */
@Test
public void testNestedMapsNullable() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMap("m1").addNullable("b", MinorType.VARCHAR).addMap("m2").addNullable("c", MinorType.VARCHAR).resumeMap().resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    rsLoader.startBatch();
    rootWriter.addRow(10, objArray("b1", objArray("c1")));
    // Validate first batch
    RowSet actual = fixture.wrap(rsLoader.harvest());
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray("b1", objArray("c1"))).build();
    // actual.print();
    // expected.print();
    new RowSetComparison(expected).verifyAndClearAll(actual);
    // Now add columns in the second batch.
    rsLoader.startBatch();
    rootWriter.addRow(20, objArray("b2", objArray("c2")));
    TupleWriter m1Writer = rootWriter.tuple("m1");
    m1Writer.addColumn(SchemaBuilder.columnSchema("d", MinorType.VARCHAR, DataMode.OPTIONAL));
    TupleWriter m2Writer = m1Writer.tuple("m2");
    m2Writer.addColumn(SchemaBuilder.columnSchema("e", MinorType.VARCHAR, DataMode.OPTIONAL));
    rootWriter.addRow(30, objArray("b3", objArray("c3", "e3"), "d3"));
    // And another set while the write proceeds.
    m1Writer.addColumn(SchemaBuilder.columnSchema("f", MinorType.VARCHAR, DataMode.OPTIONAL));
    m2Writer.addColumn(SchemaBuilder.columnSchema("g", MinorType.VARCHAR, DataMode.OPTIONAL));
    rootWriter.addRow(40, objArray("b4", objArray("c4", "e4", "g4"), "d4", "e4"));
    // Validate second batch
    actual = fixture.wrap(rsLoader.harvest());
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m1").addNullable("b", MinorType.VARCHAR).addMap("m2").addNullable("c", MinorType.VARCHAR).addNullable("e", MinorType.VARCHAR).addNullable("g", MinorType.VARCHAR).resumeMap().addNullable("d", MinorType.VARCHAR).addNullable("f", MinorType.VARCHAR).resumeSchema().buildSchema();
    expected = fixture.rowSetBuilder(expectedSchema).addRow(20, objArray("b2", objArray("c2", null, null), null, null)).addRow(30, objArray("b3", objArray("c3", "e3", null), "d3", null)).addRow(40, objArray("b4", objArray("c4", "e4", "g4"), "d4", "e4")).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
    rsLoader.close();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.rowSet.ResultSetLoader) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) RowSetLoader(org.apache.drill.exec.physical.rowSet.RowSetLoader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)93 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)78 Test (org.junit.Test)74 BatchSchema (org.apache.drill.exec.record.BatchSchema)64 SubOperatorTest (org.apache.drill.test.SubOperatorTest)57 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)38 RowSet (org.apache.drill.test.rowSet.RowSet)27 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)25 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)25 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)22 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)17 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)16 ValueVector (org.apache.drill.exec.vector.ValueVector)13 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)13 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)13 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)10 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)10 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)10 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)9 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)9