@Override public void consume(BulletRecord data) { sketch.update(composeField(data)); }
private void splitFields(BulletRecord record) { String field = record.getAndRemove(FrequentItemsSketch.ITEM_FIELD).toString(); List<String> values = decomposeField(field); for (int i = 0; i < fields.size(); ++i) { String originalField = fields.get(i); String fieldName = fieldsToNames.get(originalField); record.setString(Utilities.isEmpty(fieldName) ? originalField : fieldName, values.get(i)); } record.rename(FrequentItemsSketch.COUNT_FIELD, newName); }
/** * Constructor that requires an {@link Aggregation} and a {@link BulletConfig} configuration. * * @param aggregation An {@link Aggregation} with valid fields and attributes for this aggregation type. * @param config The config that has relevant configs for this strategy. */ @SuppressWarnings("unchecked") public TopK(Aggregation aggregation, BulletConfig config) { super(aggregation, config); String errorConfiguration = config.getAs(BulletConfig.TOP_K_AGGREGATION_SKETCH_ERROR_TYPE, String.class); ErrorType errorType = getErrorType(errorConfiguration); Map<String, Object> attributes = aggregation.getAttributes(); newName = attributes == null ? DEFAULT_NEW_NAME : attributes.getOrDefault(NEW_NAME_FIELD, DEFAULT_NEW_NAME).toString(); int maxMapSize = config.getAs(BulletConfig.TOP_K_AGGREGATION_SKETCH_ENTRIES, Integer.class); Number threshold = getThreshold(attributes); int size = aggregation.getSize(); BulletRecordProvider provider = config.getBulletRecordProvider(); sketch = threshold != null ? new FrequentItemsSketch(errorType, maxMapSize, threshold.longValue(), size, provider) : new FrequentItemsSketch(errorType, maxMapSize, size, provider); }
fields.put("B", "foo"); TopK topK = TopKTest.makeTopK(config, makeAttributes("cnt", null), fields, 2, null); topK.combine(rawData); List<BulletRecord> records = topK.getRecords(); Assert.assertEquals(records.size(), 2);
/** * 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); } }