Search in sources :

Example 1 with ColumnSelectorPlus

use of io.druid.query.ColumnSelectorPlus in project druid by druid-io.

the class GroupByQueryEngineV2 method process.

public static Sequence<Row> process(final GroupByQuery query, final StorageAdapter storageAdapter, final StupidPool<ByteBuffer> intermediateResultsBufferPool, final GroupByQueryConfig config) {
    if (storageAdapter == null) {
        throw new ISE("Null storage adapter found. Probably trying to issue a query against a segment being memory unmapped.");
    }
    final List<Interval> intervals = query.getQuerySegmentSpec().getIntervals();
    if (intervals.size() != 1) {
        throw new IAE("Should only have one interval, got[%s]", intervals);
    }
    final Sequence<Cursor> cursors = storageAdapter.makeCursors(Filters.toFilter(query.getDimFilter()), intervals.get(0), query.getVirtualColumns(), query.getGranularity(), false);
    final ResourceHolder<ByteBuffer> bufferHolder = intermediateResultsBufferPool.take();
    final String fudgeTimestampString = Strings.emptyToNull(query.getContextValue(GroupByStrategyV2.CTX_KEY_FUDGE_TIMESTAMP, ""));
    final DateTime fudgeTimestamp = fudgeTimestampString == null ? null : new DateTime(Long.parseLong(fudgeTimestampString));
    return Sequences.concat(Sequences.withBaggage(Sequences.map(cursors, new Function<Cursor, Sequence<Row>>() {

        @Override
        public Sequence<Row> apply(final Cursor cursor) {
            return new BaseSequence<>(new BaseSequence.IteratorMaker<Row, GroupByEngineIterator>() {

                @Override
                public GroupByEngineIterator make() {
                    ColumnSelectorPlus<GroupByColumnSelectorStrategy>[] selectorPlus = DimensionHandlerUtils.createColumnSelectorPluses(STRATEGY_FACTORY, query.getDimensions(), cursor);
                    return new GroupByEngineIterator(query, config, cursor, bufferHolder.get(), fudgeTimestamp, createGroupBySelectorPlus(selectorPlus));
                }

                @Override
                public void cleanup(GroupByEngineIterator iterFromMake) {
                    iterFromMake.close();
                }
            });
        }
    }), new Closeable() {

        @Override
        public void close() throws IOException {
            CloseQuietly.close(bufferHolder);
        }
    }));
}
Also used : GroupByColumnSelectorPlus(io.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorPlus) ColumnSelectorPlus(io.druid.query.ColumnSelectorPlus) Closeable(java.io.Closeable) BaseSequence(io.druid.java.util.common.guava.BaseSequence) Sequence(io.druid.java.util.common.guava.Sequence) IAE(io.druid.java.util.common.IAE) Cursor(io.druid.segment.Cursor) ByteBuffer(java.nio.ByteBuffer) DateTime(org.joda.time.DateTime) ISE(io.druid.java.util.common.ISE) Interval(org.joda.time.Interval)

Example 2 with ColumnSelectorPlus

use of io.druid.query.ColumnSelectorPlus in project druid by druid-io.

the class DimensionHandlerUtils method createColumnSelectorPluses.

/**
   * Creates an array of ColumnSelectorPlus objects, selectors that handle type-specific operations within
   * query processing engines, using a strategy factory provided by the query engine. One ColumnSelectorPlus
   * will be created for each column specified in dimensionSpecs.
   *
   * The ColumnSelectorPlus provides access to a type strategy (e.g., how to group on a float column)
   * and a value selector for a single column.
   *
   * A caller should define a strategy factory that provides an interface for type-specific operations
   * in a query engine. See GroupByStrategyFactory for a reference.
   *
   * @param <ColumnSelectorStrategyClass> The strategy type created by the provided strategy factory.
   * @param strategyFactory A factory provided by query engines that generates type-handling strategies
   * @param dimensionSpecs The set of columns to generate ColumnSelectorPlus objects for
   * @param cursor Used to create value selectors for columns.
   * @return An array of ColumnSelectorPlus objects, in the order of the columns specified in dimensionSpecs
   */
public static <ColumnSelectorStrategyClass extends ColumnSelectorStrategy> ColumnSelectorPlus<ColumnSelectorStrategyClass>[] createColumnSelectorPluses(ColumnSelectorStrategyFactory<ColumnSelectorStrategyClass> strategyFactory, List<DimensionSpec> dimensionSpecs, ColumnSelectorFactory cursor) {
    int dimCount = dimensionSpecs.size();
    ColumnSelectorPlus<ColumnSelectorStrategyClass>[] dims = new ColumnSelectorPlus[dimCount];
    for (int i = 0; i < dimCount; i++) {
        final DimensionSpec dimSpec = dimensionSpecs.get(i);
        final String dimName = dimSpec.getDimension();
        final ColumnValueSelector selector = getColumnValueSelectorFromDimensionSpec(dimSpec, cursor);
        ColumnSelectorStrategyClass strategy = makeStrategy(strategyFactory, dimSpec, cursor.getColumnCapabilities(dimSpec.getDimension()), selector);
        final ColumnSelectorPlus<ColumnSelectorStrategyClass> selectorPlus = new ColumnSelectorPlus<>(dimName, dimSpec.getOutputName(), strategy, selector);
        dims[i] = selectorPlus;
    }
    return dims;
}
Also used : ColumnSelectorPlus(io.druid.query.ColumnSelectorPlus) DimensionSpec(io.druid.query.dimension.DimensionSpec)

Example 3 with ColumnSelectorPlus

use of io.druid.query.ColumnSelectorPlus in project druid by druid-io.

the class TopNMapFn method apply.

@Override
@SuppressWarnings("unchecked")
public Result<TopNResultValue> apply(Cursor cursor) {
    final ColumnSelectorPlus selectorPlus = DimensionHandlerUtils.createColumnSelectorPlus(STRATEGY_FACTORY, query.getDimensionSpec(), cursor);
    if (selectorPlus.getSelector() == null) {
        return null;
    }
    TopNParams params = null;
    try {
        params = topNAlgorithm.makeInitParams(selectorPlus, cursor);
        TopNResultBuilder resultBuilder = BaseTopNAlgorithm.makeResultBuilder(params, query);
        topNAlgorithm.run(params, resultBuilder, null);
        return resultBuilder.build();
    } finally {
        topNAlgorithm.cleanup(params);
    }
}
Also used : ColumnSelectorPlus(io.druid.query.ColumnSelectorPlus)

Example 4 with ColumnSelectorPlus

use of io.druid.query.ColumnSelectorPlus in project druid by druid-io.

the class CardinalityAggregatorTest method testBufferAggregateRows.

@Test
public void testBufferAggregateRows() throws Exception {
    CardinalityBufferAggregator agg = new CardinalityBufferAggregator(dimInfoList.toArray(new ColumnSelectorPlus[] {}), true);
    int maxSize = rowAggregatorFactory.getMaxIntermediateSize();
    ByteBuffer buf = ByteBuffer.allocate(maxSize + 64);
    int pos = 10;
    buf.limit(pos + maxSize);
    agg.init(buf, pos);
    for (int i = 0; i < values1.size(); ++i) {
        bufferAggregate(selectorList, agg, buf, pos);
    }
    Assert.assertEquals(9.0, (Double) rowAggregatorFactory.finalizeComputation(agg.get(buf, pos)), 0.05);
}
Also used : ColumnSelectorPlus(io.druid.query.ColumnSelectorPlus) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with ColumnSelectorPlus

use of io.druid.query.ColumnSelectorPlus in project druid by druid-io.

the class CardinalityAggregatorBenchmark method setUp.

protected void setUp() {
    Iterable<String[]> values = FluentIterable.from(ContiguousSet.create(Range.closedOpen(0, 500), DiscreteDomain.integers())).transform(new Function<Integer, String[]>() {

        @Override
        public String[] apply(Integer input) {
            if (multivaluedSized == 1) {
                return new String[] { input.toString() };
            } else {
                String[] res = new String[multivaluedSized];
                String value = input.toString();
                for (int i = 0; i < multivaluedSized; ++i) {
                    res[i] = value + i;
                }
                return res;
            }
        }
    }).cycle().limit(MAX);
    final DimensionSpec dimSpec1 = new DefaultDimensionSpec("dim1", "dim1");
    final CardinalityAggregatorTest.TestDimensionSelector dim1 = new CardinalityAggregatorTest.TestDimensionSelector(values, null);
    final ColumnSelectorPlus<CardinalityAggregatorColumnSelectorStrategy> dimInfo1 = new ColumnSelectorPlus(dimSpec1.getDimension(), dimSpec1.getOutputName(), new StringCardinalityAggregatorColumnSelectorStrategy(), dim1);
    selectorList = Lists.newArrayList((DimensionSelector) dim1);
    dimInfos = new ColumnSelectorPlus[] { dimInfo1 };
    agg = new CardinalityBufferAggregator(dimInfos, byRow);
    CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", Lists.<DimensionSpec>newArrayList(new DefaultDimensionSpec("dim1", "dim1")), byRow);
    int maxSize = factory.getMaxIntermediateSize();
    buf = ByteBuffer.allocate(maxSize + 64);
    pos = 10;
    buf.limit(pos + maxSize);
    agg.init(buf, pos);
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) ColumnSelectorPlus(io.druid.query.ColumnSelectorPlus) DimensionSelector(io.druid.segment.DimensionSelector) StringCardinalityAggregatorColumnSelectorStrategy(io.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy) CardinalityAggregatorColumnSelectorStrategy(io.druid.query.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) StringCardinalityAggregatorColumnSelectorStrategy(io.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy)

Aggregations

ColumnSelectorPlus (io.druid.query.ColumnSelectorPlus)6 ByteBuffer (java.nio.ByteBuffer)3 DimensionSpec (io.druid.query.dimension.DimensionSpec)2 Test (org.junit.Test)2 IAE (io.druid.java.util.common.IAE)1 ISE (io.druid.java.util.common.ISE)1 BaseSequence (io.druid.java.util.common.guava.BaseSequence)1 Sequence (io.druid.java.util.common.guava.Sequence)1 CardinalityAggregatorColumnSelectorStrategy (io.druid.query.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy)1 StringCardinalityAggregatorColumnSelectorStrategy (io.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy)1 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)1 GroupByColumnSelectorPlus (io.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorPlus)1 Cursor (io.druid.segment.Cursor)1 DimensionSelector (io.druid.segment.DimensionSelector)1 Closeable (java.io.Closeable)1 DateTime (org.joda.time.DateTime)1 Interval (org.joda.time.Interval)1