Search in sources :

Example 6 with SerializablePair

use of io.druid.collections.SerializablePair in project druid by druid-io.

the class DoubleFirstAggregatorFactory method getCombiningFactory.

@Override
public AggregatorFactory getCombiningFactory() {
    return new DoubleFirstAggregatorFactory(name, name) {

        @Override
        public Aggregator factorize(ColumnSelectorFactory metricFactory) {
            final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
            return new DoubleFirstAggregator(name, null, null) {

                @Override
                public void aggregate() {
                    SerializablePair<Long, Double> pair = (SerializablePair<Long, Double>) 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 DoubleFirstBufferAggregator(null, null) {

                @Override
                public void aggregate(ByteBuffer buf, int position) {
                    SerializablePair<Long, Double> pair = (SerializablePair<Long, Double>) selector.get();
                    long firstTime = buf.getLong(position);
                    if (pair.lhs < firstTime) {
                        buf.putLong(position, pair.lhs);
                        buf.putDouble(position + Longs.BYTES, pair.rhs);
                    }
                }

                @Override
                public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                    inspector.visit("selector", selector);
                }
            };
        }
    };
}
Also used : SerializablePair(io.druid.collections.SerializablePair) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) RuntimeShapeInspector(io.druid.query.monomorphicprocessing.RuntimeShapeInspector) ByteBuffer(java.nio.ByteBuffer) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Example 7 with SerializablePair

use of io.druid.collections.SerializablePair in project druid by druid-io.

the class DoubleFirstAggregationTest method testCombine.

@Test
public void testCombine() {
    SerializablePair pair1 = new SerializablePair<>(1467225000L, 3.621);
    SerializablePair pair2 = new SerializablePair<>(1467240000L, 785.4);
    Assert.assertEquals(pair1, doubleFirstAggFactory.combine(pair1, pair2));
}
Also used : SerializablePair(io.druid.collections.SerializablePair) Test(org.junit.Test)

Example 8 with SerializablePair

use of io.druid.collections.SerializablePair in project druid by druid-io.

the class LongFirstAggregationTest method testCombine.

@Test
public void testCombine() {
    SerializablePair pair1 = new SerializablePair<>(1467225000L, 1263L);
    SerializablePair pair2 = new SerializablePair<>(1467240000L, 752713L);
    Assert.assertEquals(pair1, longFirstAggFactory.combine(pair1, pair2));
}
Also used : SerializablePair(io.druid.collections.SerializablePair) Test(org.junit.Test)

Aggregations

SerializablePair (io.druid.collections.SerializablePair)8 RuntimeShapeInspector (io.druid.query.monomorphicprocessing.RuntimeShapeInspector)4 ColumnSelectorFactory (io.druid.segment.ColumnSelectorFactory)4 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4