/** * Buid a stream of metric columns by filtering the table group's collection of ApiMetricNames. * Metric names are resolved and then filtered considering the table granularity and the metric referenced. * * @param apiMetricNames The names of the apiMetrics being bound and filtered * @param granularity The grain used to filter those metric names * @param metricDictionary The dictionary to resolve the logical metric instances from * * @return A stream of metric columns, filtered for compatibility with the grain. */ private static Stream<LogicalMetricColumn> buildMetricColumns( Collection<ApiMetricName> apiMetricNames, Granularity granularity, MetricDictionary metricDictionary ) { return apiMetricNames.stream() .filter(name -> name.isValidFor(granularity, metricDictionary.get(name.asName()))) .map(ApiMetricName::asName) .map(metricDictionary::get) .map(LogicalMetricColumn::new); } }
List<String> invalidMetricNames = new ArrayList<>(); for (String metricName : apiMetricQuery.split(",")) { LogicalMetric logicalMetric = metricDictionary.get(metricName); if (logicalMetric == null) { invalidMetricNames.add(metricName);
/** * Prepare a post aggregation for a field expecting a numeric value. * <p> * The post-agg is created per the following heuristics: * <dl> * <dt>If it's an aggregator * <dd>wrap it in a field accessor * <dt>If it's a sketch * <dd>wrap it in a sketch estimate * <dt>If it's already a numeric post aggregator * <dd>simply return it * </dl> * * @param fieldName The name for the aggregation or post aggregation column being gotten * * @return A post aggregator representing a number field value * * @deprecated use the static version {@link #getNumericField(MetricField)} by preference */ @Deprecated protected PostAggregation getNumericField(String fieldName) { return getNumericField(metrics.get(fieldName).getMetricField()); }
/** * Prepare a post aggregation for a field expecting a sketch value. * <p> * The post-agg is created per the following heuristics: * <dl> * <dt>If it's an aggregator * <dd>wrap it in a field accessor * <dt>If it's a sketch estimate * <dd>unwrap the sketch estimate * <dt>If it's already a sketch post aggregator * <dd>simply return it * <dt>Otherwise</dt> * <dd>This is an illegal field</dd> * </dl> * * @param fieldName The name for the aggregation or post aggregation column being gotten * * @return A post aggregator representing a number field value * * @deprecated use the static version {@link MetricMaker#getSketchField(MetricField)} by preference */ @Deprecated protected PostAggregation getSketchField(String fieldName) { // Get the field return getSketchField(metrics.get(fieldName).getMetricField()); }
LogicalMetric logicalMetric = metricDictionary.get(metricName);
sortMetricName = entry.getKey(); LogicalMetric logicalMetric = metricDictionary.get(sortMetricName);
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { LogicalMetric sourceMetric = metricDictionary.get(dependentMetrics.get(0)); Aggregation sourceAggregation = assertDependentIsAggregationMetric(sourceMetric); FilteredAggregation filteredAggregation = new FilteredAggregation( logicalMetricInfo.getName(), sourceAggregation, filter ); return new LogicalMetric( new TemplateDruidQuery( ImmutableSet.of(filteredAggregation), Collections.emptySet(), sourceMetric.getTemplateDruidQuery().getInnerQuery().orElse(null) ), sourceMetric.getCalculation(), logicalMetricInfo ); }
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { // Get the Metric that is being averaged over LogicalMetric dependentMetric = metrics.get(dependentMetrics.get(0)); // Get the field being subtotalled in the inner query MetricField sourceMetric = convertToSketchEstimateIfNeeded(dependentMetric.getMetricField()); // Build the TemplateDruidQuery for the metric TemplateDruidQuery innerQuery = buildInnerQuery(sourceMetric, dependentMetric.getTemplateDruidQuery()); TemplateDruidQuery outerQuery = buildOuterQuery(logicalMetricInfo.getName(), sourceMetric, innerQuery); return new LogicalMetric(outerQuery, NO_OP_MAPPER, logicalMetricInfo); }
LogicalMetric logicalMetric = metricDictionary.get(metricName);