List of usage examples for org.joda.time Interval overlaps
public boolean overlaps(ReadableInterval interval)
From source file:org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter.java
License:Apache License
@Override public Sequence<Cursor> makeCursors(@Nullable final Filter filter, final Interval interval, final VirtualColumns virtualColumns, final Granularity gran, final boolean descending, @Nullable QueryMetrics<?> queryMetrics) { if (index.isEmpty()) { return Sequences.empty(); }/* w w w .java 2s. c o m*/ final Interval dataInterval = new Interval(getMinTime(), gran.bucketEnd(getMaxTime())); if (!interval.overlaps(dataInterval)) { return Sequences.empty(); } final Interval actualInterval = interval.overlap(dataInterval); Iterable<Interval> intervals = gran.getIterable(actualInterval); if (descending) { intervals = Lists.reverse(ImmutableList.copyOf(intervals)); } return Sequences.simple(intervals) .map(i -> new IncrementalIndexCursor(virtualColumns, descending, filter, i, actualInterval, gran)); }
From source file:org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec.java
License:Apache License
@JsonCreator public ArbitraryGranularitySpec(@JsonProperty("queryGranularity") Granularity queryGranularity, @JsonProperty("rollup") Boolean rollup, @JsonProperty("intervals") List<Interval> inputIntervals) { this.queryGranularity = queryGranularity == null ? Granularities.NONE : queryGranularity; this.rollup = rollup == null ? Boolean.TRUE : rollup; this.intervals = new TreeSet<>(Comparators.intervalsByStartThenEnd()); if (inputIntervals == null) { inputIntervals = new ArrayList<>(); }/*from w w w . ja va 2s .c o m*/ // Insert all intervals for (final Interval inputInterval : inputIntervals) { intervals.add(inputInterval); } // Ensure intervals are non-overlapping (but they may abut each other) final PeekingIterator<Interval> intervalIterator = Iterators.peekingIterator(intervals.iterator()); while (intervalIterator.hasNext()) { final Interval currentInterval = intervalIterator.next(); if (intervalIterator.hasNext()) { final Interval nextInterval = intervalIterator.peek(); if (currentInterval.overlaps(nextInterval)) { throw new IAE("Overlapping intervals: %s, %s", currentInterval, nextInterval); } } } }
From source file:org.apache.druid.segment.QueryableIndexStorageAdapter.java
License:Apache License
@Nullable private Interval computeCursorInterval(final Granularity gran, final Interval interval) { final DateTime minTime = getMinTime(); final DateTime maxTime = getMaxTime(); final Interval dataInterval = new Interval(minTime, gran.bucketEnd(maxTime)); if (!interval.overlaps(dataInterval)) { return null; }//from www . j a v a 2 s . c om return interval.overlap(dataInterval); }
From source file:org.apache.druid.server.ClientInfoResource.java
License:Apache License
@GET @Path("/{dataSourceName}") @Produces(MediaType.APPLICATION_JSON)/*w w w . j av a2s.co m*/ @ResourceFilters(DatasourceResourceFilter.class) public Map<String, Object> getDatasource(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval, @QueryParam("full") String full) { if (full == null) { return ImmutableMap.of(KEY_DIMENSIONS, getDataSourceDimensions(dataSourceName, interval), KEY_METRICS, getDataSourceMetrics(dataSourceName, interval)); } Interval theInterval; if (interval == null || interval.isEmpty()) { DateTime now = getCurrentTime(); theInterval = new Interval(segmentMetadataQueryConfig.getDefaultHistory(), now); } else { theInterval = Intervals.of(interval); } TimelineLookup<String, ServerSelector> timeline = timelineServerView .getTimeline(new TableDataSource(dataSourceName)); Iterable<TimelineObjectHolder<String, ServerSelector>> serversLookup = timeline != null ? timeline.lookup(theInterval) : null; if (serversLookup == null || Iterables.isEmpty(serversLookup)) { return Collections.EMPTY_MAP; } Map<Interval, Object> servedIntervals = new TreeMap<>(new Comparator<Interval>() { @Override public int compare(Interval o1, Interval o2) { if (o1.equals(o2) || o1.overlaps(o2)) { return 0; } else { return o1.isBefore(o2) ? -1 : 1; } } }); for (TimelineObjectHolder<String, ServerSelector> holder : serversLookup) { final Set<Object> dimensions = new HashSet<>(); final Set<Object> metrics = new HashSet<>(); final PartitionHolder<ServerSelector> partitionHolder = holder.getObject(); if (partitionHolder.isComplete()) { for (ServerSelector server : partitionHolder.payloads()) { final DataSegment segment = server.getSegment(); dimensions.addAll(segment.getDimensions()); metrics.addAll(segment.getMetrics()); } } servedIntervals.put(holder.getInterval(), ImmutableMap.of(KEY_DIMENSIONS, dimensions, KEY_METRICS, metrics)); } //collapse intervals if they abut and have same set of columns Map<String, Object> result = Maps.newLinkedHashMap(); Interval curr = null; Map<String, Set<String>> cols = null; for (Map.Entry<Interval, Object> e : servedIntervals.entrySet()) { Interval ival = e.getKey(); if (curr != null && curr.abuts(ival) && cols.equals(e.getValue())) { curr = curr.withEnd(ival.getEnd()); } else { if (curr != null) { result.put(curr.toString(), cols); } curr = ival; cols = (Map<String, Set<String>>) e.getValue(); } } //add the last one in if (curr != null) { result.put(curr.toString(), cols); } return result; }
From source file:org.apache.druid.server.ClientInfoResource.java
License:Apache License
@Deprecated @GET// w w w. j a v a 2s . c o m @Path("/{dataSourceName}/dimensions") @Produces(MediaType.APPLICATION_JSON) @ResourceFilters(DatasourceResourceFilter.class) public Iterable<String> getDataSourceDimensions(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval) { final Set<DataSegment> segments = getAllSegmentsForDataSource(dataSourceName); final Interval theInterval; if (interval == null || interval.isEmpty()) { DateTime now = getCurrentTime(); theInterval = new Interval(segmentMetadataQueryConfig.getDefaultHistory(), now); } else { theInterval = Intervals.of(interval); } final Set<String> dims = new HashSet<>(); for (DataSegment segment : segments) { if (theInterval.overlaps(segment.getInterval())) { dims.addAll(segment.getDimensions()); } } return dims; }
From source file:org.apache.druid.server.ClientInfoResource.java
License:Apache License
@Deprecated @GET//from w w w. j ava 2 s .c o m @Path("/{dataSourceName}/metrics") @Produces(MediaType.APPLICATION_JSON) @ResourceFilters(DatasourceResourceFilter.class) public Iterable<String> getDataSourceMetrics(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval) { final Set<DataSegment> segments = getAllSegmentsForDataSource(dataSourceName); final Interval theInterval; if (interval == null || interval.isEmpty()) { DateTime now = getCurrentTime(); theInterval = new Interval(segmentMetadataQueryConfig.getDefaultHistory(), now); } else { theInterval = Intervals.of(interval); } final Set<String> metrics = new HashSet<>(); for (DataSegment segment : segments) { if (theInterval.overlaps(segment.getInterval())) { metrics.addAll(segment.getMetrics()); } } return metrics; }
From source file:org.apache.druid.server.coordinator.helper.NewestSegmentFirstIterator.java
License:Apache License
@VisibleForTesting static List<Interval> sortAndAddSkipIntervalFromLatest(DateTime latest, Period skipOffset, @Nullable List<Interval> skipIntervals) { final List<Interval> nonNullSkipIntervals = skipIntervals == null ? new ArrayList<>(1) : new ArrayList<>(skipIntervals.size()); if (skipIntervals != null) { final List<Interval> sortedSkipIntervals = new ArrayList<>(skipIntervals); sortedSkipIntervals.sort(Comparators.intervalsByStartThenEnd()); final List<Interval> overlapIntervals = new ArrayList<>(); final Interval skipFromLatest = new Interval(skipOffset, latest); for (Interval interval : sortedSkipIntervals) { if (interval.overlaps(skipFromLatest)) { overlapIntervals.add(interval); } else { nonNullSkipIntervals.add(interval); }// w w w .java 2 s . co m } if (!overlapIntervals.isEmpty()) { overlapIntervals.add(skipFromLatest); nonNullSkipIntervals.add(JodaUtils.umbrellaInterval(overlapIntervals)); } else { nonNullSkipIntervals.add(skipFromLatest); } } else { final Interval skipFromLatest = new Interval(skipOffset, latest); nonNullSkipIntervals.add(skipFromLatest); } return nonNullSkipIntervals; }
From source file:org.apache.druid.server.coordinator.rules.Rules.java
License:Apache License
public static boolean eligibleForLoad(Interval src, Interval target) { return src.overlaps(target); }
From source file:org.apache.druid.timeline.VersionedIntervalTimeline.java
License:Apache License
public boolean isOvershadowed(Interval interval, VersionType version, ObjectType object) { lock.readLock().lock();// www . j av a 2s . c om try { TimelineEntry entry = completePartitionsTimeline.get(interval); if (entry != null) { final int majorVersionCompare = versionComparator.compare(version, entry.getVersion()); if (majorVersionCompare == 0) { for (PartitionChunk<ObjectType> chunk : entry.partitionHolder) { if (chunk.getObject().overshadows(object)) { return true; } } return false; } else { return majorVersionCompare < 0; } } Interval lower = completePartitionsTimeline.floorKey(new Interval(interval.getStart(), DateTimes.MAX)); if (lower == null || !lower.overlaps(interval)) { return false; } Interval prev = null; Interval curr = lower; do { if (curr == null || //no further keys (prev != null && curr.getStartMillis() > prev.getEndMillis()) //a discontinuity ) { return false; } final TimelineEntry timelineEntry = completePartitionsTimeline.get(curr); final int versionCompare = versionComparator.compare(version, timelineEntry.getVersion()); //lower or same version if (versionCompare > 0) { return false; } else if (versionCompare == 0) { if (timelineEntry.partitionHolder.stream() .noneMatch(chunk -> chunk.getObject().overshadows(object))) { return false; } } prev = curr; curr = completePartitionsTimeline.higherKey(curr); } while (interval.getEndMillis() > prev.getEndMillis()); return true; } finally { lock.readLock().unlock(); } }
From source file:org.apache.druid.timeline.VersionedIntervalTimeline.java
License:Apache License
/** * @param timeline//w ww . j a va2 s . c om * @param key * @param entry * * @return boolean flag indicating whether or not we inserted or discarded something */ private boolean addAtKey(NavigableMap<Interval, TimelineEntry> timeline, Interval key, TimelineEntry entry) { boolean retVal = false; Interval currKey = key; Interval entryInterval = entry.getTrueInterval(); if (!currKey.overlaps(entryInterval)) { return false; } while (entryInterval != null && currKey != null && currKey.overlaps(entryInterval)) { final Interval nextKey = timeline.higherKey(currKey); final int versionCompare = versionComparator.compare(entry.getVersion(), timeline.get(currKey).getVersion()); if (versionCompare < 0) { // since the entry version is lower than the existing one, the existing one overwrites the given entry // if overlapped. if (currKey.contains(entryInterval)) { // the version of the entry of currKey is larger than that of the given entry. Discard it return true; } else if (currKey.getStart().isBefore(entryInterval.getStart())) { // | entry | // | cur | // => |new| entryInterval = new Interval(currKey.getEnd(), entryInterval.getEnd()); } else { // | entry | // | cur | // => |new| addIntervalToTimeline(new Interval(entryInterval.getStart(), currKey.getStart()), entry, timeline); // | entry | // | cur | // => |new| if (entryInterval.getEnd().isAfter(currKey.getEnd())) { entryInterval = new Interval(currKey.getEnd(), entryInterval.getEnd()); } else { // Discard this entry since there is no portion of the entry interval that goes past the end of the curr // key interval. entryInterval = null; } } } else if (versionCompare > 0) { // since the entry version is greater than the existing one, the given entry overwrites the existing one // if overlapped. final TimelineEntry oldEntry = timeline.remove(currKey); if (currKey.contains(entryInterval)) { // | cur | // | entry | // => |old| new |old| addIntervalToTimeline(new Interval(currKey.getStart(), entryInterval.getStart()), oldEntry, timeline); addIntervalToTimeline(new Interval(entryInterval.getEnd(), currKey.getEnd()), oldEntry, timeline); addIntervalToTimeline(entryInterval, entry, timeline); return true; } else if (currKey.getStart().isBefore(entryInterval.getStart())) { // | cur | // | entry | // => |old| addIntervalToTimeline(new Interval(currKey.getStart(), entryInterval.getStart()), oldEntry, timeline); } else if (entryInterval.getEnd().isBefore(currKey.getEnd())) { // | cur | // | entry | // => |old| addIntervalToTimeline(new Interval(entryInterval.getEnd(), currKey.getEnd()), oldEntry, timeline); } } else { if (timeline.get(currKey).equals(entry)) { // This occurs when restoring segments timeline.remove(currKey); } else { throw new UOE("Cannot add overlapping segments [%s and %s] with the same version [%s]", currKey, entryInterval, entry.getVersion()); } } currKey = nextKey; retVal = true; } addIntervalToTimeline(entryInterval, entry, timeline); return retVal; }