Search in sources :

Example 6 with TestLongColumnSelector

use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.

the class StringFirstAggregationTest method setup.

@Before
public void setup() {
    NullHandling.initializeForTests();
    stringFirstAggFactory = new StringFirstAggregatorFactory("billy", "nilly", null, MAX_STRING_SIZE);
    combiningAggFactory = stringFirstAggFactory.getCombiningFactory();
    timeSelector = new TestLongColumnSelector(times);
    customTimeSelector = new TestLongColumnSelector(customTimes);
    valueSelector = new TestObjectColumnSelector<>(strings);
    objectSelector = new TestObjectColumnSelector<>(pairs);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector(ColumnHolder.TIME_COLUMN_NAME)).andReturn(timeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("customTime")).andReturn(customTimeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("billy")).andReturn(objectSelector);
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.STRING));
    EasyMock.expect(colSelectorFactory.getColumnCapabilities("billy")).andReturn(null);
    EasyMock.replay(colSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) ColumnCapabilitiesImpl(org.apache.druid.segment.column.ColumnCapabilitiesImpl) Before(org.junit.Before)

Example 7 with TestLongColumnSelector

use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.

the class StringFirstBufferAggregatorTest method testNullBufferAggregate.

@Test
public void testNullBufferAggregate() {
    final long[] timestamps = { 2222L, 1111L, 3333L, 4444L, 5555L };
    final String[] strings = { null, "AAAA", "BBBB", "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[1], sp.rhs);
    Assert.assertEquals("last string timestamp is the biggest", new Long(timestamps[1]), sp.lhs);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ByteBuffer(java.nio.ByteBuffer) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Test(org.junit.Test)

Example 8 with TestLongColumnSelector

use of org.apache.druid.query.aggregation.TestLongColumnSelector 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);
}
Also used : TestObjectColumnSelector(org.apache.druid.query.aggregation.TestObjectColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) ByteBuffer(java.nio.ByteBuffer) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Test(org.junit.Test)

Example 9 with TestLongColumnSelector

use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.

the class DoubleLastAggregationTest method setup.

@Before
public void setup() {
    doubleLastAggFactory = new DoubleLastAggregatorFactory("billy", "nilly", null);
    combiningAggFactory = (DoubleLastAggregatorFactory) doubleLastAggFactory.getCombiningFactory();
    timeSelector = new TestLongColumnSelector(times);
    customTimeSelector = new TestLongColumnSelector(customTimes);
    valueSelector = new TestDoubleColumnSelectorImpl(doubles);
    objectSelector = new TestObjectColumnSelector<>(pairs);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector(ColumnHolder.TIME_COLUMN_NAME)).andReturn(timeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("customTime")).andReturn(customTimeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("billy")).andReturn(objectSelector);
    EasyMock.replay(colSelectorFactory);
}
Also used : ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Before(org.junit.Before)

Example 10 with TestLongColumnSelector

use of org.apache.druid.query.aggregation.TestLongColumnSelector in project druid by druid-io.

the class FloatLastAggregationTest method setup.

@Before
public void setup() {
    floatLastAggregatorFactory = new FloatLastAggregatorFactory("billy", "nilly", null);
    combiningAggFactory = (FloatLastAggregatorFactory) floatLastAggregatorFactory.getCombiningFactory();
    timeSelector = new TestLongColumnSelector(times);
    customTimeSelector = new TestLongColumnSelector(customTimes);
    valueSelector = new TestFloatColumnSelector(floats);
    objectSelector = new TestObjectColumnSelector<>(pairs);
    colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector(ColumnHolder.TIME_COLUMN_NAME)).andReturn(timeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("customTime")).andReturn(customTimeSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
    EasyMock.expect(colSelectorFactory.makeColumnValueSelector("billy")).andReturn(objectSelector);
    EasyMock.replay(colSelectorFactory);
}
Also used : TestFloatColumnSelector(org.apache.druid.query.aggregation.TestFloatColumnSelector) ColumnSelectorFactory(org.apache.druid.segment.ColumnSelectorFactory) TestLongColumnSelector(org.apache.druid.query.aggregation.TestLongColumnSelector) Before(org.junit.Before)

Aggregations

TestLongColumnSelector (org.apache.druid.query.aggregation.TestLongColumnSelector)17 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)9 Before (org.junit.Before)9 ByteBuffer (java.nio.ByteBuffer)8 SerializablePairLongString (org.apache.druid.query.aggregation.SerializablePairLongString)8 TestObjectColumnSelector (org.apache.druid.query.aggregation.TestObjectColumnSelector)8 Test (org.junit.Test)8 TestDoubleColumnSelectorImpl (org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl)2 TestFloatColumnSelector (org.apache.druid.query.aggregation.TestFloatColumnSelector)2 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)2