/** * Construct a MetricInstance from Strings with a list of dependencyMetricNames. * * @param metricName The name of the Logical Metric in the metric dictionary * @param maker The Metric Maker that creates the actual Logical Metric * @param dependencyMetricNames The names of metrics either in the dictionary or raw druid metrics that this * Logical Metric depends on */ public MetricInstance(ApiMetricName metricName, MetricMaker maker, FieldName... dependencyMetricNames) { this(metricName.asLogicalMetricInfo(), maker, dependencyMetricNames); }
/** * Determine if this API Metric Name is valid for the given time grain. * This capability is provided as a convenience for configurers to filter metrics from a TableGroup onto a set of * LogicalTable instances at configuration time. This version allows the logical metric itself to be used for * filtering. * <p> * An example of this is a DailyAverage metric that doesn't make sense to query by the HOUR grain, but does at WEEK. * * @param granularity TimeGrain to determine validity for * @param logicalMetric The metric whose validity is being tested. * * @return True if the ApiMetricName is valid for the time grain */ default boolean isValidFor(Granularity granularity, LogicalMetric logicalMetric) { return isValidFor(granularity); }
@Override public boolean equals(Object o) { if (o == null || ! (o instanceof ApiMetricName)) { return false; } return Objects.equals(name, ((ApiMetricName) o).asName()) && Objects.equals(name, ((ApiMetricName) o).getApiName()); }
/** * 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); } }
/** * Provide a logical metric info view on this object. * * @return A Logical Metric Info based for this metric name. */ default LogicalMetricInfo asLogicalMetricInfo() { return new LogicalMetricInfo(asName()); } }
/** * Construct a MetricInstance from Strings with a list of dependencyMetricNames. * * @param metricName The name of the Logical Metric in the metric dictionary * @param maker The Metric Maker that creates the actual Logical Metric * @param dependencyMetricNames The names of metrics either in the dictionary or raw druid metrics that this * Logical Metric depends on */ public MetricInstance(ApiMetricName metricName, MetricMaker maker, String... dependencyMetricNames) { this(metricName.asLogicalMetricInfo(), maker, dependencyMetricNames); }
/** * Determine if this API Metric Name is valid for the given time grain. * This capability is provided as a convenience for configurers to filter metrics from a TableGroup onto a set of * LogicalTable instances at configuration time. * <p> * This version only takes the time grain into account. The default implementation simply sets a required minimum * grain for the metric. * <p> * An example of this is a DailyAverage metric that doesn't make sense to query by the HOUR grain, but does at WEEK. * * @param granularity TimeGrain to determine validity for * * @return True if the ApiMetricName is valid for the time grain */ default boolean isValidFor(Granularity granularity) { if (granularity instanceof TimeGrain) { return isValidFor(((TimeGrain) granularity)); } else { return granularity instanceof AllGranularity; } }