Search in sources :

Example 26 with NullableVarCharVector

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

the class TestVectorLimits method testNullableWideVariableVector.

@Test
public void testNullableWideVariableVector() {
    @SuppressWarnings("resource") NullableVarCharVector vector = new NullableVarCharVector(makeField(MinorType.VARCHAR, DataMode.OPTIONAL), fixture.allocator());
    vector.allocateNew();
    byte[] dummyValue = makeVarCharValue(512);
    NullableVarCharVector.Mutator mutator = vector.getMutator();
    int count = 0;
    for (; count < 2 * ValueVector.MAX_ROW_COUNT; count++) {
        try {
            mutator.setScalar(count, dummyValue, 0, dummyValue.length);
        } catch (VectorOverflowException e) {
            break;
        }
    }
    mutator.setValueCount(count);
    assertEquals(ValueVector.MAX_BUFFER_SIZE, vector.getValuesVector().getBuffer().getActualMemoryConsumed());
    assertTrue(count < ValueVector.MAX_ROW_COUNT);
    vector.close();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Example 27 with NullableVarCharVector

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

the class TestValueVector method testReAllocNullableVariableWidthVector.

@Test
public void testReAllocNullableVariableWidthVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE);
    // Create a new value vector for 1024 integers
    try (final NullableVarCharVector vector = (NullableVarCharVector) TypeHelper.getNewVector(field, allocator)) {
        final NullableVarCharVector.Mutator m = vector.getMutator();
        vector.allocateNew();
        int initialCapacity = vector.getValueCapacity();
        // Put values in indexes that fall within the initial allocation
        m.setSafe(0, STR1, 0, STR1.length);
        m.setSafe(initialCapacity - 1, STR2, 0, STR2.length);
        // Now try to put values in space that falls beyond the initial allocation
        m.setSafe(initialCapacity + 200, STR3, 0, STR3.length);
        // Check valueCapacity is more than initial allocation
        assertEquals((initialCapacity + 1) * 2 - 1, vector.getValueCapacity());
        final NullableVarCharVector.Accessor accessor = vector.getAccessor();
        assertArrayEquals(STR1, accessor.get(0));
        assertArrayEquals(STR2, accessor.get(initialCapacity - 1));
        assertArrayEquals(STR3, accessor.get(initialCapacity + 200));
        // Set the valueCount to be more than valueCapacity of current allocation. This is possible for NullableValueVectors
        // as we don't call setSafe for null values, but we do call setValueCount when the current batch is processed.
        m.setValueCount(vector.getValueCapacity() + 200);
    }
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorTest(org.apache.drill.categories.VectorTest) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 28 with NullableVarCharVector

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

the class TestToNullable method testVariableWidth.

@Test
public void testVariableWidth() {
    MaterializedField nonNullableSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.REQUIRED);
    @SuppressWarnings("resource") VarCharVector nonNullableVector = new VarCharVector(nonNullableSchema, fixture.allocator());
    VarCharVector.Mutator mutator = nonNullableVector.getMutator();
    nonNullableVector.allocateNew(100, 20);
    byte[] value = new byte[20];
    for (int i = 0; i < 100; i++) {
        Arrays.fill(value, (byte) ('A' + i % 26));
        mutator.setSafe(i, value);
    }
    mutator.setValueCount(100);
    MaterializedField nullableVarCharSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.OPTIONAL);
    NullableVarCharVector nullableVector = new NullableVarCharVector(nullableVarCharSchema, fixture.allocator());
    nonNullableVector.toNullable(nullableVector);
    assertEquals(0, nonNullableVector.getAccessor().getValueCount());
    NullableVarCharVector.Accessor nullableAccessor = nullableVector.getAccessor();
    assertEquals(100, nullableAccessor.getValueCount());
    for (int i = 0; i < 100; i++) {
        assertFalse(nullableAccessor.isNull(i));
        Arrays.fill(value, (byte) ('A' + i % 26));
        assertTrue(Arrays.areEqual(value, nullableAccessor.get(i)));
    }
    nullableVector.clear();
// Don't clear the nonNullableVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 29 with NullableVarCharVector

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

the class TestFillEmpties method testNullableVarChar.

@Test
public void testNullableVarChar() {
    NullableVarCharVector vector = new NullableVarCharVector(SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.OPTIONAL), fixture.allocator());
    vector.allocateNew();
    // Create "foo", null, "bar", but omit the null.
    NullableVarCharVector.Mutator mutator = vector.getMutator();
    byte[] value = makeValue("foo");
    mutator.setSafe(0, value, 0, value.length);
    value = makeValue("bar");
    mutator.setSafe(2, value, 0, value.length);
    visualize(vector, 3);
    verifyOffsets(vector.getValuesVector().getOffsetVector(), new int[] { 0, 3, 3, 6 });
    vector.close();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest)

Example 30 with NullableVarCharVector

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

the class TestSimpleFunctions method testSubstringNegative.

@Test
public void testSubstringNegative() throws Throwable {
    final DrillbitContext bitContext = mockDrillbitContext();
    final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/testSubstringNegative.json"), Charsets.UTF_8).read());
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    while (exec.next()) {
        final NullableVarCharVector c1 = exec.getValueVectorById(new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class);
        final NullableVarCharVector.Accessor a1 = c1.getAccessor();
        int count = 0;
        for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
            if (!a1.isNull(i)) {
                final NullableVarCharHolder holder = new NullableVarCharHolder();
                a1.get(i, holder);
                // when offset is negative, substring return empty string.
                assertEquals("", StringFunctionHelpers.toStringFromUTF8(holder.start, holder.end, holder.buffer));
                ++count;
            }
        }
        assertEquals(50, count);
    }
    if (context.getExecutorState().getFailureCause() != null) {
        throw context.getExecutorState().getFailureCause();
    }
    assertTrue(!context.getExecutorState().isFailed());
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) NullableVarCharHolder(org.apache.drill.exec.expr.holders.NullableVarCharHolder) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) SchemaPath(org.apache.drill.common.expression.SchemaPath) UserClientConnection(org.apache.drill.exec.rpc.UserClientConnection) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)33 Test (org.junit.Test)25 ExecTest (org.apache.drill.exec.ExecTest)12 VectorTest (org.apache.drill.categories.VectorTest)10 MaterializedField (org.apache.drill.exec.record.MaterializedField)10 SchemaPath (org.apache.drill.common.expression.SchemaPath)9 VarCharVector (org.apache.drill.exec.vector.VarCharVector)9 SubOperatorTest (org.apache.drill.test.SubOperatorTest)9 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)6 ValueVector (org.apache.drill.exec.vector.ValueVector)6 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)5 NullableVarCharHolder (org.apache.drill.exec.expr.holders.NullableVarCharHolder)5 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)5 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)5 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)5 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)5 NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)5 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)5