Package org.apache.druid.timeline
Class SegmentId
- java.lang.Object
-
- org.apache.druid.timeline.SegmentId
-
- All Implemented Interfaces:
Comparable<SegmentId>
public final class SegmentId extends Object implements Comparable<SegmentId>
Identifier ofDataSegment.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(SegmentId o)static SegmentIddummy(String dataSource)Creates a dummy SegmentId with the given data source.static SegmentIddummy(String dataSource, int partitionNum)Creates a dummy SegmentId with the given data source and partition number.booleanequals(Object o)StringgetDataSource()org.joda.time.IntervalgetInterval()org.joda.time.DateTimegetIntervalEnd()org.joda.time.DateTimegetIntervalStart()intgetPartitionNum()StringgetVersion()inthashCode()static Iterable<SegmentId>iterateAllPossibleParsings(String segmentId)Returns a (potentially empty) lazy iteration of all possible valid parsings of the given segment id string intoSegmentIdobjects.static List<SegmentId>iteratePossibleParsingsWithDataSource(String dataSource, String segmentId)Returns a list of either 0, 1 or 2 elements containing possible parsings if the given segment id String representation with the given data source name.static SegmentIdmerged(String dataSource, org.joda.time.Interval interval, int partitionNum)Creates a merged SegmentId for the given data source, interval and partition number.static SegmentIdof(String dataSource, org.joda.time.Interval interval, String version, int partitionNum)static SegmentIdof(String dataSource, org.joda.time.Interval interval, String version, ShardSpec shardSpec)intsafeUpperLimitOfStringSize()SegmentDescriptortoDescriptor()StringtoString()static SegmentIdtryParse(String dataSource, String segmentId)Tries to parse a segment id from the given String representation, or returns null on failure.SegmentIdwithInterval(org.joda.time.Interval newInterval)
-
-
-
Method Detail
-
of
public static SegmentId of(String dataSource, org.joda.time.Interval interval, String version, int partitionNum)
-
of
public static SegmentId of(String dataSource, org.joda.time.Interval interval, String version, @Nullable ShardSpec shardSpec)
-
tryParse
@Nullable public static SegmentId tryParse(String dataSource, String segmentId)
Tries to parse a segment id from the given String representation, or returns null on failure. If returns a non-nullSegmentIdobject, callingtoString()on the latter is guaranteed to return a string equal to the argument string of thetryParse()call. It is possible that this method may incorrectly parse a segment id, for example if the dataSource name in the segment id contains a DateTime parseable string such as 'datasource_2000-01-01T00:00:00.000Z' and dataSource was provided as 'datasource'. The desired behavior in this case would be to return null since the identifier does not actually belong to the provided dataSource but a non-null result would be returned. This is an edge case that would currently only affect paged select queries with a union dataSource of two similarly-named dataSources as in the given example. Another source of ambiguity is the end of a segment id like '_123' - it could always be interpreted either as the partitionNum of the segment id, or as the end of the version, with the implicit partitionNum of 0. This method prefers the first iterpretation. To iterate all possible parsings of a segment id, useiteratePossibleParsingsWithDataSource(java.lang.String, java.lang.String).- Parameters:
dataSource- the dataSource corresponding to this segment idsegmentId- segment id- Returns:
- a
SegmentIdobject if the segment id could be parsed, null otherwise
-
iterateAllPossibleParsings
public static Iterable<SegmentId> iterateAllPossibleParsings(String segmentId)
Returns a (potentially empty) lazy iteration of all possible valid parsings of the given segment id string intoSegmentIdobjects. Warning: most of the parsing work is repeated each timeIterable.iterator()of this iterable is consumed, so it should be consumed only once if possible.
-
iteratePossibleParsingsWithDataSource
public static List<SegmentId> iteratePossibleParsingsWithDataSource(String dataSource, String segmentId)
Returns a list of either 0, 1 or 2 elements containing possible parsings if the given segment id String representation with the given data source name. Returns an empty list when parsing into a validSegmentIdobject is impossible. Returns a list of a single element when the given segment id doesn't end with '_[any positive number]', that means that the implicit partitionNum is 0. Otherwise the end of the segment id is interpreted in two ways: with the explicit partitionNum (the first element in the returned list), and with the implicit partitionNum of 0 and the version that ends with '_[any positive number]' (the second element in the returned list).
-
merged
public static SegmentId merged(String dataSource, org.joda.time.Interval interval, int partitionNum)
Creates a merged SegmentId for the given data source, interval and partition number. Used when segments are merged.
-
dummy
public static SegmentId dummy(String dataSource)
Creates a dummy SegmentId with the given data source. This method is useful in benchmark and test code.
-
dummy
public static SegmentId dummy(String dataSource, int partitionNum)
Creates a dummy SegmentId with the given data source and partition number. This method is useful in benchmark and test code.
-
getDataSource
public String getDataSource()
-
getIntervalStart
public org.joda.time.DateTime getIntervalStart()
-
getIntervalEnd
public org.joda.time.DateTime getIntervalEnd()
-
getInterval
public org.joda.time.Interval getInterval()
-
getVersion
public String getVersion()
-
getPartitionNum
public int getPartitionNum()
-
withInterval
public SegmentId withInterval(org.joda.time.Interval newInterval)
-
toDescriptor
public SegmentDescriptor toDescriptor()
-
compareTo
public int compareTo(SegmentId o)
- Specified by:
compareToin interfaceComparable<SegmentId>
-
safeUpperLimitOfStringSize
public int safeUpperLimitOfStringSize()
-
-