use of org.apache.druid.query.aggregation.TestObjectColumnSelector in project druid by druid-io.
the class SketchAggregationTest method testUpdateUnionWithNullInList.
@Test
public void testUpdateUnionWithNullInList() {
List<String> value = new ArrayList<>();
value.add("foo");
value.add(null);
value.add("");
value.add("bar");
List[] columnValues = new List[] { value };
final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
final Aggregator agg = new SketchAggregator(selector, 4096);
agg.aggregate();
Assert.assertFalse(agg.isNull());
Assert.assertNotNull(agg.get());
Assert.assertTrue(agg.get() instanceof SketchHolder);
Assert.assertEquals(2, ((SketchHolder) agg.get()).getEstimate(), 0);
Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
Assert.assertEquals(2, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
use of org.apache.druid.query.aggregation.TestObjectColumnSelector in project druid by druid-io.
the class SketchAggregationTest method testUpdateUnionWithDouble.
@Test
public void testUpdateUnionWithDouble() {
Double[] columnValues = new Double[] { 2.0 };
final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
final Aggregator agg = new SketchAggregator(selector, 4096);
agg.aggregate();
Assert.assertFalse(agg.isNull());
Assert.assertNotNull(agg.get());
Assert.assertTrue(agg.get() instanceof SketchHolder);
Assert.assertEquals(1, ((SketchHolder) agg.get()).getEstimate(), 0);
Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
Assert.assertEquals(1, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
use of org.apache.druid.query.aggregation.TestObjectColumnSelector in project druid by druid-io.
the class SketchToStringPostAggregatorTest method testCompute.
@Test
public void testCompute() {
// not going to iterate over the selector since getting a summary of an empty sketch is sufficient
final TestObjectColumnSelector selector = new TestObjectColumnSelector(new Object[0]);
final Aggregator agg = new SketchAggregator(selector, 4096);
final Map<String, Object> fields = new HashMap<>();
fields.put("sketch", agg.get());
final PostAggregator postAgg = new SketchToStringPostAggregator("summary", new FieldAccessPostAggregator("field", "sketch"));
final String summary = (String) postAgg.compute(fields);
Assert.assertNotNull(summary);
Assert.assertTrue(summary.contains("SUMMARY"));
}
use of org.apache.druid.query.aggregation.TestObjectColumnSelector in project druid by druid-io.
the class VarianceAggregatorTest method testObjectVarianceBufferAggregatorWithZeroCount.
@Test
public void testObjectVarianceBufferAggregatorWithZeroCount() {
VarianceAggregatorCollector holder1 = new VarianceAggregatorCollector().add(1.1f);
VarianceAggregatorCollector holder2 = new VarianceAggregatorCollector().add(2.7f);
VarianceAggregatorCollector holder3 = new VarianceAggregatorCollector();
VarianceAggregatorCollector[] values = { holder1, holder2, holder3 };
TestObjectColumnSelector<VarianceAggregatorCollector> selector = new TestObjectColumnSelector(values);
colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(selector);
EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(new ColumnCapabilitiesImpl().setType(VarianceAggregatorFactory.TYPE));
EasyMock.replay(colSelectorFactory);
VarianceBufferAggregator agg = (VarianceBufferAggregator) aggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[aggFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 0, 0d, 0d);
aggregate(selector, agg, buffer, 0);
assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 1, 1.1d, 0d);
aggregate(selector, agg, buffer, 0);
assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 2, 3.8d, 1.28d);
aggregate(selector, agg, buffer, 0);
assertValues((VarianceAggregatorCollector) agg.get(buffer, 0), 2, 3.8d, 1.28d);
}
use of org.apache.druid.query.aggregation.TestObjectColumnSelector in project druid by druid-io.
the class StringFirstBufferAggregatorTest method testBufferAggregate.
@Test
public void testBufferAggregate() {
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);
StringFirstAggregatorFactory factory = new StringFirstAggregatorFactory("billy", "billy", null, maxStringBytes);
StringFirstBufferAggregator agg = new StringFirstBufferAggregator(longColumnSelector, objectColumnSelector, maxStringBytes, false);
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", strings[0], sp.rhs);
Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[0]), sp.lhs);
}
Aggregations