Search in sources :

Example 16 with VarCharHolder

use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.

the class TestCastFunctions method testCastVarChar.

@Test
public // cast to varchar(length)
void testCastVarChar() throws Throwable {
    final DrillbitContext bitContext = mockDrillbitContext();
    final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/cast/testCastVarChar.json"), Charsets.UTF_8).read());
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
    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 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.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) VarCharVector(org.apache.drill.exec.vector.VarCharVector) FragmentContextImpl(org.apache.drill.exec.ops.FragmentContextImpl) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) SchemaPath(org.apache.drill.common.expression.SchemaPath) UserClientConnection(org.apache.drill.exec.rpc.UserClientConnection) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test)

Example 17 with VarCharHolder

use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.

the class TestByteComparisonFunctions method testNotEqualLong.

@Test
public void testNotEqualLong() {
    final VarCharHolder left = helloLong;
    final VarCharHolder right = goodbyeLong;
    assertTrue(ByteFunctionHelpers.equal(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 0);
}
Also used : VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest) VectorTest(org.apache.drill.categories.VectorTest)

Example 18 with VarCharHolder

use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.

the class TestByteComparisonFunctions method testEqualLong.

@Test
public void testEqualLong() {
    final VarCharHolder left = helloLong;
    final VarCharHolder right = helloLong;
    assertTrue(ByteFunctionHelpers.equal(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1);
}
Also used : VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest) VectorTest(org.apache.drill.categories.VectorTest)

Example 19 with VarCharHolder

use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.

the class TestByteComparisonFunctions method testAfterLong.

@Test
public void testAfterLong() {
    final VarCharHolder left = helloLong;
    final VarCharHolder right = goodbyeLong;
    assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1);
}
Also used : VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest) VectorTest(org.apache.drill.categories.VectorTest)

Example 20 with VarCharHolder

use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.

the class TestByteComparisonFunctions method testAfter.

@Test
public void testAfter() {
    final VarCharHolder left = hello;
    final VarCharHolder right = goodbye;
    assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1);
}
Also used : VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) Test(org.junit.Test) ExecTest(org.apache.drill.exec.ExecTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest) VectorTest(org.apache.drill.categories.VectorTest)

Aggregations

VarCharHolder (org.apache.drill.exec.expr.holders.VarCharHolder)36 Test (org.junit.Test)23 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)20 VectorTest (org.apache.drill.categories.VectorTest)20 ExecTest (org.apache.drill.exec.ExecTest)20 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)5 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)4 FieldReader (org.apache.drill.exec.vector.complex.reader.FieldReader)4 BaseWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)3 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)3 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)3 VarCharVector (org.apache.drill.exec.vector.VarCharVector)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 BitHolder (org.apache.drill.exec.expr.holders.BitHolder)2 VarDecimalHolder (org.apache.drill.exec.expr.holders.VarDecimalHolder)2 DrillBuf (io.netty.buffer.DrillBuf)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1