/** * Check if outer TimeGrain is compatible with inner TimeGrain. * * @return false if outer TimeGrain cannot be composed by the inner time grain */ public boolean isTimeGrainValid() { if (nestedQuery != null) { TimeGrain nestedTimeGrain = nestedQuery.getTimeGrain(); // Nested time grain must be smaller or equal to this time grain return timeGrain == null || nestedTimeGrain == null || timeGrain.satisfiedBy(nestedTimeGrain); } return true; }
@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() ); }
Granularity mergeGrain = (template.getTimeGrain() != null) ? template.getTimeGrain().buildZonedTimeGrain(timeZone) : granularity;
if (template.getTimeGrain() != null) { granularity = template.getTimeGrain().buildZonedTimeGrain(timeZone);
updatedPostAggs, query.getInnerQuery().orElse(null), query.getTimeGrain() );
/** * Get the a granularity which must be satisfied by any answering table granularity for this request. * <p> * If a query has a time grain constraint, it will be returned as a granularity with the request time zone * applied. If the query has no constraint, the request grain will be returned as a granularity. * * @param apiRequest DataApiRequest from the user which may specify a coarsest satisfying grain * @param query Query which may apply a coarsest satisfying grain * * @return The coarsest valid table grain to satisfy the query */ public Granularity resolveAcceptingGrain(DataApiRequest apiRequest, TemplateDruidQuery query) { // Gather any specified time grains Granularity requestGranularity = apiRequest.getGranularity(); ZonelessTimeGrain queryGrain = query.getInnermostQuery().getTimeGrain(); // The query makes no restrictions, so use the apiRequest only if (queryGrain == null) { return requestGranularity; } if (requestGranularity.satisfiedBy(queryGrain)) { return queryGrain.buildZonedTimeGrain(apiRequest.getTimeZone()); } LOG.error(QUERY_GRAIN_NOT_SATISFIED.format(queryGrain, requestGranularity)); throw new IllegalArgumentException(QUERY_GRAIN_NOT_SATISFIED.format(queryGrain, requestGranularity)); }
Granularity mergedGranularity = template.getTimeGrain() != null ? template.getTimeGrain().buildZonedTimeGrain(timeZone) : granularity;
ZonelessTimeGrain mergedGrain = mergeTimeGrains(self.getTimeGrain(), sibling.getTimeGrain()); TemplateDruidQuery mergedNested = self.isNested() ? self.nestedQuery.merge(sibling.getInnerQuery().get())