@Override public AggregatorFactory getCombiningFactory() { return new LongSumAggregatorFactory(name, name, null, macroTable); }
@Test public void testComparator() { final TestLongColumnSelector selector = new TestLongColumnSelector(new long[]{18293L}); LongSumAggregator agg = new LongSumAggregator(selector); Object first = agg.get(); agg.aggregate(); Comparator comp = new LongSumAggregatorFactory("null", "null").getComparator(); Assert.assertEquals(-1, comp.compare(first, agg.get())); Assert.assertEquals(0, comp.compare(first, first)); Assert.assertEquals(0, comp.compare(agg.get(), agg.get())); Assert.assertEquals(1, comp.compare(agg.get(), first)); } }
@Override protected BaseLongColumnValueSelector selector(ColumnSelectorFactory metricFactory) { return getLongColumnSelector( metricFactory, 0L ); }
@Override public AggregatorFactory getCombiningFactory() { return new LongSumAggregatorFactory(name, name); }
@Override public AggregatorFactory getCombiningFactory() { return new LongSumAggregatorFactory(name, name); }
@Override public List<AggregatorFactory> getRequiredColumns() { return Collections.singletonList(new LongSumAggregatorFactory(fieldName, fieldName, expression, macroTable)); }
static AggregatorFactory createSumAggregatorFactory( final ValueType aggregationType, final String name, final String fieldName, final String expression, final ExprMacroTable macroTable ) { switch (aggregationType) { case LONG: return new LongSumAggregatorFactory(name, fieldName, expression, macroTable); case FLOAT: return new FloatSumAggregatorFactory(name, fieldName, expression, macroTable); case DOUBLE: return new DoubleSumAggregatorFactory(name, fieldName, expression, macroTable); default: throw new ISE("Cannot create aggregator factory for type[%s]", aggregationType); } } }
@SuppressWarnings("unchecked") public int countRows(String dataSource, String interval) { TimeseriesQuery query = Druids.newTimeseriesQueryBuilder() .dataSource(dataSource) .aggregators( ImmutableList.of( new LongSumAggregatorFactory("rows", "count") ) ) .granularity(Granularities.ALL) .intervals(interval) .build(); List<Map<String, Object>> results = queryClient.query(getQueryURL(broker), query); if (results.isEmpty()) { return 0; } else { Map<String, Object> map = (Map<String, Object>) results.get(0).get("result"); return (Integer) map.get("rows"); } }
private BufferArrayGrouper newGrouper( TestColumnSelectorFactory columnSelectorFactory, int bufferSize ) { final ByteBuffer buffer = ByteBuffer.allocate(bufferSize); final BufferArrayGrouper grouper = new BufferArrayGrouper( Suppliers.ofInstance(buffer), columnSelectorFactory, new AggregatorFactory[]{ new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count") }, 1000 ); grouper.init(); return grouper; }
private StreamingMergeSortedGrouper<Integer> newGrouper( TestColumnSelectorFactory columnSelectorFactory, int bufferSize ) { final ByteBuffer buffer = ByteBuffer.allocate(bufferSize); final StreamingMergeSortedGrouper<Integer> grouper = new StreamingMergeSortedGrouper<>( Suppliers.ofInstance(buffer), GrouperTestUtil.intKeySerde(), columnSelectorFactory, new AggregatorFactory[]{ new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count") }, System.currentTimeMillis() + 1000L ); grouper.init(); return grouper; } }
private BufferHashGrouper<Integer> makeGrouper( TestColumnSelectorFactory columnSelectorFactory, int bufferSize, int initialBuckets, float maxLoadFactor ) { final ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize); final BufferHashGrouper<Integer> grouper = new BufferHashGrouper<>( Suppliers.ofInstance(buffer), GrouperTestUtil.intKeySerde(), columnSelectorFactory, new AggregatorFactory[]{ new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count") }, Integer.MAX_VALUE, maxLoadFactor, initialBuckets, true ); grouper.init(); return grouper; } }
@Test public void testSerde() throws Exception { ObjectMapper jsonMapper = TestHelper.makeJsonMapper(); AggregatorFactory[] aggregators = new AggregatorFactory[] { new LongSumAggregatorFactory("out", "in") }; Metadata metadata = new Metadata( Collections.singletonMap("k", "v"), aggregators, null, Granularities.ALL, Boolean.FALSE ); Metadata other = jsonMapper.readValue( jsonMapper.writeValueAsString(metadata), Metadata.class ); Assert.assertEquals(metadata, other); }
private static LimitedBufferHashGrouper<Integer> makeGrouper( TestColumnSelectorFactory columnSelectorFactory, int bufferSize, int initialBuckets, int limit ) { LimitedBufferHashGrouper<Integer> grouper = new LimitedBufferHashGrouper<>( Suppliers.ofInstance(ByteBuffer.allocate(bufferSize)), GrouperTestUtil.intKeySerde(), columnSelectorFactory, new AggregatorFactory[]{ new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count") }, Integer.MAX_VALUE, 0.5f, initialBuckets, limit, false ); grouper.init(); return grouper; } }
new LongSumAggregatorFactory("A", "A"), new LongSumAggregatorFactory("C", "C") }); closer.closeLater(index2); new LongSumAggregatorFactory("C", "C"), new LongSumAggregatorFactory("B", "B") }); closer.closeLater(index5); true, new AggregatorFactory[]{ new LongSumAggregatorFactory("B", "B"), new LongSumAggregatorFactory("A", "A"), new LongSumAggregatorFactory("D", "D") }, tmpDirMerged,
0, ImmutableMap.of( "foo", new LongSumAggregatorFactory("foo", "foo"), "bar", new DoubleSumAggregatorFactory("bar", "bar") ), Assert.assertEquals( ImmutableMap.of( "foo", new LongSumAggregatorFactory("foo", "foo"), "bar", new DoubleSumAggregatorFactory("bar", "bar") ),
new LongSumAggregatorFactory("A", "A") }); closer.closeLater(index1); new LongSumAggregatorFactory("A", "A"), new LongSumAggregatorFactory("C", "C") }); toMerge, true, new AggregatorFactory[]{new LongSumAggregatorFactory("A", "A"), new LongSumAggregatorFactory("C", "C")}, tmpDirMerged, indexSpec
new LongSumAggregatorFactory("A", "A") }); index1.add(new MapBasedInputRow(
.withMinTimestamp(JodaUtils.MIN_INSTANT) .withDimensionsSpec(ROW_PARSER) .withMetrics(new LongSumAggregatorFactory(METRICS[0], METRICS[0])) .build(); final IncrementalIndex index = new IncrementalIndex.Builder()
public LongFilteringTest( String testName, IndexBuilder indexBuilder, Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher, boolean cnf, boolean optimize ) { super( testName, ROWS, indexBuilder.schema( new IncrementalIndexSchema.Builder() .withMetrics(new LongSumAggregatorFactory(LONG_COLUMN, LONG_COLUMN)) .build() ), finisher, cnf, optimize ); }
@Test public void testRequiredBufferCapacity() { int[] cardinalityArray = new int[]{1, 10, Integer.MAX_VALUE - 1}; AggregatorFactory[] aggregatorFactories = new AggregatorFactory[]{ new LongSumAggregatorFactory("sum", "sum") }; long[] requiredSizes; if (NullHandling.sqlCompatible()) { // We need additional size to store nullability information. requiredSizes = new long[]{19, 101, 19058917368L}; } else { requiredSizes = new long[]{17, 90, 16911433721L}; } for (int i = 0; i < cardinalityArray.length; i++) { Assert.assertEquals(requiredSizes[i], BufferArrayGrouper.requiredBufferCapacity( cardinalityArray[i], aggregatorFactories )); } } }