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