Search in sources :

Example 1 with ColumnSelectorPlus

use of org.apache.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.
 * <p>
 * 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.
 * <p>
 * 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 <Strategy>            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 columnSelectorFactory Used to create value selectors for columns.
 * @return An array of ColumnSelectorPlus objects, in the order of the columns specified in dimensionSpecs
 * @see ColumnProcessors#makeProcessor which may replace this in the future
 */
public static <Strategy extends ColumnSelectorStrategy> ColumnSelectorPlus<Strategy>[] createColumnSelectorPluses(ColumnSelectorStrategyFactory<Strategy> strategyFactory, List<DimensionSpec> dimensionSpecs, ColumnSelectorFactory columnSelectorFactory) {
    int dimCount = dimensionSpecs.size();
    @SuppressWarnings("unchecked") ColumnSelectorPlus<Strategy>[] 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, columnSelectorFactory);
        Strategy strategy = makeStrategy(strategyFactory, dimSpec, columnSelectorFactory.getColumnCapabilities(dimSpec.getDimension()), selector);
        final ColumnSelectorPlus<Strategy> selectorPlus = new ColumnSelectorPlus<>(dimName, dimSpec.getOutputName(), strategy, selector);
        dims[i] = selectorPlus;
    }
    return dims;
}
Also used : ColumnSelectorPlus(org.apache.druid.query.ColumnSelectorPlus) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnSelectorStrategy(org.apache.druid.query.dimension.ColumnSelectorStrategy)

Example 2 with ColumnSelectorPlus

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

the class CardinalityAggregatorTest method testBufferAggregateRows.

@Test
public void testBufferAggregateRows() {
    CardinalityBufferAggregator agg = new CardinalityBufferAggregator(dimInfoList.toArray(new ColumnSelectorPlus[0]), true);
    int maxSize = rowAggregatorFactory.getMaxIntermediateSizeWithNulls();
    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);
    Assert.assertEquals(9L, rowAggregatorFactoryRounded.finalizeComputation(agg.get(buf, pos)));
}
Also used : ColumnSelectorPlus(org.apache.druid.query.ColumnSelectorPlus) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with ColumnSelectorPlus

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

the class CardinalityAggregatorBenchmark method setUp.

@Override
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 = Collections.singletonList((DimensionSelector) dim1);
    dimInfos = new ColumnSelectorPlus[] { dimInfo1 };
    agg = new CardinalityBufferAggregator(dimInfos, byRow);
    CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", Collections.singletonList(new DefaultDimensionSpec("dim1", "dim1")), byRow);
    int maxSize = factory.getMaxIntermediateSizeWithNulls();
    buf = ByteBuffer.allocate(maxSize + 64);
    pos = 10;
    buf.limit(pos + maxSize);
    agg.init(buf, pos);
}
Also used : DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ColumnSelectorPlus(org.apache.druid.query.ColumnSelectorPlus) DimensionSelector(org.apache.druid.segment.DimensionSelector) CardinalityAggregatorColumnSelectorStrategy(org.apache.druid.query.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy) StringCardinalityAggregatorColumnSelectorStrategy(org.apache.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) StringCardinalityAggregatorColumnSelectorStrategy(org.apache.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy)

Example 4 with ColumnSelectorPlus

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

the class GroupByQueryEngineV2 method processNonVectorized.

private static Sequence<ResultRow> processNonVectorized(final GroupByQuery query, final StorageAdapter storageAdapter, final ByteBuffer processingBuffer, @Nullable final DateTime fudgeTimestamp, final GroupByQueryConfig querySpecificConfig, @Nullable final Filter filter, final Interval interval) {
    final Sequence<Cursor> cursors = storageAdapter.makeCursors(filter, interval, query.getVirtualColumns(), query.getGranularity(), false, null);
    return cursors.flatMap(cursor -> new BaseSequence<>(new BaseSequence.IteratorMaker<ResultRow, GroupByEngineIterator<?>>() {

        @Override
        public GroupByEngineIterator make() {
            final ColumnSelectorFactory columnSelectorFactory = cursor.getColumnSelectorFactory();
            final ColumnSelectorPlus<GroupByColumnSelectorStrategy>[] selectorPlus = DimensionHandlerUtils.createColumnSelectorPluses(STRATEGY_FACTORY, query.getDimensions(), columnSelectorFactory);
            final GroupByColumnSelectorPlus[] dims = createGroupBySelectorPlus(selectorPlus, query.getResultRowDimensionStart());
            final int cardinalityForArrayAggregation = getCardinalityForArrayAggregation(querySpecificConfig, query, storageAdapter, processingBuffer);
            if (cardinalityForArrayAggregation >= 0) {
                return new ArrayAggregateIterator(query, querySpecificConfig, cursor, processingBuffer, fudgeTimestamp, dims, hasNoExplodingDimensions(columnSelectorFactory, query.getDimensions()), cardinalityForArrayAggregation);
            } else {
                return new HashAggregateIterator(query, querySpecificConfig, cursor, processingBuffer, fudgeTimestamp, dims, hasNoExplodingDimensions(columnSelectorFactory, query.getDimensions()));
            }
        }

        @Override
        public void cleanup(GroupByEngineIterator iterFromMake) {
            iterFromMake.close();
        }
    }));
}
Also used : GroupByColumnSelectorPlus(org.apache.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorPlus) ColumnSelectorPlus(org.apache.druid.query.ColumnSelectorPlus) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) Cursor(org.apache.druid.segment.Cursor) GroupByColumnSelectorPlus(org.apache.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorPlus)

Example 5 with ColumnSelectorPlus

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

the class CardinalityAggregatorTest method testBufferAggregateValues.

@Test
public void testBufferAggregateValues() {
    CardinalityBufferAggregator agg = new CardinalityBufferAggregator(dimInfoList.toArray(new ColumnSelectorPlus[0]), false);
    int maxSize = valueAggregatorFactory.getMaxIntermediateSizeWithNulls();
    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(NullHandling.replaceWithDefault() ? 7.0 : 6.0, (Double) valueAggregatorFactory.finalizeComputation(agg.get(buf, pos)), 0.05);
    Assert.assertEquals(NullHandling.replaceWithDefault() ? 7L : 6L, rowAggregatorFactoryRounded.finalizeComputation(agg.get(buf, pos)));
}
Also used : ColumnSelectorPlus(org.apache.druid.query.ColumnSelectorPlus) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ColumnSelectorPlus (org.apache.druid.query.ColumnSelectorPlus)5 ByteBuffer (java.nio.ByteBuffer)2 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)2 Test (org.junit.Test)2 CardinalityAggregatorColumnSelectorStrategy (org.apache.druid.query.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy)1 StringCardinalityAggregatorColumnSelectorStrategy (org.apache.druid.query.aggregation.cardinality.types.StringCardinalityAggregatorColumnSelectorStrategy)1 ColumnSelectorStrategy (org.apache.druid.query.dimension.ColumnSelectorStrategy)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 GroupByColumnSelectorPlus (org.apache.druid.query.groupby.epinephelinae.column.GroupByColumnSelectorPlus)1 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)1 Cursor (org.apache.druid.segment.Cursor)1 DimensionSelector (org.apache.druid.segment.DimensionSelector)1