@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { return new LogicalMetric( null, ROW_NUM_MAPPER, logicalMetricInfo ); }
/** * Get the summary view of the logical metric. * * @param logicalMetric Logical metric to get the view of * @param uriInfo UriInfo of the request * * @return Summary view of the logical metric */ public static Map<String, String> getLogicalMetricSummaryView(LogicalMetric logicalMetric, UriInfo uriInfo) { Map<String, String> resultRow = new LinkedHashMap<>(); resultRow.put("category", logicalMetric.getCategory()); resultRow.put("name", logicalMetric.getName()); resultRow.put("longName", logicalMetric.getLongName()); resultRow.put("type", logicalMetric.getType()); resultRow.put("uri", getLogicalMetricUrl(logicalMetric, uriInfo)); return resultRow; }
/** * Get the full view of the logical metric. * * @param logicalMetric Logical metric to get the view of * @param logicalTableDictionary Logical Table Dictionary to look up the logical tables this metric is on * @param uriInfo UriInfo of the request * * @return Full view of the logical metric */ public static Map<String, Object> getLogicalMetricFullView( LogicalMetric logicalMetric, LogicalTableDictionary logicalTableDictionary, UriInfo uriInfo ) { Map<String, Object> resultRow = new LinkedHashMap<>(); resultRow.put("category", logicalMetric.getCategory()); resultRow.put("name", logicalMetric.getName()); resultRow.put("longName", logicalMetric.getLongName()); resultRow.put("description", logicalMetric.getDescription()); resultRow.put( "tables", TablesServlet.getLogicalTableListSummaryView( logicalTableDictionary.findByLogicalMetric(logicalMetric), uriInfo ) ); return resultRow; }
public MetricField getMetricField() { return getTemplateDruidQuery().getMetricField(getName()); }
/** * Test that the metric is associated with an Aggregation Metric and return that Aggregation. * * @param sourceMetric The source metric * * @return The aggregation used by this metric */ private Aggregation assertDependentIsAggregationMetric(LogicalMetric sourceMetric) { MetricField metricField = sourceMetric.getMetricField(); if (!(metricField instanceof Aggregation)) { String message = String.format( "FilteredAggregationMaker requires an aggregation metric, but found: %s.", sourceMetric.getName() ); LOG.error(message); throw new IllegalArgumentException(message); } return (Aggregation) metricField; }
) throws FilterBuilderException { TemplateDruidQuery templateDruidQuery = logicalMetric.getTemplateDruidQuery(); return new LogicalMetric( templateDruidQuery, logicalMetric.getCalculation(), new LogicalMetricInfo(logicalMetric.getName()) );
@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); }
@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 ); }
/** * Constructor. * * @param metric The logical metric */ public LogicalMetricColumn(LogicalMetric metric) { super(metric.getName()); this.metric = metric; }
if (logicalMetric.getCategory().equals(RATIO_METRIC_CATEGORY)) { LOG.debug( UNSUPPORTED_FILTERED_METRIC_CATEGORY.logFormat( logicalMetric.getName(), logicalMetric.getCategory() logicalMetric.getName(), logicalMetric.getCategory()
/** * 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()); }
TemplateDruidQuery query = metric.getTemplateDruidQuery(); if (query != null) { allQueries.add(metric.getTemplateDruidQuery());
/** * Constructor. * * @param metric a LogicalMetric * @param direction sort direction * * Note: Plan is to remove this LogicalMetric based constructor and have a DruidColumn based constructor. */ public OrderByColumn(LogicalMetric metric, SortDirection direction) { this.dimension = metric.getName(); this.direction = direction; }
/** * 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()); }
continue; if (logicalMetric.getTemplateDruidQuery() == null) { unsortableMetrics.add(sortMetricName); continue;
@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); }
/** * Add a logical metric to the dictionary. * * @param logicalMetric Logical metric to add * * @return True if the Logical Metric did not exist in the dictionary before, false if it did */ public boolean add(LogicalMetric logicalMetric) { return this.put(logicalMetric.getName(), logicalMetric) == null; }
@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 ); }
/** * Get the URL of the logical metric. * * @param logicalMetric Logical metric to get the URL of * @param uriInfo URI Info for the request * * @return The absolute URL for the logical metric */ public static String getLogicalMetricUrl(LogicalMetric logicalMetric, UriInfo uriInfo) { return uriInfo.getBaseUriBuilder() .path(MetricsServlet.class) .path(MetricsServlet.class, "getMetric") .build(logicalMetric.getName()) .toASCIIString(); } }
@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); } }