/** * Adds all the {@link BulletRecord} and the {@link Meta} from the given {@link Clip} to this. * * @param clip The clip to add. * @return This Clip for chaining. */ public Clip add(Clip clip) { if (clip != null) { add(clip.getMeta()); add(clip.getRecords()); } return this; }
/** * Gets the result from the data presented to the sketch as a {@link Clip}. Also adds {@link Meta} if * asked for. * * @param metaKey If set to a non-null value, Sketch metadata will be added to the result. * @param conceptKeys If provided, these {@link Concept} names will be added to the metadata. * @return A {@link Clip} of the results. */ public Clip getResult(String metaKey, Map<String, String> conceptKeys) { // Subclasses are charge of adding data. We'll just create an empty Clip with the metadata. return Clip.of(getMetadata(metaKey, conceptKeys)); }
/** * Get the {@link Meta} so far. By default, returns an empty one. * * @return The resulting metadata of the data aggregated so far. */ @Override default Meta getMetadata() { return new Meta(); } }
/** * Tags additional metadata. Merges any new metadata with existing metadata, if present. * * @param meta Any Meta to add to the Clip. The objects in the Meta must be * serializable to JSON with {@link com.google.gson.Gson}. * @return This Clip for chaining */ public Clip add(Meta meta) { if (meta != null) { this.meta.merge(meta); } return this; }
@Override public String asJSON() { return JSONFormatter.asJSON(this); }
/** * Terminate the query and return the final result. * * @return The final non-null {@link Clip} representing the final result. */ public Clip finish() { Clip result = getResult(); addFinishTime(result.getMeta()); return result; }
@Override protected Map<String, Object> getMetadata(Map<String, String> metadataKeys) { Map<String, Object> meta = new HashMap<>(); addIfNonNull(meta, metadataKeys, Meta.Concept.WINDOW_NAME, this::name); addIfNonNull(meta, metadataKeys, Meta.Concept.WINDOW_NUMBER, this::count); addIfNonNull(meta, metadataKeys, Meta.Concept.WINDOW_EMIT_TIME, System::currentTimeMillis); return meta; }
/** * Converts a json representation back to an instance. * * @param json The string representation of the JSON. * @return An instance of this class. */ public static PubSubMessage fromJSON(String json) { return JSONFormatter.fromJSON(json, PubSubMessage.class); } }
/** * 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 protected Map<String, Object> addMetadata(Map<String, String> conceptKeys) { Map<String, Object> metadata = super.addMetadata(conceptKeys); addIfNonNull(metadata, conceptKeys, Concept.SKETCH_ITEMS_SEEN, this::getStreamLength); addIfNonNull(metadata, conceptKeys, Concept.SKETCH_ACTIVE_ITEMS, this::getItemsStored); addIfNonNull(metadata, conceptKeys, Concept.SKETCH_MAXIMUM_COUNT_ERROR, this::getMaximumError); return metadata; }
@Override protected Map<String, Object> getMetadata(Map<String, String> metadataKeys) { Map<String, Object> meta = super.getMetadata(metadataKeys); addIfNonNull(meta, metadataKeys, Meta.Concept.WINDOW_SIZE, () -> this.recordCount); return meta; }