use of io.druid.collections.SerializablePair in project druid by druid-io.
the class LongFirstAggregatorFactory method getCombiningFactory.
@Override
public AggregatorFactory getCombiningFactory() {
return new LongFirstAggregatorFactory(name, name) {
@Override
public Aggregator factorize(ColumnSelectorFactory metricFactory) {
final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
return new LongFirstAggregator(name, null, null) {
@Override
public void aggregate() {
SerializablePair<Long, Long> pair = (SerializablePair<Long, Long>) selector.get();
if (pair.lhs < firstTime) {
firstTime = pair.lhs;
firstValue = pair.rhs;
}
}
};
}
@Override
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) {
final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
return new LongFirstBufferAggregator(null, null) {
@Override
public void aggregate(ByteBuffer buf, int position) {
SerializablePair<Long, Long> pair = (SerializablePair<Long, Long>) selector.get();
long firstTime = buf.getLong(position);
if (pair.lhs < firstTime) {
buf.putLong(position, pair.lhs);
buf.putLong(position + Longs.BYTES, pair.rhs);
}
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
}
};
}
use of io.druid.collections.SerializablePair in project druid by druid-io.
the class DoubleLastAggregatorFactory method getCombiningFactory.
@Override
public AggregatorFactory getCombiningFactory() {
return new DoubleLastAggregatorFactory(name, name) {
@Override
public Aggregator factorize(ColumnSelectorFactory metricFactory) {
final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
return new DoubleLastAggregator(name, null, null) {
@Override
public void aggregate() {
SerializablePair<Long, Double> pair = (SerializablePair<Long, Double>) selector.get();
if (pair.lhs >= lastTime) {
lastTime = pair.lhs;
lastValue = pair.rhs;
}
}
};
}
@Override
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) {
final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
return new DoubleLastBufferAggregator(null, null) {
@Override
public void aggregate(ByteBuffer buf, int position) {
SerializablePair<Long, Double> pair = (SerializablePair<Long, Double>) selector.get();
long lastTime = buf.getLong(position);
if (pair.lhs >= lastTime) {
buf.putLong(position, pair.lhs);
buf.putDouble(position + Longs.BYTES, pair.rhs);
}
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
}
};
}
use of io.druid.collections.SerializablePair in project druid by druid-io.
the class LongLastAggregatorFactory method getCombiningFactory.
@Override
public AggregatorFactory getCombiningFactory() {
return new LongLastAggregatorFactory(name, name) {
@Override
public Aggregator factorize(ColumnSelectorFactory metricFactory) {
final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
return new LongLastAggregator(name, null, null) {
@Override
public void aggregate() {
SerializablePair<Long, Long> pair = (SerializablePair<Long, Long>) selector.get();
if (pair.lhs >= lastTime) {
lastTime = pair.lhs;
lastValue = pair.rhs;
}
}
};
}
@Override
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) {
final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
return new LongLastBufferAggregator(null, null) {
@Override
public void aggregate(ByteBuffer buf, int position) {
SerializablePair<Long, Long> pair = (SerializablePair<Long, Long>) selector.get();
long lastTime = buf.getLong(position);
if (pair.lhs >= lastTime) {
buf.putLong(position, pair.lhs);
buf.putLong(position + Longs.BYTES, pair.rhs);
}
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
inspector.visit("selector", selector);
}
};
}
};
}
use of io.druid.collections.SerializablePair in project druid by druid-io.
the class DoubleLastAggregationTest method testCombine.
@Test
public void testCombine() {
SerializablePair pair1 = new SerializablePair<>(1467225000L, 3.621);
SerializablePair pair2 = new SerializablePair<>(1467240000L, 785.4);
Assert.assertEquals(pair2, doubleLastAggFactory.combine(pair1, pair2));
}
use of io.druid.collections.SerializablePair in project druid by druid-io.
the class LongLastAggregationTest method testCombine.
@Test
public void testCombine() {
SerializablePair pair1 = new SerializablePair<>(1467225000L, 64432L);
SerializablePair pair2 = new SerializablePair<>(1467240000L, 99999L);
Assert.assertEquals(pair2, longLastAggFactory.combine(pair1, pair2));
}
Aggregations