Search in sources :

Example 1 with Accessor

use of org.apache.drill.exec.vector.NullableVarCharVector.Accessor in project drill by axbaretto.

the class TestSplitAndTransfer method test.

@Test
public void test() throws Exception {
    final DrillConfig drillConfig = DrillConfig.create();
    final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
    final MaterializedField field = MaterializedField.create("field", Types.optional(MinorType.VARCHAR));
    final NullableVarCharVector varCharVector = new NullableVarCharVector(field, allocator);
    varCharVector.allocateNew(10000, 1000);
    final int valueCount = 500;
    final String[] compareArray = new String[valueCount];
    final NullableVarCharVector.Mutator mutator = varCharVector.getMutator();
    for (int i = 0; i < valueCount; i += 3) {
        final String s = String.format("%010d", i);
        mutator.set(i, s.getBytes());
        compareArray[i] = s;
    }
    mutator.setValueCount(valueCount);
    final TransferPair tp = varCharVector.getTransferPair(allocator);
    final NullableVarCharVector newVarCharVector = (NullableVarCharVector) tp.getTo();
    final Accessor accessor = newVarCharVector.getAccessor();
    final int[][] startLengths = { { 0, 201 }, { 201, 200 }, { 401, 99 } };
    for (final int[] startLength : startLengths) {
        final int start = startLength[0];
        final int length = startLength[1];
        tp.splitAndTransfer(start, length);
        newVarCharVector.getMutator().setValueCount(length);
        for (int i = 0; i < length; i++) {
            final boolean expectedSet = ((start + i) % 3) == 0;
            if (expectedSet) {
                final byte[] expectedValue = compareArray[start + i].getBytes();
                assertFalse(accessor.isNull(i));
                assertArrayEquals(expectedValue, accessor.get(i));
            } else {
                assertTrue(accessor.isNull(i));
            }
        }
        newVarCharVector.clear();
    }
    varCharVector.close();
    allocator.close();
}
Also used : TransferPair(org.apache.drill.exec.record.TransferPair) MaterializedField(org.apache.drill.exec.record.MaterializedField) Accessor(org.apache.drill.exec.vector.NullableVarCharVector.Accessor) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) DrillConfig(org.apache.drill.common.config.DrillConfig) Test(org.junit.Test)

Example 2 with Accessor

use of org.apache.drill.exec.vector.NullableVarCharVector.Accessor in project drill by apache.

the class TestSplitAndTransfer method test.

@Test
public void test() throws Exception {
    final DrillConfig drillConfig = DrillConfig.create();
    final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig);
    final MaterializedField field = MaterializedField.create("field", Types.optional(MinorType.VARCHAR));
    final NullableVarCharVector varCharVector = new NullableVarCharVector(field, allocator);
    varCharVector.allocateNew(10000, 1000);
    final int valueCount = 500;
    final String[] compareArray = new String[valueCount];
    final NullableVarCharVector.Mutator mutator = varCharVector.getMutator();
    for (int i = 0; i < valueCount; i += 3) {
        final String s = String.format("%010d", i);
        mutator.set(i, s.getBytes());
        compareArray[i] = s;
    }
    mutator.setValueCount(valueCount);
    final TransferPair tp = varCharVector.getTransferPair(allocator);
    final NullableVarCharVector newVarCharVector = (NullableVarCharVector) tp.getTo();
    final Accessor accessor = newVarCharVector.getAccessor();
    final int[][] startLengths = { { 0, 201 }, { 201, 200 }, { 401, 99 } };
    for (final int[] startLength : startLengths) {
        final int start = startLength[0];
        final int length = startLength[1];
        tp.splitAndTransfer(start, length);
        newVarCharVector.getMutator().setValueCount(length);
        for (int i = 0; i < length; i++) {
            final boolean expectedSet = ((start + i) % 3) == 0;
            if (expectedSet) {
                final byte[] expectedValue = compareArray[start + i].getBytes();
                assertFalse(accessor.isNull(i));
                assertArrayEquals(expectedValue, accessor.get(i));
            } else {
                assertTrue(accessor.isNull(i));
            }
        }
        newVarCharVector.clear();
    }
    varCharVector.close();
    allocator.close();
}
Also used : TransferPair(org.apache.drill.exec.record.TransferPair) MaterializedField(org.apache.drill.exec.record.MaterializedField) Accessor(org.apache.drill.exec.vector.NullableVarCharVector.Accessor) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) DrillConfig(org.apache.drill.common.config.DrillConfig) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Aggregations

DrillConfig (org.apache.drill.common.config.DrillConfig)2 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)2 MaterializedField (org.apache.drill.exec.record.MaterializedField)2 TransferPair (org.apache.drill.exec.record.TransferPair)2 Accessor (org.apache.drill.exec.vector.NullableVarCharVector.Accessor)2 Test (org.junit.Test)2 BaseTest (org.apache.drill.test.BaseTest)1