Search in sources :

Example 6 with FragmentRoot

use of org.apache.drill.exec.physical.base.FragmentRoot 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 7 with FragmentRoot

use of org.apache.drill.exec.physical.base.FragmentRoot in project drill by apache.

the class TestRecordIterator method testSimpleIterator.

@Test
public void testSimpleIterator(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final String planStr = Files.toString(FileUtils.getResourceAsFile("/record/test_recorditerator.json"), Charsets.UTF_8);
    final PhysicalPlan plan = reader.readPhysicalPlan(planStr);
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
    final List<PhysicalOperator> operatorList = plan.getSortedOperators(false);
    SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) operatorList.iterator().next()));
    RecordBatch singleBatch = exec.getIncoming();
    PhysicalOperator dummyPop = operatorList.iterator().next();
    OpProfileDef def = new OpProfileDef(dummyPop.getOperatorId(), UserBitShared.CoreOperatorType.MOCK_SUB_SCAN_VALUE, OperatorUtilities.getChildCount(dummyPop));
    OperatorStats stats = exec.getContext().getStats().newOperatorStats(def, exec.getContext().getAllocator());
    RecordIterator iter = new RecordIterator(singleBatch, null, exec.getContext().newOperatorContext(dummyPop, stats), 0, false);
    int totalRecords = 0;
    List<ValueVector> vectors = null;
    while (true) {
        iter.next();
        if (iter.finished()) {
            break;
        } else {
            // First time save vectors.
            if (vectors == null) {
                vectors = Lists.newArrayList();
                for (VectorWrapper vw : iter) {
                    vectors.add(vw.getValueVector());
                }
            }
            final int position = iter.getCurrentPosition();
            if (position % 2 == 0) {
                assertTrue(checkValues(vectors, position));
            } else {
                assertTrue(checkValues(vectors, position));
            }
            totalRecords++;
        }
        assertEquals(0, iter.cachedBatches().size());
    }
    assertEquals(11112, totalRecords);
    try {
        iter.mark();
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
    }
    try {
        iter.reset();
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
    }
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) OpProfileDef(org.apache.drill.exec.ops.OpProfileDef) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) OperatorStats(org.apache.drill.exec.ops.OperatorStats) ValueVector(org.apache.drill.exec.vector.ValueVector) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Test(org.junit.Test)

Example 8 with FragmentRoot

use of org.apache.drill.exec.physical.base.FragmentRoot in project drill by apache.

the class IteratorValidatorInjector method rewritePlanWithIteratorValidator.

public static FragmentRoot rewritePlanWithIteratorValidator(FragmentContext context, FragmentRoot root) throws ExecutionSetupException {
    IteratorValidatorInjector inject = new IteratorValidatorInjector();
    PhysicalOperator newOp = root.accept(inject, context);
    if (!(newOp instanceof FragmentRoot)) {
        throw new IllegalStateException("This shouldn't happen.");
    }
    return (FragmentRoot) newOp;
}
Also used : PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot)

Example 9 with FragmentRoot

use of org.apache.drill.exec.physical.base.FragmentRoot in project drill by apache.

the class TestHashJoin method testHJMockScanCommon.

private void testHJMockScanCommon(final DrillbitContext bitContext, UserClientConnection connection, String physicalPlan, int expectedRows) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile(physicalPlan), Charsets.UTF_8));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    int totalRecordCount = 0;
    while (exec.next()) {
        totalRecordCount += exec.getRecordCount();
    }
    exec.close();
    assertEquals(expectedRows, totalRecordCount);
    System.out.println("Total Record Count: " + totalRecordCount);
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 10 with FragmentRoot

use of org.apache.drill.exec.physical.base.FragmentRoot in project drill by apache.

the class TestMergeJoin method orderedEqualityLeftJoin.

@Test
@Ignore
public void orderedEqualityLeftJoin(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c, new StoragePluginRegistryImpl(bitContext));
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/join/merge_single_batch.json"), Charsets.UTF_8).replace("#{LEFT_FILE}", FileUtils.getResourceAsFile("/join/merge_single_batch.left.json").toURI().toString()).replace("#{RIGHT_FILE}", FileUtils.getResourceAsFile("/join/merge_single_batch.right.json").toURI().toString()));
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
    int totalRecordCount = 0;
    while (exec.next()) {
        totalRecordCount += exec.getRecordCount();
        System.out.println("got next with record count: " + exec.getRecordCount() + " (total: " + totalRecordCount + "):");
        System.out.println("       t1                 t2");
        for (int valueIdx = 0; valueIdx < exec.getRecordCount(); valueIdx++) {
            final List<Object> row = Lists.newArrayList();
            for (final ValueVector v : exec) {
                row.add(v.getField().getPath() + ":" + v.getAccessor().getObject(valueIdx));
            }
            for (final Object cell : row) {
                if (cell == null) {
                    System.out.print("<null>    ");
                    continue;
                }
                final int len = cell.toString().length();
                System.out.print(cell + " ");
                for (int i = 0; i < (10 - len); ++i) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
    System.out.println("Total Record Count: " + totalRecordCount);
    assertEquals(25, totalRecordCount);
    if (context.getFailureCause() != null) {
        throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) SimpleRootExec(org.apache.drill.exec.physical.impl.SimpleRootExec) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) StoragePluginRegistryImpl(org.apache.drill.exec.store.StoragePluginRegistryImpl) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)45 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)39 FragmentContext (org.apache.drill.exec.ops.FragmentContext)39 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)39 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)35 Test (org.junit.Test)29 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)23 SchemaPath (org.apache.drill.common.expression.SchemaPath)15 ExecTest (org.apache.drill.exec.ExecTest)14 ValueVector (org.apache.drill.exec.vector.ValueVector)7 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)6 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)6 BigIntVector (org.apache.drill.exec.vector.BigIntVector)6 IntVector (org.apache.drill.exec.vector.IntVector)6 Ignore (org.junit.Ignore)5 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)4 BigIntHolder (org.apache.drill.exec.expr.holders.BigIntHolder)3 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)3 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2