Search in sources :

Example 16 with FragmentRoot

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

the class TestMergeJoin method simpleEqualityJoin.

@Test
// this doesn't have a sort.  it also causes an infinite loop.  these may or may not be related.
@Ignore
public void simpleEqualityJoin(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
    mockDrillbitContext(bitContext);
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/join/merge_join.json"), 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();
        for (final ValueVector v : exec) {
            System.out.print("[" + v.getField().getPath() + "]        ");
        }
        System.out.println("\n");
        for (int valueIdx = 0; valueIdx < exec.getRecordCount(); valueIdx++) {
            final List<Object> row = new ArrayList<>();
            for (final ValueVector v : exec) {
                row.add(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 < (14 - len); ++i) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
        System.out.println();
    }
    assertEquals(100, totalRecordCount);
    System.out.println("Total Record Count: " + 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) ArrayList(java.util.ArrayList) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with FragmentRoot

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

the class TestMergeJoin method orderedEqualityInnerJoin.

@Test
@Ignore
public void orderedEqualityInnerJoin(@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_inner_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(23, 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)

Example 18 with FragmentRoot

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

the class TestSimpleLimit method verifyLimitCount.

private void verifyLimitCount(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount) throws Throwable {
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/limit/" + testPlan), 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 recordCount = 0;
    while (exec.next()) {
        recordCount += exec.getRecordCount();
    }
    assertEquals(expectedCount, recordCount);
    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 19 with FragmentRoot

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

the class TestSimpleLimit method verifySum.

private void verifySum(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount, long expectedSum) throws Throwable {
    final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
    final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/limit/" + testPlan), 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 recordCount = 0;
    long sum = 0;
    while (exec.next()) {
        recordCount += exec.getRecordCount();
        final BigIntVector v = (BigIntVector) exec.iterator().next();
        for (int i = 0; i < v.getAccessor().getValueCount(); i++) {
            sum += v.getAccessor().get(i);
        }
    }
    assertEquals(expectedCount, recordCount);
    assertEquals(expectedSum, sum);
    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) BigIntVector(org.apache.drill.exec.vector.BigIntVector)

Example 20 with FragmentRoot

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

the class Foreman method runFragment.

/**
   * This is a helper method to run query based on the list of PlanFragment that were planned
   * at some point of time
   * @param fragmentsList
   * @throws ExecutionSetupException
   */
private void runFragment(List<PlanFragment> fragmentsList) throws ExecutionSetupException {
    // need to set QueryId, MinorFragment for incoming Fragments
    PlanFragment rootFragment = null;
    boolean isFirst = true;
    final List<PlanFragment> planFragments = Lists.newArrayList();
    for (PlanFragment myFragment : fragmentsList) {
        final FragmentHandle handle = myFragment.getHandle();
        // though we have new field in the FragmentHandle - parentQueryId
        // it can not be used until every piece of code that creates handle is using it, as otherwise
        // comparisons on that handle fail that causes fragment runtime failure
        final FragmentHandle newFragmentHandle = FragmentHandle.newBuilder().setMajorFragmentId(handle.getMajorFragmentId()).setMinorFragmentId(handle.getMinorFragmentId()).setQueryId(queryId).build();
        final PlanFragment newFragment = PlanFragment.newBuilder(myFragment).setHandle(newFragmentHandle).build();
        if (isFirst) {
            rootFragment = newFragment;
            isFirst = false;
        } else {
            planFragments.add(newFragment);
        }
    }
    final FragmentRoot rootOperator;
    try {
        rootOperator = drillbitContext.getPlanReader().readFragmentOperator(rootFragment.getFragmentJson());
    } catch (IOException e) {
        throw new ExecutionSetupException(String.format("Unable to parse FragmentRoot from fragment: %s", rootFragment.getFragmentJson()));
    }
    if (queuingEnabled) {
        acquireQuerySemaphore(rootOperator.getCost());
        moveToState(QueryState.STARTING, null);
    }
    drillbitContext.getWorkBus().addFragmentStatusListener(queryId, queryManager.getFragmentStatusListener());
    drillbitContext.getClusterCoordinator().addDrillbitStatusListener(queryManager.getDrillbitStatusListener());
    logger.debug("Submitting fragments to run.");
    // set up the root fragment first so we'll have incoming buffers available.
    setupRootFragment(rootFragment, rootOperator);
    setupNonRootFragments(planFragments);
    moveToState(QueryState.RUNNING, null);
    logger.debug("Fragments running.");
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) FragmentHandle(org.apache.drill.exec.proto.ExecProtos.FragmentHandle) IOException(java.io.IOException) PlanFragment(org.apache.drill.exec.proto.BitControl.PlanFragment)

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