/** * Makes a copy of the template query, changing nested query. * <p> * Everything is a shallow copy. * * @param newNestedQuery The nestedQuery to replace in the copy * * @return copy of the query */ public TemplateDruidQuery withInnerQuery(TemplateDruidQuery newNestedQuery) { return new TemplateDruidQuery(aggregations, postAggregations, newNestedQuery, timeGrain); }
/** * Makes a copy of the template query and any sub query(s), changing post-aggregations. * <p> * Everything is a shallow copy. * * @param newPostAggregations The PostAggregations to replace with in the copy * * @return copy of the query */ public TemplateDruidQuery withPostAggregations(Collection<PostAggregation> newPostAggregations) { return new TemplateDruidQuery(aggregations, newPostAggregations, nestedQuery, timeGrain); }
/** * Makes a copy of the template query and any sub query(s), changing time grain on the outermost level only. * <p> * Everything is a shallow copy. * * @param newTimeGrain The TimeGrain to replace with in the copy * * @return copy of the query */ public TemplateDruidQuery withGranularity(ZonelessTimeGrain newTimeGrain) { return new TemplateDruidQuery(aggregations, postAggregations, nestedQuery, newTimeGrain); }
/** * Makes a copy of the template query and any sub query(s), changing aggregations. * <p> * Everything is a shallow copy. * * @param newAggregations The Aggregations to replace in the copy * * @return copy of the query */ @Override public TemplateDruidQuery withAggregations(Collection<Aggregation> newAggregations) { return new TemplateDruidQuery(newAggregations, postAggregations, nestedQuery, timeGrain); }
/** * Create a query with a counter field and a grain. * * @return The created query */ private TemplateDruidQuery buildTimeGrainCounterQuery() { return new TemplateDruidQuery(Collections.emptySet(), Collections.singleton(COUNT_INNER), innerGrain); } }
@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); }
@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 ); }
innerQuery = new TemplateDruidQuery(innerAggregations, Collections.emptySet(), nestedQuery, null); } else { innerQuery = new TemplateDruidQuery( innerAggregations, Collections.emptySet(), return new TemplateDruidQuery(outerAggregations, postAggregations, innerQuery, timeGrain);
@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); } }
@Override protected LogicalMetric makeInner(LogicalMetricInfo logicalMetricInfo, List<String> dependentMetrics) { TemplateDruidQuery query = new TemplateDruidQuery( Collections.singleton(new CountAggregation(logicalMetricInfo.getName())), Collections.emptySet() ); return new LogicalMetric(query, NO_OP_MAPPER, logicalMetricInfo); }
/** * Build the outer query for the average. It will have a sum, a count, and a post agg to divide them. * * @param metricDictionary The metric dictionary name for the metric being created (usually an api name) * @param sourceMetric The metric in the inner query being averaged * @param innerQuery The inner template query being summed over * * @return The query for creating a logical metric */ private TemplateDruidQuery buildOuterQuery( String metricDictionary, MetricField sourceMetric, TemplateDruidQuery innerQuery ) { // Build the outer aggregations Aggregation sum = createSummingAggregator(sourceMetric); Set<Aggregation> outerAggs = new LinkedHashSet<>(Arrays.asList(sum, COUNT_OUTER)); // Build the average post aggregation FieldAccessorPostAggregation sumPost = new FieldAccessorPostAggregation(sum); PostAggregation average = new ArithmeticPostAggregation( metricDictionary, DIVIDE, Arrays.asList(sumPost, COUNT_FIELD_OUTER) ); Set<PostAggregation> outerPostAggs = Collections.singleton(average); // Build the resulting query template return new TemplateDruidQuery(outerAggs, outerPostAggs, innerQuery); }
@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 public TemplateDruidQuery updateOuterQuery( TemplateDruidQuery outerQuery, Map<String, String> oldFieldNameToNewFieldNameMap ) { Map<String, Aggregation> oldNameToNewAggregationMapping = new HashMap<>(); Set<Aggregation> updatedOuterAggs = updateQueryAggs( outerQuery.getAggregations(), oldFieldNameToNewFieldNameMap, oldNameToNewAggregationMapping ); //Update the FieldAccessors from the outer query post aggs to access the correct aggs. Set<PostAggregation> updateOuterPostAggs = new HashSet<>(); for (PostAggregation postAggregation: outerQuery.getPostAggregations()) { updateOuterPostAggs.add(replacePostAggWithPostAggFromMap(postAggregation, oldNameToNewAggregationMapping)); } //create new TDQ using updated aggs, updatedPostAggs, updatedInnerQuery and timegrain of outerQuery return new TemplateDruidQuery( updatedOuterAggs, updateOuterPostAggs, outerQuery.getInnerQuery().orElse(null), outerQuery.getTimeGrain() ); }
return new TemplateDruidQuery( updatedAggs, updatedPostAggs,
self.nestedQuery.merge(sibling.getInnerQuery().get()) : null; return new TemplateDruidQuery( mergedAggregations, mergedPostAggregations,
new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_BOOLEAN_METRIC.asName(), ), new LogicalMetric( new TemplateDruidQuery( Collections.singleton( new LongMinAggregation(A_JSON_NODE_METRIC.asName(), A_HEIGHT.getApiName()) new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_NULL_METRIC.asName(),
new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_BOOLEAN_METRIC.asName(), ), new LogicalMetric( new TemplateDruidQuery( Collections.singleton( new LongMinAggregation(A_JSON_NODE_METRIC.asName(), A_HEIGHT.getApiName()) new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_NULL_METRIC.asName(),