Package org.apache.druid.timeline
Class VersionedIntervalTimeline<VersionType,ObjectType extends Overshadowable<ObjectType>>
java.lang.Object
org.apache.druid.timeline.VersionedIntervalTimeline<VersionType,ObjectType>
- All Implemented Interfaces:
TimelineLookup<VersionType,ObjectType>
- Direct Known Subclasses:
SegmentTimeline
public class VersionedIntervalTimeline<VersionType,ObjectType extends Overshadowable<ObjectType>>
extends Object
implements TimelineLookup<VersionType,ObjectType>
VersionedIntervalTimeline is a data structure that manages objects on a specific timeline.
It associates an
Interval and a generically-typed version with the object that is being stored.
In the event of overlapping timeline entries, timeline intervals may be chunked. The underlying data associated
with a timeline entry remains unchanged when chunking occurs.
After loading objects via the add(org.joda.time.Interval, VersionType, org.apache.druid.timeline.partition.PartitionChunk<ObjectType>) method, the lookup(Interval) method can be used to get the list
of the most recent objects (according to the version) that match the given interval. The intent is that objects
represent a certain time period and when you do a lookup(Interval), you are asking for all of the objects
that you need to look at in order to get a correct answer about that time period.
The findFullyOvershadowed() method returns a list of objects that will never be returned by a call to lookup(org.joda.time.Interval) because they are overshadowed by some other object. This can be used in conjunction with the add(org.joda.time.Interval, VersionType, org.apache.druid.timeline.partition.PartitionChunk<ObjectType>)
and remove(org.joda.time.Interval, VersionType, org.apache.druid.timeline.partition.PartitionChunk<ObjectType>) methods to achieve "atomic" updates. First add new items, then check if those items caused
anything to be overshadowed, if so, remove the overshadowed elements and you have effectively updated your data set
without any user impact.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStores aPartitionChunkfor a given interval and version.class -
Constructor Summary
ConstructorsConstructorDescriptionVersionedIntervalTimeline(Comparator<? super VersionType> versionComparator) VersionedIntervalTimeline(Comparator<? super VersionType> versionComparator, boolean skipObjectsWithNoData) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(org.joda.time.Interval interval, VersionType version, PartitionChunk<ObjectType> object) voidfindChunk(org.joda.time.Interval interval, VersionType version, int partitionNum) Finds thePartitionChunkfor the given time interval, version and chunk number.This method should be deduplicated with DataSourcesSnapshot.determineOvershadowedSegments(): see https://github.com/apache/druid/issues/8070.findNonOvershadowedObjectsInInterval(org.joda.time.Interval interval, Partitions completeness) Computes a set with all objects falling within the specified interval which are at least partially "visible" in this interval (that is, are not fully overshadowed within this interval).first()static <VersionType,ObjectType extends Overshadowable<ObjectType>>
Iterable<ObjectType> getAllObjects(List<TimelineObjectHolder<VersionType, ObjectType>> holders) Map<org.joda.time.Interval, TreeMap<VersionType, VersionedIntervalTimeline<VersionType, ObjectType>.TimelineEntry>> intbooleanisEmpty()booleanisOvershadowed(org.joda.time.Interval interval, VersionType version, ObjectType object) Returns a lazy collection with all objects (including partially AND fully overshadowed, seefindFullyOvershadowed()) in this VersionedIntervalTimeline to be used for iteration orCollection.stream()transformation.last()lookup(org.joda.time.Interval interval) Does a lookup for the objects representing the given time interval.lookupWithIncompletePartitions(org.joda.time.Interval interval) Does a lookup for the objects representing the given time interval.remove(org.joda.time.Interval interval, VersionType version, PartitionChunk<ObjectType> chunk)
-
Constructor Details
-
VersionedIntervalTimeline
-
VersionedIntervalTimeline
public VersionedIntervalTimeline(Comparator<? super VersionType> versionComparator, boolean skipObjectsWithNoData)
-
-
Method Details
-
getAllObjects
public static <VersionType,ObjectType extends Overshadowable<ObjectType>> Iterable<ObjectType> getAllObjects(List<TimelineObjectHolder<VersionType, ObjectType>> holders) -
getAllTimelineEntries
public Map<org.joda.time.Interval,TreeMap<VersionType, getAllTimelineEntries()VersionedIntervalTimeline<VersionType, ObjectType>.TimelineEntry>> -
iterateAllObjects
Returns a lazy collection with all objects (including partially AND fully overshadowed, seefindFullyOvershadowed()) in this VersionedIntervalTimeline to be used for iteration orCollection.stream()transformation. The order of objects in this collection is unspecified. Note: iteration over the returned collection may not be as trivially cheap as, for example, iteration over an ArrayList. Try (to some reasonable extent) to organize the code so that it iterates the returned collection only once rather than several times. -
getNumObjects
public int getNumObjects() -
findNonOvershadowedObjectsInInterval
public Set<ObjectType> findNonOvershadowedObjectsInInterval(org.joda.time.Interval interval, Partitions completeness) Computes a set with all objects falling within the specified interval which are at least partially "visible" in this interval (that is, are not fully overshadowed within this interval). Note that this method returns a set ofVersionedIntervalTimeline. Duplicate objects in different time chunks will be removed in the result. -
add
public void add(org.joda.time.Interval interval, VersionType version, PartitionChunk<ObjectType> object) -
addAll
public void addAll(Iterator<VersionedIntervalTimeline.PartitionChunkEntry<VersionType, ObjectType>> objects) -
remove
@Nullable public PartitionChunk<ObjectType> remove(org.joda.time.Interval interval, VersionType version, PartitionChunk<ObjectType> chunk) -
findChunk
@Nullable public PartitionChunk<ObjectType> findChunk(org.joda.time.Interval interval, VersionType version, int partitionNum) Description copied from interface:TimelineLookupFinds thePartitionChunkfor the given time interval, version and chunk number.- Specified by:
findChunkin interfaceTimelineLookup<VersionType,ObjectType extends Overshadowable<ObjectType>>
-
lookup
Does a lookup for the objects representing the given time interval. Will *only* return PartitionHolders that are complete.- Specified by:
lookupin interfaceTimelineLookup<VersionType,ObjectType extends Overshadowable<ObjectType>> - Parameters:
interval- interval to find objects for- Returns:
- Holders representing the interval that the objects exist for, PartitionHolders are guaranteed to be complete
-
lookupWithIncompletePartitions
public List<TimelineObjectHolder<VersionType,ObjectType>> lookupWithIncompletePartitions(org.joda.time.Interval interval) Description copied from interface:TimelineLookupDoes a lookup for the objects representing the given time interval. Will also return incomplete PartitionHolders.- Specified by:
lookupWithIncompletePartitionsin interfaceTimelineLookup<VersionType,ObjectType extends Overshadowable<ObjectType>> - Parameters:
interval- interval to find objects for- Returns:
- Holders representing the interval that the objects exist for, PartitionHolders can be incomplete. Holders returned sorted by the interval.
-
isEmpty
public boolean isEmpty() -
first
-
last
-
findFullyOvershadowed
This method should be deduplicated with DataSourcesSnapshot.determineOvershadowedSegments(): see https://github.com/apache/druid/issues/8070. -
isOvershadowed
public boolean isOvershadowed(org.joda.time.Interval interval, VersionType version, ObjectType object)
-