use of org.apache.druid.query.aggregation.SerializablePairLongString in project druid by druid-io.
the class StringLastBufferAggregatorTest method testBufferAggregateWithFoldCheck.
@Test
public void testBufferAggregateWithFoldCheck() {
final long[] timestamps = { 1526724600L, 1526724700L, 1526724800L, 1526725900L, 1526725000L };
final String[] strings = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE" };
Integer maxStringBytes = 1024;
TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps);
TestObjectColumnSelector<String> objectColumnSelector = new TestObjectColumnSelector<>(strings);
StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
StringLastBufferAggregator agg = new StringLastBufferAggregator(longColumnSelector, objectColumnSelector, maxStringBytes, true);
ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSize());
int position = 0;
agg.init(buf, position);
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < timestamps.length; i++) {
aggregateBuffer(longColumnSelector, objectColumnSelector, agg, buf, position);
}
SerializablePairLongString sp = ((SerializablePairLongString) agg.get(buf, position));
Assert.assertEquals("expected last string value", "DDDD", sp.rhs);
Assert.assertEquals("last string timestamp is the biggest", new Long(1526725900L), sp.lhs);
}
use of org.apache.druid.query.aggregation.SerializablePairLongString in project druid by druid-io.
the class StringFirstAggregationTest method testCombineRightLower.
@Test
public void testCombineRightLower() {
SerializablePairLongString pair1 = new SerializablePairLongString(1467240000L, "AAAA");
SerializablePairLongString pair2 = new SerializablePairLongString(1467225000L, "BBBB");
Assert.assertEquals(pair2, stringFirstAggFactory.combine(pair1, pair2));
}
use of org.apache.druid.query.aggregation.SerializablePairLongString in project druid by druid-io.
the class StringLastBufferAggregator method aggregate.
@Override
public void aggregate(ByteBuffer buf, int position) {
if (timeSelector.isNull()) {
return;
}
if (needsFoldCheck) {
// Less efficient code path when folding is a possibility (we must read the value selector first just in case
// it's a foldable object).
final SerializablePairLongString inPair = StringFirstLastUtils.readPairFromSelectors(timeSelector, valueSelector);
if (inPair != null) {
final long lastTime = buf.getLong(position);
if (inPair.lhs >= lastTime) {
StringFirstLastUtils.writePair(buf, position, new SerializablePairLongString(inPair.lhs, inPair.rhs), maxStringBytes);
}
}
} else {
final long time = timeSelector.getLong();
final long lastTime = buf.getLong(position);
if (time >= lastTime) {
final String value = DimensionHandlerUtils.convertObjectToString(valueSelector.getObject());
StringFirstLastUtils.writePair(buf, position, new SerializablePairLongString(time, value), maxStringBytes);
}
}
}
Aggregations