Search in sources :

Example 96 with VectorContainer

use of org.apache.drill.exec.record.VectorContainer 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 97 with VectorContainer

use of org.apache.drill.exec.record.VectorContainer 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 98 with VectorContainer

use of org.apache.drill.exec.record.VectorContainer in project drill by axbaretto.

the class AbstractGenericCopierTest method testAppendRecords.

@Test
public void testAppendRecords() throws SchemaChangeException {
    try (RootAllocator allocator = new RootAllocator(10_000_000)) {
        final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
        final RowSet srcRowSet = createSrcRowSet(allocator);
        final RowSet destRowSet = new RowSetBuilder(allocator, batchSchema).build();
        final VectorContainer destContainer = destRowSet.container();
        final Copier copier = createCopier();
        final RowSet expectedRowSet = createExpectedRowset(allocator);
        copier.setup(new RowSetBatch(srcRowSet), destContainer);
        copier.appendRecord(0);
        copier.appendRecords(1, 2);
        try {
            new RowSetComparison(expectedRowSet).verify(destRowSet);
        } finally {
            srcRowSet.clear();
            if (srcRowSet instanceof RowSet.HyperRowSet) {
                ((RowSet.HyperRowSet) srcRowSet).getSv4().clear();
            }
            destRowSet.clear();
            expectedRowSet.clear();
        }
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RootAllocator(org.apache.drill.exec.memory.RootAllocator) RowSetBatch(org.apache.drill.test.rowSet.RowSetBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test)

Example 99 with VectorContainer

use of org.apache.drill.exec.record.VectorContainer in project drill by axbaretto.

the class GenericSV4CopierTest method createSrcRowSet.

@Override
public RowSet createSrcRowSet(RootAllocator allocator) throws SchemaChangeException {
    final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
    final DrillBuf drillBuf = allocator.buffer(4 * 3);
    final SelectionVector4 sv4 = new SelectionVector4(drillBuf, 3, Character.MAX_VALUE);
    final VectorContainer batch1 = new RowSetBuilder(allocator, batchSchema).addRow(row1()).addRow(row4()).build().container();
    final VectorContainer batch2 = new RowSetBuilder(allocator, batchSchema).addRow(row2()).addRow(row5()).addRow(row3()).build().container();
    final ExpandableHyperContainer hyperContainer = new ExpandableHyperContainer(batch1);
    hyperContainer.addBatch(batch2);
    sv4.set(0, 0, 0);
    sv4.set(1, 1, 0);
    sv4.set(2, 1, 2);
    return new HyperRowSetImpl(hyperContainer, sv4);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) ExpandableHyperContainer(org.apache.drill.exec.record.ExpandableHyperContainer) BatchSchema(org.apache.drill.exec.record.BatchSchema) HyperRowSetImpl(org.apache.drill.test.rowSet.HyperRowSetImpl) DrillBuf(io.netty.buffer.DrillBuf) SelectionVector4(org.apache.drill.exec.record.selection.SelectionVector4) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 100 with VectorContainer

use of org.apache.drill.exec.record.VectorContainer in project drill by axbaretto.

the class DumpCat method doBatch.

/**
 * Batch mode:
 * $drill-dumpcat --file=local:///tmp/drilltrace/[queryid]_[tag]_[majorid]_[minor]_[operator] --batch=123 --include-headers=true
 * Records: 1/1
 * Average Record Size: 8 bytes
 * Total Data Size: 8 bytes
 * Schema Information
 * name: col1, minor_type: int4, data_mode: nullable
 * name: col2, minor_type: int4, data_mode: non-nullable
 * @param targetBatchNum
 * @throws Exception
 */
protected void doBatch(FileInputStream input, int targetBatchNum, boolean showHeader) throws Exception {
    int batchNum = -1;
    VectorAccessibleSerializable vcSerializable = null;
    while (input.available() > 0 && batchNum++ < targetBatchNum) {
        vcSerializable = new VectorAccessibleSerializable(DumpCat.allocator);
        vcSerializable.readFromStream(input);
        if (batchNum != targetBatchNum) {
            final VectorContainer vectorContainer = vcSerializable.get();
            vectorContainer.zeroVectors();
        }
    }
    if (batchNum < targetBatchNum) {
        System.out.println(String.format("Wrong input of batch # ! Total # of batch in the file is %d. Please input a number 0..%d as batch #", batchNum + 1, batchNum));
        input.close();
        System.exit(-1);
    }
    if (vcSerializable != null) {
        showSingleBatch(vcSerializable, showHeader);
        final VectorContainer vectorContainer = vcSerializable.get();
        vectorContainer.zeroVectors();
    }
}
Also used : VectorAccessibleSerializable(org.apache.drill.exec.cache.VectorAccessibleSerializable) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

VectorContainer (org.apache.drill.exec.record.VectorContainer)178 Test (org.junit.Test)75 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)63 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)62 SubOperatorTest (org.apache.drill.test.SubOperatorTest)60 ValueVector (org.apache.drill.exec.vector.ValueVector)44 RowSetTest (org.apache.drill.categories.RowSetTest)41 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)39 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)31 BatchSchema (org.apache.drill.exec.record.BatchSchema)27 ArrayList (java.util.ArrayList)23 MaterializedField (org.apache.drill.exec.record.MaterializedField)23 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)18 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)17 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)16 UserException (org.apache.drill.common.exceptions.UserException)15 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)15 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)15 OperatorTest (org.apache.drill.categories.OperatorTest)14 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)14