use of org.apache.druid.query.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy 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.aggregation.cardinality.types.CardinalityAggregatorColumnSelectorStrategy in project druid by druid-io.
the class CardinalityAggregator method hashRow.
static void hashRow(ColumnSelectorPlus<CardinalityAggregatorColumnSelectorStrategy>[] selectorPluses, HyperLogLogCollector collector) {
final Hasher hasher = HASH_FUNCTION.newHasher();
for (int k = 0; k < selectorPluses.length; ++k) {
if (k != 0) {
hasher.putByte((byte) 0);
}
ColumnSelectorPlus<CardinalityAggregatorColumnSelectorStrategy> selectorPlus = selectorPluses[k];
selectorPlus.getColumnSelectorStrategy().hashRow(selectorPlus.getSelector(), hasher);
}
collector.add(hasher.hash().asBytes());
}
Aggregations