Search in sources :

Example 6 with SingleRowSet

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

the class RowSetTest method testSmallIntRW.

private void testSmallIntRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.SMALLINT).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0).add(Short.MAX_VALUE).add(Short.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getInt());
    assertTrue(reader.next());
    assertEquals(Short.MAX_VALUE, reader.column(0).getInt());
    assertTrue(reader.next());
    assertEquals(Short.MIN_VALUE, reader.column(0).getInt());
    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 7 with SingleRowSet

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

the class TestBatchSerialization method verifySerialize.

/**
 * Verify serialize and deserialize. Need to pass both the
 * input and expected (even though the expected should be the same
 * data as the input) because the act of serializing clears the
 * input for obscure historical reasons.
 *
 * @param rowSet
 * @param expected
 * @throws IOException
 */
private void verifySerialize(SingleRowSet rowSet, SingleRowSet expected) throws IOException {
    File dir = DirTestWatcher.createTempDir(dirTestWatcher.getDir());
    FileChannel channel = FileChannel.open(new File(dir, "serialize.dat").toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    VectorSerializer.Writer writer = VectorSerializer.writer(channel);
    VectorContainer container = rowSet.container();
    SelectionVector2 sv2 = rowSet.getSv2();
    writer.write(container, sv2);
    container.clear();
    if (sv2 != null) {
        sv2.clear();
    }
    writer.close();
    File outFile = new File(dir, "serialize.dat");
    assertTrue(outFile.exists());
    assertTrue(outFile.isFile());
    RowSet result;
    try (InputStream in = new BufferedInputStream(new FileInputStream(outFile))) {
        Reader reader = VectorSerializer.reader(fixture.allocator(), in);
        result = fixture.wrap(reader.read(), reader.sv2());
    }
    new RowSetComparison(expected).verifyAndClearAll(result);
    outFile.delete();
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BufferedInputStream(java.io.BufferedInputStream) FileChannel(java.nio.channels.FileChannel) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) SelectionVector2(org.apache.drill.exec.record.selection.SelectionVector2) Reader(org.apache.drill.exec.cache.VectorSerializer.Reader) File(java.io.File) FileInputStream(java.io.FileInputStream) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 8 with SingleRowSet

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

the class TestOperatorRecordBatch method testBatchAccessor.

/**
 * The record batch abstraction has a bunch of methods to work with a vector container.
 * Rather than simply exposing the container itself, the batch instead exposes various
 * container operations. Probably an artifact of its history. In any event, make
 * sure those methods are passed through to the container accessor.
 */
@Test
public void testBatchAccessor() {
    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();
    MockOperatorExec opExec = new MockOperatorExec(rs.container());
    opExec.nextCalls = 1;
    try (OperatorRecordBatch opBatch = makeOpBatch(opExec)) {
        assertEquals(IterOutcome.OK_NEW_SCHEMA, opBatch.next());
        assertEquals(schema, opBatch.getSchema());
        assertEquals(2, opBatch.getRecordCount());
        assertSame(rs.container(), opBatch.getOutgoingContainer());
        Iterator<VectorWrapper<?>> iter = opBatch.iterator();
        assertEquals("a", iter.next().getValueVector().getField().getName());
        assertEquals("b", iter.next().getValueVector().getField().getName());
        // Not a full test of the schema path; just make sure that the
        // pass-through to the Vector Container works.
        SchemaPath path = SchemaPath.create(NamePart.newBuilder().setName("a").build());
        TypedFieldId id = opBatch.getValueVectorId(path);
        assertEquals(MinorType.INT, id.getFinalType().getMinorType());
        assertEquals(1, id.getFieldIds().length);
        assertEquals(0, id.getFieldIds()[0]);
        path = SchemaPath.create(NamePart.newBuilder().setName("b").build());
        id = opBatch.getValueVectorId(path);
        assertEquals(MinorType.VARCHAR, id.getFinalType().getMinorType());
        assertEquals(1, id.getFieldIds().length);
        assertEquals(1, id.getFieldIds()[0]);
        // Sanity check of getValueAccessorById()
        VectorWrapper<?> w = opBatch.getValueAccessorById(IntVector.class, 0);
        assertNotNull(w);
        assertEquals("a", w.getValueVector().getField().getName());
        w = opBatch.getValueAccessorById(VarCharVector.class, 1);
        assertNotNull(w);
        assertEquals("b", w.getValueVector().getField().getName());
        try {
            opBatch.getSelectionVector2();
            fail();
        } catch (UnsupportedOperationException e) {
        // Expected
        }
        try {
            opBatch.getSelectionVector4();
            fail();
        } catch (UnsupportedOperationException e) {
        // Expected
        }
    } catch (Exception e) {
        fail(e.getMessage());
    }
    assertTrue(opExec.closeCalled);
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UserException(org.apache.drill.common.exceptions.UserException) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaPath(org.apache.drill.common.expression.SchemaPath) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 9 with SingleRowSet

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

the class TestOperatorRecordBatch method testSv2.

/**
 * Test that an SV2 is properly handled by the proper container accessor.
 */
@Test
public void testSv2() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").withSv2().build();
    ContainerAndSv2Accessor accessor = new ContainerAndSv2Accessor();
    accessor.setContainer(rs.container());
    accessor.setSelectionVector(rs.getSv2());
    MockOperatorExec opExec = new MockOperatorExec(accessor);
    opExec.nextCalls = 1;
    try (OperatorRecordBatch opBatch = makeOpBatch(opExec)) {
        assertEquals(IterOutcome.OK_NEW_SCHEMA, opBatch.next());
        assertSame(rs.getSv2(), opBatch.getSelectionVector2());
    } catch (Exception e) {
        fail();
    }
    assertTrue(opExec.closeCalled);
    // Must release SV2
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) ContainerAndSv2Accessor(org.apache.drill.exec.physical.impl.protocol.VectorContainerAccessor.ContainerAndSv2Accessor) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) UserException(org.apache.drill.common.exceptions.UserException) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 10 with SingleRowSet

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

the class TestBatchValidator method testVariableCorruptFirst.

@Test
public void testVariableCorruptFirst() {
    BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
    SingleRowSet batch = fixture.rowSetBuilder(schema).addRow("x").addRow("y").addRow("z").build();
    zapOffset(batch, 0, 1);
    // Validator should catch the error.
    BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
    validator.validate();
    List<String> errors = validator.errors();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0).contains("Offset (0) must be 0"));
    batch.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) 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