/** * The constructor for creating a Sketch based strategy. * * @param aggregation An {@link Aggregation} with valid fields and attributes for this aggregation type. * @param config The config that has relevant configs for this sketch based strategy. */ @SuppressWarnings("unchecked") public SketchingStrategy(Aggregation aggregation, BulletConfig config) { metadataKeys = (Map<String, String>) config.getAs(BulletConfig.RESULT_METADATA_METRICS, Map.class); separator = config.getAs(BulletConfig.AGGREGATION_COMPOSITE_FIELD_SEPARATOR, String.class); shouldMeta = config.getAs(BulletConfig.RESULT_METADATA_ENABLE, Boolean.class); fieldsToNames = aggregation.getFields(); fields = Utilities.isEmpty(fieldsToNames) ? Collections.emptyList() : new ArrayList<>(fieldsToNames.keySet()); }
/** * 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); } }