use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.
the class StringLastBufferAggregatorTest method testNonStringValue.
@Test
public void testNonStringValue() {
final long[] timestamps = { 1526724000L, 1526724600L };
final Double[] doubles = { null, 2.00 };
Integer maxStringBytes = 1024;
TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps);
TestObjectColumnSelector<Double> objectColumnSelector = new TestObjectColumnSelector<>(doubles);
StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
StringLastBufferAggregator agg = new StringLastBufferAggregator(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(1526724600L, (long) sp.lhs);
Assert.assertEquals("2.0", sp.rhs);
}
use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.
the class StringLastBufferAggregatorTest method testNullBufferAggregate.
@Test
public void testNullBufferAggregate() {
final long[] timestamps = { 1111L, 2222L, 6666L, 4444L, 5555L };
final String[] strings = { "CCCC", "AAAA", "BBBB", null, "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, 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[2], sp.rhs);
Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[2]), sp.lhs);
}
use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.
the class StringLastBufferAggregatorTest 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);
StringLastAggregatorFactory factory = new StringLastAggregatorFactory("billy", "billy", null, maxStringBytes);
StringLastBufferAggregator agg = new StringLastBufferAggregator(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", "DDDD", sp.rhs);
Assert.assertEquals("last string timestamp is the biggest", new Long(1526725900L), sp.lhs);
}
use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.
the class StringFirstBufferAggregatorTest method testNoStringValue.
@Test
public void testNoStringValue() {
final long[] timestamps = { 1526724000L, 1526724600L };
final Double[] doubles = { null, 2.00 };
Integer maxStringBytes = 1024;
TestLongColumnSelector longColumnSelector = new TestLongColumnSelector(timestamps);
TestObjectColumnSelector<Double> objectColumnSelector = new TestObjectColumnSelector<>(doubles);
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(1526724000L, (long) sp.lhs);
Assert.assertEquals(null, sp.rhs);
}
use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.
the class StringFirstBufferAggregatorTest 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);
StringFirstAggregatorFactory factory = new StringFirstAggregatorFactory("billy", "billy", null, maxStringBytes);
StringFirstBufferAggregator agg = new StringFirstBufferAggregator(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", strings[0], sp.rhs);
Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[0]), sp.lhs);
}
Aggregations