/** * Gets the aggregated records so far since the last call to {@link #reset()}. The records have a size that is at * most the maximum specified by the {@link Aggregation}. * * @return a {@link Clip} of the records so far. */ @Override public Clip getResult() { return Clip.of(getRecords()); }
@Override public void consume(BulletRecord data) { // Since Raw is the only strategy that can close and is really a special case, it should check before // consumption. Otherwise, Windows will need to expose the fact that the aggregation should not be fed more data // in order to prevent Raw from accidentally consuming/combining till only the Window is closed. if (data == null || isClosed()) { return; } consumed++; aggregate.add(data); }
/** * Returns a new {@link Strategy} instance that can handle this aggregation. * * @param aggregation The non-null, initialized {@link Aggregation} instance. * @param config The {@link BulletConfig} containing configuration for the strategy. * * @return The created instance of a strategy that can implement the Aggregation. */ public static Strategy findStrategy(Aggregation aggregation, BulletConfig config) { // Guaranteed to be present. switch (aggregation.getType()) { case COUNT_DISTINCT: return new CountDistinct(aggregation, config); case DISTRIBUTION: return new Distribution(aggregation, config); case RAW: return new Raw(aggregation, config); case TOP_K: return new TopK(aggregation, config); } // If we have any fields -> GroupBy return Utilities.isEmpty(aggregation.getFields()) ? new GroupAll(aggregation, config) : new GroupBy(aggregation, config); } }
/** * Since {@link #getData()} returns a {@link List} of {@link BulletRecord}, this method consumes * that list. If the deserialized List has a size that takes the aggregated records above the aggregation size, only * the first X records in the List will be combined till the size is reached. * * @param data A serialized {@link List} of {@link BulletRecord}. */ @Override public void combine(byte[] data) { // See the comment in consume on why the check for isClosed. if (data == null || isClosed()) { return; } ArrayList<BulletRecord> batch = SerializerDeserializer.fromBytes(data); if (batch == null || batch.isEmpty()) { return; } int batchSize = batch.size(); int maximumLeft = size - aggregate.size(); if (batchSize <= maximumLeft) { aggregate.addAll(batch); combined += batchSize; } else { aggregate.addAll(batch.subList(0, maximumLeft)); combined += maximumLeft; } }