Search in sources :

Example 1 with VarCharVector

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

the class TestCastFunctions method testCastVarChar.

@Test
public //cast to varchar(length)
void testCastVarChar(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/cast/testCastVarChar.json"), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    while (exec.next()) {
        final VarCharVector c0 = exec.getValueVectorById(new SchemaPath("int_lit_cast", ExpressionPosition.UNKNOWN), VarCharVector.class);
        final VarCharVector.Accessor a0 = c0.getAccessor();
        int count = 0;
        for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
            final VarCharHolder holder0 = new VarCharHolder();
            a0.get(i, holder0);
            assertEquals("123", StringFunctionHelpers.toStringFromUTF8(holder0.start, holder0.end, holder0.buffer));
            ++count;
        }
        assertEquals(5, count);
    }
    exec.close();
    context.close();
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) SchemaPath(org.apache.drill.common.expression.SchemaPath) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) VarCharVector(org.apache.drill.exec.vector.VarCharVector) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test)

Example 2 with VarCharVector

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

the class WriterRecordBatch method addOutputContainerData.

private void addOutputContainerData() {
    final VarCharVector fragmentIdVector = (VarCharVector) container.getValueAccessorById(VarCharVector.class, container.getValueVectorId(SchemaPath.getSimplePath("Fragment")).getFieldIds()).getValueVector();
    AllocationHelper.allocate(fragmentIdVector, 1, 50);
    final BigIntVector summaryVector = (BigIntVector) container.getValueAccessorById(BigIntVector.class, container.getValueVectorId(SchemaPath.getSimplePath("Number of records written")).getFieldIds()).getValueVector();
    AllocationHelper.allocate(summaryVector, 1, 8);
    fragmentIdVector.getMutator().setSafe(0, fragmentUniqueId.getBytes());
    fragmentIdVector.getMutator().setValueCount(1);
    summaryVector.getMutator().setSafe(0, counter);
    summaryVector.getMutator().setValueCount(1);
    container.setRecordCount(1);
}
Also used : VarCharVector(org.apache.drill.exec.vector.VarCharVector) BigIntVector(org.apache.drill.exec.vector.BigIntVector)

Example 3 with VarCharVector

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

the class TestValueVector method testVectors.

/**
   * Convenience method that allows running tests on various {@link ValueVector vector} instances.
   *
   * @param test test function to execute
   */
private void testVectors(VectorVerifier test) throws Exception {
    final MaterializedField[] fields = { MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, BitHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, VarCharHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedListVector.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, MapVector.TYPE), MaterializedField.create(EMPTY_SCHEMA_PATH, RepeatedMapVector.TYPE) };
    final ValueVector[] vectors = { new UInt4Vector(fields[0], allocator), new BitVector(fields[1], allocator), new VarCharVector(fields[2], allocator), new NullableVarCharVector(fields[3], allocator), new RepeatedListVector(fields[4], allocator, null), new MapVector(fields[5], allocator, null), new RepeatedMapVector(fields[6], allocator, null) };
    try {
        for (final ValueVector vector : vectors) {
            test.verify(vector);
        }
    } finally {
        AutoCloseables.close(vectors);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) BaseValueVector(org.apache.drill.exec.vector.BaseValueVector) BitVector(org.apache.drill.exec.vector.BitVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) NullableUInt4Vector(org.apache.drill.exec.vector.NullableUInt4Vector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 4 with VarCharVector

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

the class TestValueVector method testVarCharVectorLoad.

@Test
public void testVarCharVectorLoad() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, VarCharHolder.TYPE);
    // Create a new value vector for 1024 variable length strings.
    final VarCharVector vector1 = new VarCharVector(field, allocator);
    final VarCharVector.Mutator mutator = vector1.getMutator();
    vector1.allocateNew(1024 * 10, 1024);
    // Populate the vector.
    final StringBuilder stringBuilder = new StringBuilder();
    final int valueCount = 10;
    for (int i = 0; i < valueCount; ++i) {
        stringBuilder.append('x');
        mutator.setSafe(i, stringBuilder.toString().getBytes(utf8Charset));
    }
    mutator.setValueCount(valueCount);
    assertEquals(valueCount, vector1.getAccessor().getValueCount());
    // Combine the backing buffers so we can load them into a new vector.
    final DrillBuf[] buffers1 = vector1.getBuffers(false);
    final DrillBuf buffer1 = combineBuffers(allocator, buffers1);
    final VarCharVector vector2 = new VarCharVector(field, allocator);
    vector2.load(vector1.getMetadata(), buffer1);
    // Check the contents of the new vector.
    final VarCharVector.Accessor accessor = vector2.getAccessor();
    stringBuilder.setLength(0);
    for (int i = 0; i < valueCount; ++i) {
        stringBuilder.append('x');
        final Object object = accessor.getObject(i);
        assertEquals(stringBuilder.toString(), object.toString());
    }
    vector1.close();
    vector2.close();
    buffer1.release();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) DrillBuf(io.netty.buffer.DrillBuf) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 5 with VarCharVector

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

the class TestValueVector method testVariableVectorReallocation.

@Test(expected = OversizedAllocationException.class)
public void testVariableVectorReallocation() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE);
    final VarCharVector vector = new VarCharVector(field, allocator);
    // edge case 1: value count = MAX_VALUE_ALLOCATION
    final int expectedAllocationInBytes = BaseValueVector.MAX_ALLOCATION_SIZE;
    final int expectedOffsetSize = 10;
    try {
        vector.allocateNew(expectedAllocationInBytes, 10);
        assertTrue(expectedOffsetSize <= vector.getValueCapacity());
        assertTrue(expectedAllocationInBytes <= vector.getBuffer().capacity());
        vector.reAlloc();
        assertTrue(expectedOffsetSize * 2 <= vector.getValueCapacity());
        assertTrue(expectedAllocationInBytes * 2 <= vector.getBuffer().capacity());
    } finally {
        vector.close();
    }
    // common: value count < MAX_VALUE_ALLOCATION
    try {
        vector.allocateNew(BaseValueVector.MAX_ALLOCATION_SIZE / 2, 0);
        // value allocation reaches to MAX_VALUE_ALLOCATION
        vector.reAlloc();
        // this tests if it overflows
        vector.reAlloc();
    } finally {
        vector.close();
    }
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

VarCharVector (org.apache.drill.exec.vector.VarCharVector)20 ValueVector (org.apache.drill.exec.vector.ValueVector)9 Test (org.junit.Test)9 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)7 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)6 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)5 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)4 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)4 ExecTest (org.apache.drill.exec.ExecTest)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)3 BigIntVector (org.apache.drill.exec.vector.BigIntVector)3 DrillBuf (io.netty.buffer.DrillBuf)2 ArrayList (java.util.ArrayList)2 BatchValidator (org.apache.drill.exec.physical.impl.validate.BatchValidator)2 BatchSchema (org.apache.drill.exec.record.BatchSchema)2 Float4Vector (org.apache.drill.exec.vector.Float4Vector)2 IntVector (org.apache.drill.exec.vector.IntVector)2 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)2 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)2