/** * 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; }
/** * Constructor. * * @param metric The logical metric */ public LogicalMetricColumn(LogicalMetric metric) { super(metric.getName()); this.metric = metric; }
/** * 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; }
/** * 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(); } }
/** * 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; }
/** * 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; }
public MetricField getMetricField() { return getTemplateDruidQuery().getMetricField(getName()); }
/** * Generates the set of all available metrics. * * @param metricName string corresponding to the metric name specified in the URL * @param metricDictionary metric dictionary that contains the map of valid metric names to metric objects. * * @return Set of metric objects. * @throws BadApiRequestException if an invalid metric is requested or the metric dictionary is empty. */ protected LinkedHashSet<LogicalMetric> generateMetrics(String metricName, MetricDictionary metricDictionary) throws BadApiRequestException { LinkedHashSet<LogicalMetric> generated = metricDictionary.values().stream() .filter(logicalMetric -> metricName == null || metricName.equals(logicalMetric.getName())) .collect(Collectors.toCollection(LinkedHashSet::new)); if (generated.isEmpty()) { String msg; if (metricDictionary.isEmpty()) { msg = EMPTY_DICTIONARY.logFormat("Metric"); } else { msg = METRICS_UNDEFINED.logFormat(metricName); } LOG.error(msg); throw new BadApiRequestException(msg); } LOG.trace("Generated set of metrics: {}", generated); return generated; }
/** * 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; }
LogicalMetric metric = newHaving.getMetric(); if (!logicalMetrics.contains(metric)) { unmatchedMetrics.add(metric.getName()); } else { generated.putIfAbsent(metric, new LinkedHashSet<>());
orHavings.add(new NumericHaving(Having.DefaultHavingType.GREATER_THAN, metric.getName(), lowerValue)); orHavings.add(new NumericHaving(Having.DefaultHavingType.EQUAL_TO, metric.getName(), lowerValue)); OrHaving orHavingLower = new OrHaving(orHavings); orHavings = new ArrayList<>(); orHavings.add(new NumericHaving(Having.DefaultHavingType.LESS_THAN, metric.getName(), upperValue)); orHavings.add(new NumericHaving(Having.DefaultHavingType.EQUAL_TO, metric.getName(), upperValue)); OrHaving orHavingUpper = new OrHaving(orHavings); newHaving = new AndHaving(Arrays.asList(orHavingLower, orHavingUpper)); .map(value -> new NumericHaving(operation.getType(), metric.getName(), value)) .collect(Collectors.toList()); newHaving = havings.size() == 1 ? havings.get(0) : new OrHaving(havings);
REGISTRY.meter("request.metric." + metric.getName()).mark();
templateDruidQuery, logicalMetric.getCalculation(), new LogicalMetricInfo(logicalMetric.getName()) );