/** * Build a fully specified Logical Metric. * * @param templateDruidQuery Query the metric needs * @param calculation Mapper for the metric * @param name Name of the metric * @param longName Long name of the metric * @param category Category of the metric * @param description Description of the metric * * {@link com.yahoo.bard.webservice.data.metric.LogicalMetricInfo}. Use new constructor * {@link #LogicalMetric(TemplateDruidQuery, ResultSetMapper, LogicalMetricInfo)} instead. */ public LogicalMetric( TemplateDruidQuery templateDruidQuery, ResultSetMapper calculation, String name, String longName, String category, String description ) { this(templateDruidQuery, calculation, new LogicalMetricInfo(name, longName, category, description)); }
public String getCategory() { return logicalMetricInfo.getCategory(); }
public String getDescription() { return logicalMetricInfo.getDescription(); }
@Override public String toString() { return "LogicalMetric{\n" + "name=" + logicalMetricInfo.getName() + ",\n" + "templateDruidQuery=" + query + ",\n" + "calculation=" + calculation + "\n" + "}"; }
public String getLongName() { return logicalMetricInfo.getLongName(); }
public String getType() { return logicalMetricInfo.getType(); }
public String getName() { return logicalMetricInfo.getName(); }
/** * Build a partly specified Logical Metric. * <p> * Note: The description is set to the same as the name. * * @param templateDruidQuery Query the metric needs * @param calculation Mapper for the metric * @param name Name of the metric * * @deprecated Properties, such as name, of LogicalMetric is stored in a unified object called * {@link com.yahoo.bard.webservice.data.metric.LogicalMetricInfo}. Use new constructor * {@link #LogicalMetric(TemplateDruidQuery, ResultSetMapper, LogicalMetricInfo)} instead. */ @Deprecated public LogicalMetric(TemplateDruidQuery templateDruidQuery, ResultSetMapper calculation, String name) { this(templateDruidQuery, calculation, new LogicalMetricInfo(name, name, DEFAULT_CATEGORY, name)); }
public String getMetricName() { return logicalMetricInfo.getName(); }
/** * Build a slightly more specified Logical Metric. * <p> * Note: The description is set to the same as the name. * * @param templateDruidQuery Query the metric needs * @param calculation Mapper for the metric * @param name Name of the metric * @param description Description of the metric * * @deprecated Properties, such as name, of LogicalMetric is stored in a unified object called * {@link com.yahoo.bard.webservice.data.metric.LogicalMetricInfo}. Use new constructor * {@link #LogicalMetric(TemplateDruidQuery, ResultSetMapper, LogicalMetricInfo)} instead. */ @Deprecated public LogicalMetric( TemplateDruidQuery templateDruidQuery, ResultSetMapper calculation, String name, String description ) { this(templateDruidQuery, calculation, new LogicalMetricInfo(name, name, DEFAULT_CATEGORY, description)); }
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentDimensions) { Set<Dimension> dimensions = dependentDimensions.stream() .map(dimensionDictionary::findByApiName) .collect(Collectors.toSet()); Set<Aggregation> aggs = Collections.singleton( new CardinalityAggregation(logicalMetricInfo.getName(), dimensions, byRow) ); return new LogicalMetric(new TemplateDruidQuery(aggs, Collections.emptySet()), NO_OP_MAPPER, logicalMetricInfo); }
/** * 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 * * @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long * name, description, etc. Use {@link #MetricInstance(LogicalMetricInfo, MetricMaker, String...)} instead. */ @Deprecated public MetricInstance(String metricName, MetricMaker maker, String... dependencyMetricNames) { this.logicalMetricInfo = new LogicalMetricInfo(metricName); this.maker = maker; this.dependencyMetricNames = Arrays.asList(dependencyMetricNames); }
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { // Get the ArithmeticPostAggregation operands from the dependent metrics List<PostAggregation> operands = dependentMetrics.stream() .map(metrics::get) .map(LogicalMetric::getMetricField) .map(MetricMaker::getNumericField) .collect(Collectors.toList()); // Create the ArithmeticPostAggregation Set<PostAggregation> postAggregations = Collections.singleton(new ArithmeticPostAggregation( logicalMetricInfo.getName(), function, operands )); TemplateDruidQuery query = getMergedQuery(dependentMetrics).withPostAggregations(postAggregations); return new LogicalMetric( query, resultSetMapperSupplier.apply(logicalMetricInfo.getName()), logicalMetricInfo ); }
/** * 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()); } }
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { String metricName = logicalMetricInfo.getName(); Aggregation aggregation = aggregationFactory.apply(metricName, dependentMetrics.get(0)); return new LogicalMetric( new TemplateDruidQuery(Collections.singleton(aggregation), Collections.emptySet()), getResultSetMapper(metricName), logicalMetricInfo ); }
/** * Make the metric. * * @param metricName Name for the metric we're making * @param dependentMetric Metric this metric depends on * * @return The new logicalMetric */ public LogicalMetric make(String metricName, String dependentMetric) { return this.make(new LogicalMetricInfo(metricName), Collections.singletonList(dependentMetric)); }
@Override public LogicalMetric make(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { // Check that we have the right number of metrics assertRequiredDependentMetricCount(logicalMetricInfo.getName(), dependentMetrics); // Actually build the metric. return makeInner(logicalMetricInfo, dependentMetrics); }
/** * Construct a MetricInstance from FieldNames with a list of dependencyFields. * * @param metricName The name of the Logical Metric when it's in the metric dictionary * @param maker The Metric Maker that creates the actual Logical Metric * @param dependencyFields The field names that this Logical Metric depends on * * @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long * name, description, etc. Use {@link #MetricInstance(LogicalMetricInfo, MetricMaker, FieldName...)} instead. */ @Deprecated public MetricInstance(FieldName metricName, MetricMaker maker, FieldName... dependencyFields) { this(new LogicalMetricInfo(metricName.asName()), maker, dependencyFields); }
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { String metricName = logicalMetricInfo.getName(); try { Set<PostAggregation> postAggregations = Collections.singleton(new ConstantPostAggregation( metricName, new Double(dependentMetrics.get(0)) )); return new LogicalMetric( new TemplateDruidQuery(Collections.emptySet(), postAggregations), NO_OP_MAPPER, logicalMetricInfo ); } catch (NumberFormatException nfe) { String message = String.format( "%s value '%s' does not parse to a number", metricName, dependentMetrics.get(0) ); LOG.error(message); throw new IllegalArgumentException(message, nfe); } }
/** * Delegated to for actually making the metric. * * @param metricName Name for the metric we're making * @param dependentMetrics Metrics this metric depends on * * @return the new logicalMetric * * @deprecated logical metric needs more config-richness to not just configure metric name, but also metric long * name, description, etc. Use {@link #makeInner(LogicalMetricInfo, List)} instead. */ @Deprecated protected LogicalMetric makeInner(String metricName, List<String> dependentMetrics) { return makeInner(new LogicalMetricInfo(metricName), dependentMetrics); }