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;
}
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)));
}
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);
}
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();
}
}));
}
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)));
}
Aggregations