Search in sources :

Example 1 with QueryContext

use of org.apache.drill.exec.ops.QueryContext in project drill by apache.

the class TestExceptionInjection method checkedInjection.

@SuppressWarnings("static-method")
@Test
public void checkedInjection() {
    // set the injection via the parsing POJOs
    final String controls = Controls.newBuilder().addException(DummyClass.class, DummyClass.THROWS_IOEXCEPTION, IOException.class, 0, 1).build();
    ControlsInjectionUtil.setControls(session, controls);
    final QueryContext context = new QueryContext(session, bits[0].getContext(), QueryId.getDefaultInstance());
    // test that the expected exception (checked) gets thrown
    final DummyClass dummyClass = new DummyClass(context);
    try {
        dummyClass.throwsIOException();
        fail(NO_THROW_FAIL);
    } catch (IOException e) {
        assertEquals(DummyClass.THROWS_IOEXCEPTION, e.getMessage());
    }
    try {
        context.close();
    } catch (Exception e) {
        fail();
    }
}
Also used : IOException(java.io.IOException) QueryContext(org.apache.drill.exec.ops.QueryContext) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with QueryContext

use of org.apache.drill.exec.ops.QueryContext in project drill by apache.

the class TestCountDownLatchInjection method latchInjected.

// test would hang if the correct init, wait and countdowns did not happen, and the test timeout mechanism will
@Test
public // catch that case
void latchInjected() {
    final int threads = 10;
    final ExtendedLatch trigger = new ExtendedLatch(1);
    final Pointer<Long> countingDownTime = new Pointer<>();
    final String controls = Controls.newBuilder().addLatch(DummyClass.class, DummyClass.LATCH_NAME).build();
    ControlsInjectionUtil.setControls(session, controls);
    final QueryContext queryContext = new QueryContext(session, bits[0].getContext(), QueryId.getDefaultInstance());
    final DummyClass dummyClass = new DummyClass(queryContext, trigger, threads);
    (new ThreadCreator(dummyClass, trigger, threads, countingDownTime)).start();
    final long timeSpentWaiting;
    try {
        timeSpentWaiting = dummyClass.initAndWait();
    } catch (final InterruptedException e) {
        fail("Thread should not be interrupted; there is no deliberate attempt.");
        return;
    }
    assertTrue(timeSpentWaiting >= countingDownTime.value);
    try {
        queryContext.close();
    } catch (final Exception e) {
        fail("Failed to close query context: " + e);
    }
}
Also used : Pointer(org.apache.drill.exec.util.Pointer) QueryContext(org.apache.drill.exec.ops.QueryContext) ExtendedLatch(org.apache.drill.common.concurrent.ExtendedLatch) Test(org.junit.Test)

Example 3 with QueryContext

use of org.apache.drill.exec.ops.QueryContext in project drill by apache.

the class PlanSplitter method planFragments.

/**
   * Method to plan the query and return list of fragments
   * it will return query plan "as is" or split plans based on the req setting: split_plan
   * @param dContext
   * @param queryId
   * @param req
   * @param connection
   * @return
   */
public QueryPlanFragments planFragments(DrillbitContext dContext, QueryId queryId, GetQueryPlanFragments req, UserClientConnection connection) {
    QueryPlanFragments.Builder responseBuilder = QueryPlanFragments.newBuilder();
    QueryContext queryContext = new QueryContext(connection.getSession(), dContext, queryId);
    responseBuilder.setQueryId(queryId);
    try {
        responseBuilder.addAllFragments(getFragments(dContext, req, queryContext, queryId));
        responseBuilder.setStatus(QueryState.COMPLETED);
    } catch (Exception e) {
        final String errorMessage = String.format("Failed to produce PlanFragments for query id \"%s\" with " + "request to %s plan", queryId, (req.getSplitPlan() ? "split" : "no split"));
        DrillPBError error = DrillPBError.newBuilder().setMessage(errorMessage).setErrorType(DrillPBError.ErrorType.PLAN).build();
        responseBuilder.setStatus(QueryState.FAILED);
        responseBuilder.setError(error);
    }
    return responseBuilder.build();
}
Also used : DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) QueryContext(org.apache.drill.exec.ops.QueryContext)

Example 4 with QueryContext

use of org.apache.drill.exec.ops.QueryContext in project drill by apache.

the class TestOptiqPlans method doLogicalTest.

private SimpleRootExec doLogicalTest(final BootStrapContext context, UserClientConnection connection, String file, ClusterCoordinator coord, DataConnectionCreator com, Controller controller, WorkEventBus workBus) throws Exception {
    new NonStrictExpectations() {

        {
            context.getMetrics();
            result = new MetricRegistry();
            context.getAllocator();
            result = RootAllocatorFactory.newRoot(config);
            context.getConfig();
            result = config;
        }
    };
    final RemoteServiceSet lss = RemoteServiceSet.getLocalServiceSet();
    final DrillbitContext bitContext = new DrillbitContext(DrillbitEndpoint.getDefaultInstance(), context, coord, controller, com, workBus, new LocalPersistentStoreProvider(config));
    final QueryContext qc = new QueryContext(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build(), bitContext, QueryId.getDefaultInstance());
    final PhysicalPlanReader reader = bitContext.getPlanReader();
    final LogicalPlan plan = reader.readLogicalPlan(Files.toString(FileUtils.getResourceAsFile(file), Charsets.UTF_8));
    final PhysicalPlan pp = new BasicOptimizer(qc, connection).optimize(new BasicOptimizer.BasicOptimizationContext(qc), plan);
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(config);
    final FragmentContext fctxt = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(fctxt, (FragmentRoot) pp.getSortedOperators(false).iterator().next()));
    return exec;
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) BasicOptimizer(org.apache.drill.exec.opt.BasicOptimizer) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) LocalPersistentStoreProvider(org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) MetricRegistry(com.codahale.metrics.MetricRegistry) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) QueryContext(org.apache.drill.exec.ops.QueryContext) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) LogicalPlan(org.apache.drill.common.logical.LogicalPlan) NonStrictExpectations(mockit.NonStrictExpectations) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 5 with QueryContext

use of org.apache.drill.exec.ops.QueryContext in project drill by apache.

the class TestExceptionInjection method uncheckedInjection.

@SuppressWarnings("static-method")
@Test
public void uncheckedInjection() {
    // set exceptions via a string
    final String exceptionDesc = "<<injected from descPassthroughMethod()>>";
    final String exceptionClassName = "java.lang.RuntimeException";
    final String jsonString = "{\"injections\":[{" + "\"type\":\"exception\"," + "\"siteClass\":\"org.apache.drill.exec.testing.TestExceptionInjection$DummyClass\"," + "\"desc\":\"" + exceptionDesc + "\"," + "\"nSkip\":0," + "\"nFire\":1," + "\"exceptionClass\":\"" + exceptionClassName + "\"" + "}]}";
    ControlsInjectionUtil.setControls(session, jsonString);
    final QueryContext context = new QueryContext(session, bits[0].getContext(), QueryId.getDefaultInstance());
    // test that the exception gets thrown
    final DummyClass dummyClass = new DummyClass(context);
    assertPassthroughThrows(dummyClass, exceptionClassName, exceptionDesc);
    try {
        context.close();
    } catch (Exception e) {
        fail();
    }
}
Also used : QueryContext(org.apache.drill.exec.ops.QueryContext) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

QueryContext (org.apache.drill.exec.ops.QueryContext)9 Test (org.junit.Test)7 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)6 IOException (java.io.IOException)4 ExtendedLatch (org.apache.drill.common.concurrent.ExtendedLatch)3 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)3 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)3 Pointer (org.apache.drill.exec.util.Pointer)3 DrillConfig (org.apache.drill.common.config.DrillConfig)2 ZookeeperHelper (org.apache.drill.exec.ZookeeperHelper)2 UserSession (org.apache.drill.exec.rpc.user.UserSession)2 Drillbit (org.apache.drill.exec.server.Drillbit)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 NonStrictExpectations (mockit.NonStrictExpectations)1 LogicalPlan (org.apache.drill.common.logical.LogicalPlan)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 FragmentContext (org.apache.drill.exec.ops.FragmentContext)1 BasicOptimizer (org.apache.drill.exec.opt.BasicOptimizer)1 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)1 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)1