Search in sources :

Example 6 with VarBinaryHolder

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

the class TestCastFunctions method testCastVarBinary.

@Test
public //cast to varbinary(length)
void testCastVarBinary(@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/testCastVarBinary.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 VarBinaryVector c0 = exec.getValueVectorById(new SchemaPath("int_lit_cast", ExpressionPosition.UNKNOWN), VarBinaryVector.class);
        final VarBinaryVector.Accessor a0 = c0.getAccessor();
        int count = 0;
        for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
            final VarBinaryHolder holder0 = new VarBinaryHolder();
            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) VarBinaryHolder(org.apache.drill.exec.expr.holders.VarBinaryHolder) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) VarBinaryVector(org.apache.drill.exec.vector.VarBinaryVector) Test(org.junit.Test)

Aggregations

VarBinaryHolder (org.apache.drill.exec.expr.holders.VarBinaryHolder)6 VarBinaryVector (org.apache.drill.exec.vector.VarBinaryVector)4 Test (org.junit.Test)4 ExecTest (org.apache.drill.exec.ExecTest)3 DrillClient (org.apache.drill.exec.client.DrillClient)3 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)3 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)3 QueryDataBatch (org.apache.drill.exec.rpc.user.QueryDataBatch)3 Drillbit (org.apache.drill.exec.server.Drillbit)3 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)3 ValueVector (org.apache.drill.exec.vector.ValueVector)3 VectorWrapper (org.apache.drill.exec.record.VectorWrapper)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 FragmentContext (org.apache.drill.exec.ops.FragmentContext)1 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)1 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)1 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)1 BsonBinary (org.bson.BsonBinary)1