/** * Sum the length of the intervals in this collection. * * @param intervals A collection of time intervals * * @return The total duration of all the intervals */ public static long getTotalDuration(Collection<Interval> intervals) { return new SimplifiedIntervalList(intervals).stream() .map(Interval::toDuration) .mapToLong(Duration::getMillis) .sum(); }
/** * Create an Iterator using IntervalPeriodInterators to all intervals of this list broken up into pieces of size * period. * * @param readablePeriod The period to chunk subintervals into. * * @return An iterator which returns period sized subintervals of this interval list. */ public Iterator<Interval> periodIterator(ReadablePeriod readablePeriod) { List<Iterator<? extends Interval>> periodIterators = this.stream() .map(e -> new IntervalPeriodIterator(readablePeriod, e)) .collect(Collectors.toList()); return IteratorUtils.chainedIterator(periodIterators); } }
@Override public Optional<Long> getSegmentSetId(DruidAggregationQuery<?> query) { // Gather the data source names backing the query Set<DataSourceName> dataSourceNames = query.getInnermostQuery() .getDataSource() .getPhysicalTable() .getDataSourceNames() .stream() .collect(Collectors.toSet()); // Get all the segments for the data sources of the query's physical tables Set<SortedMap<DateTime, Map<String, SegmentInfo>>> tableSegments = dataSourceMetadataService.getSegments( dataSourceNames ); // Check if we have no tables with segments if (tableSegments.isEmpty()) { LOG.warn(DRUID_METADATA_SEGMENTS_MISSING.logFormat(dataSourceNames)); return Optional.empty(); } // Get requested intervals, then their segments, and sum their hash codes into a long return getSegmentHash( requestedIntervalsQueryExtractionFunctions.get(query.getClass()).apply(query).stream() .flatMap(interval -> tableSegments.stream() .map(segments -> segments.subMap(interval.getStart(), interval.getEnd())) ) ); }
/** * Remove result records which are missing and not marked as volatile. * Any bucket which is partially volatile is not removed. In the case of the All granularity, all data is * considered to be in a single bucket. * * @param result The result row being transformed * @param schema The schema for that result * @return Null if the bucket this result falls in is missing but not volatile */ @Override public Result map(Result result, ResultSetSchema schema) { Granularity grain = schema.getGranularity(); if (grain.equals(AllGranularity.INSTANCE)) { return ! volatileIntervalSupply.get().isEmpty() || missingIntervals.isEmpty() ? result : null; } // Currently any Granularity which isn't 'ALL' must currently be a TimeGrain Interval resultInterval = new Interval(result.getTimeStamp(), ((TimeGrain) grain).getPeriod()); return getMissingNotVolatile().stream().anyMatch((it) -> it.overlaps(resultInterval)) ? null : result; }