Search in sources :

Example 31 with NullableVarCharVector

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

the class TestSimpleFunctions method testSubstring.

@Test
public void testSubstring() 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/testSubstring.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);
                assertEquals("aaaa", 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)

Example 32 with NullableVarCharVector

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

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 33 with NullableVarCharVector

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

the class TestHiveUDFs method testGenericUDF.

@Test
public void testGenericUDF() throws Throwable {
    String planString = Resources.toString(Resources.getResource("functions/hive/GenericUDF.json"), Charsets.UTF_8);
    List<QueryDataBatch> results = testPhysicalWithResults(planString);
    RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
    for (QueryDataBatch result : results) {
        batchLoader.load(result.getHeader().getDef(), result.getData());
        if (batchLoader.getRecordCount() <= 0) {
            result.release();
            batchLoader.clear();
            continue;
        }
        // Output columns and types
        // 1. str1 : VarChar
        // 2. upperStr1 : NullableVarChar
        // 3. concat : NullableVarChar
        // 4. flt1 : Float4
        // 5. format_number : NullableFloat8
        // 6. nullableStr1 : NullableVarChar
        // 7. upperNullableStr1 : NullableVarChar
        VarCharVector str1V = (VarCharVector) batchLoader.getValueAccessorById(VarCharVector.class, 0).getValueVector();
        NullableVarCharVector upperStr1V = (NullableVarCharVector) batchLoader.getValueAccessorById(NullableVarCharVector.class, 1).getValueVector();
        NullableVarCharVector concatV = (NullableVarCharVector) batchLoader.getValueAccessorById(NullableVarCharVector.class, 2).getValueVector();
        Float4Vector flt1V = (Float4Vector) batchLoader.getValueAccessorById(Float4Vector.class, 3).getValueVector();
        NullableVarCharVector format_numberV = (NullableVarCharVector) batchLoader.getValueAccessorById(NullableVarCharVector.class, 4).getValueVector();
        NullableVarCharVector nullableStr1V = (NullableVarCharVector) batchLoader.getValueAccessorById(NullableVarCharVector.class, 5).getValueVector();
        NullableVarCharVector upperNullableStr1V = (NullableVarCharVector) batchLoader.getValueAccessorById(NullableVarCharVector.class, 6).getValueVector();
        for (int i = 0; i < batchLoader.getRecordCount(); i++) {
            String in = new String(str1V.getAccessor().get(i), Charsets.UTF_8);
            String upper = new String(upperStr1V.getAccessor().get(i), Charsets.UTF_8);
            assertTrue(in.toUpperCase().equals(upper));
            String concat = new String(concatV.getAccessor().get(i), Charsets.UTF_8);
            assertTrue(concat.equals(in + "-" + in));
            String nullableStr1 = null;
            if (!nullableStr1V.getAccessor().isNull(i)) {
                nullableStr1 = new String(nullableStr1V.getAccessor().get(i), Charsets.UTF_8);
            }
            String upperNullableStr1 = null;
            if (!upperNullableStr1V.getAccessor().isNull(i)) {
                upperNullableStr1 = new String(upperNullableStr1V.getAccessor().get(i), Charsets.UTF_8);
            }
            assertEquals(nullableStr1 != null, upperNullableStr1 != null);
            if (nullableStr1 != null) {
                assertEquals(nullableStr1.toUpperCase(), upperNullableStr1);
            }
        }
        result.release();
        batchLoader.clear();
    }
}
Also used : QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) Float4Vector(org.apache.drill.exec.vector.Float4Vector) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) HiveStorageTest(org.apache.drill.categories.HiveStorageTest) Test(org.junit.Test) SlowTest(org.apache.drill.categories.SlowTest)

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