Search in sources :

Example 21 with GroupByQueryConfig

use of org.apache.druid.query.groupby.GroupByQueryConfig in project druid by druid-io.

the class ApproximateHistogramGroupByQueryTest method constructorFeeder.

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> constructorFeeder() {
    final GroupByQueryConfig v1Config = new GroupByQueryConfig() {

        @Override
        public String getDefaultStrategy() {
            return GroupByStrategySelector.STRATEGY_V1;
        }

        @Override
        public String toString() {
            return "v1";
        }
    };
    final GroupByQueryConfig v1SingleThreadedConfig = new GroupByQueryConfig() {

        @Override
        public boolean isSingleThreaded() {
            return true;
        }

        @Override
        public String getDefaultStrategy() {
            return GroupByStrategySelector.STRATEGY_V1;
        }

        @Override
        public String toString() {
            return "v1SingleThreaded";
        }
    };
    final GroupByQueryConfig v2Config = new GroupByQueryConfig() {

        @Override
        public String getDefaultStrategy() {
            return GroupByStrategySelector.STRATEGY_V2;
        }

        @Override
        public String toString() {
            return "v2";
        }
    };
    v1Config.setMaxIntermediateRows(10000);
    v1SingleThreadedConfig.setMaxIntermediateRows(10000);
    final List<Object[]> constructors = new ArrayList<>();
    final List<GroupByQueryConfig> configs = ImmutableList.of(v1Config, v1SingleThreadedConfig, v2Config);
    for (GroupByQueryConfig config : configs) {
        final Pair<GroupByQueryRunnerFactory, Closer> factoryAndCloser = GroupByQueryRunnerTest.makeQueryRunnerFactory(config);
        final GroupByQueryRunnerFactory factory = factoryAndCloser.lhs;
        RESOURCE_CLOSER.register(factoryAndCloser.rhs);
        for (QueryRunner<ResultRow> runner : QueryRunnerTestHelper.makeQueryRunners(factory)) {
            final String testName = StringUtils.format("config=%s, runner=%s", config.toString(), runner.toString());
            constructors.add(new Object[] { testName, factory, runner });
        }
    }
    return constructors;
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) ResultRow(org.apache.druid.query.groupby.ResultRow) GroupByQueryRunnerFactory(org.apache.druid.query.groupby.GroupByQueryRunnerFactory) GroupByQueryConfig(org.apache.druid.query.groupby.GroupByQueryConfig) ArrayList(java.util.ArrayList)

Example 22 with GroupByQueryConfig

use of org.apache.druid.query.groupby.GroupByQueryConfig in project druid by druid-io.

the class GroupByMergedQueryRunner method run.

@Override
public Sequence<T> run(final QueryPlus<T> queryPlus, final ResponseContext responseContext) {
    final GroupByQuery query = (GroupByQuery) queryPlus.getQuery();
    final GroupByQueryConfig querySpecificConfig = configSupplier.get().withOverrides(query);
    final boolean isSingleThreaded = querySpecificConfig.isSingleThreaded();
    final Pair<IncrementalIndex, Accumulator<IncrementalIndex, T>> indexAccumulatorPair = GroupByQueryHelper.createIndexAccumulatorPair(query, null, querySpecificConfig);
    final Pair<Queue, Accumulator<Queue, T>> bySegmentAccumulatorPair = GroupByQueryHelper.createBySegmentAccumulatorPair();
    final boolean bySegment = QueryContexts.isBySegment(query);
    final int priority = QueryContexts.getPriority(query);
    final QueryPlus<T> threadSafeQueryPlus = queryPlus.withoutThreadUnsafeState();
    final List<ListenableFuture<Void>> futures = Lists.newArrayList(Iterables.transform(queryables, new Function<QueryRunner<T>, ListenableFuture<Void>>() {

        @Override
        public ListenableFuture<Void> apply(final QueryRunner<T> input) {
            if (input == null) {
                throw new ISE("Null queryRunner! Looks to be some segment unmapping action happening");
            }
            ListenableFuture<Void> future = queryProcessingPool.submitRunnerTask(new AbstractPrioritizedQueryRunnerCallable<Void, T>(priority, input) {

                @Override
                public Void call() {
                    try {
                        if (bySegment) {
                            input.run(threadSafeQueryPlus, responseContext).accumulate(bySegmentAccumulatorPair.lhs, bySegmentAccumulatorPair.rhs);
                        } else {
                            input.run(threadSafeQueryPlus, responseContext).accumulate(indexAccumulatorPair.lhs, indexAccumulatorPair.rhs);
                        }
                        return null;
                    } catch (QueryInterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (Exception e) {
                        log.error(e, "Exception with one of the sequences!");
                        Throwables.propagateIfPossible(e);
                        throw new RuntimeException(e);
                    }
                }
            });
            if (isSingleThreaded) {
                waitForFutureCompletion(query, ImmutableList.of(future), indexAccumulatorPair.lhs);
            }
            return future;
        }
    }));
    if (!isSingleThreaded) {
        waitForFutureCompletion(query, futures, indexAccumulatorPair.lhs);
    }
    if (bySegment) {
        return Sequences.simple(bySegmentAccumulatorPair.lhs);
    }
    return Sequences.withBaggage(Sequences.simple(Iterables.transform(indexAccumulatorPair.lhs.iterableWithPostAggregations(null, query.isDescending()), new Function<Row, T>() {

        @Override
        public T apply(Row input) {
            return (T) input;
        }
    })), indexAccumulatorPair.lhs);
}
Also used : Accumulator(org.apache.druid.java.util.common.guava.Accumulator) Function(com.google.common.base.Function) GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) ISE(org.apache.druid.java.util.common.ISE) Queue(java.util.Queue) GroupByQueryConfig(org.apache.druid.query.groupby.GroupByQueryConfig) IncrementalIndex(org.apache.druid.segment.incremental.IncrementalIndex) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Row(org.apache.druid.data.input.Row)

Aggregations

GroupByQueryConfig (org.apache.druid.query.groupby.GroupByQueryConfig)22 ByteBuffer (java.nio.ByteBuffer)11 GroupByQueryRunnerFactory (org.apache.druid.query.groupby.GroupByQueryRunnerFactory)10 Closer (org.apache.druid.java.util.common.io.Closer)7 ArrayList (java.util.ArrayList)6 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)6 GroupByQueryEngine (org.apache.druid.query.groupby.GroupByQueryEngine)6 List (java.util.List)5 StupidPool (org.apache.druid.collections.StupidPool)5 GroupByQueryQueryToolChest (org.apache.druid.query.groupby.GroupByQueryQueryToolChest)5 ResultRow (org.apache.druid.query.groupby.ResultRow)5 Interval (org.joda.time.Interval)5 CloseableStupidPool (org.apache.druid.collections.CloseableStupidPool)4 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)4 Row (org.apache.druid.data.input.Row)4 Accumulator (org.apache.druid.java.util.common.guava.Accumulator)4 DruidProcessingConfig (org.apache.druid.query.DruidProcessingConfig)4 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)4 Before (org.junit.Before)4 Test (org.junit.Test)4