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 int
compareTo(SegmentId o)
static SegmentId
dummy(String dataSource)
Creates a dummy SegmentId with the given data source.static SegmentId
dummy(String dataSource, int partitionNum)
Creates a dummy SegmentId with the given data source and partition number.boolean
equals(Object o)
String
getDataSource()
org.joda.time.Interval
getInterval()
org.joda.time.DateTime
getIntervalEnd()
org.joda.time.DateTime
getIntervalStart()
int
getPartitionNum()
String
getVersion()
int
hashCode()
static Iterable<SegmentId>
iterateAllPossibleParsings(String segmentId)
Returns a (potentially empty) lazy iteration of all possible valid parsings of the given segment id string intoSegmentId
objects.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 SegmentId
merged(String dataSource, org.joda.time.Interval interval, int partitionNum)
Creates a merged SegmentId for the given data source, interval and partition number.static SegmentId
of(String dataSource, org.joda.time.Interval interval, String version, int partitionNum)
static SegmentId
of(String dataSource, org.joda.time.Interval interval, String version, ShardSpec shardSpec)
int
safeUpperLimitOfStringSize()
SegmentDescriptor
toDescriptor()
Returns a descriptor that references the entire time range of the segment.String
toString()
static SegmentId
tryParse(String dataSource, String segmentId)
Tries to parse a segment id from the given String representation, or returns null on failure.SegmentId
withInterval(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-nullSegmentId
object, 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
SegmentId
object 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 intoSegmentId
objects. 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 validSegmentId
object 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()
Returns a descriptor that references the entire time range of the segment.
-
compareTo
public int compareTo(SegmentId o)
- Specified by:
compareTo
in interfaceComparable<SegmentId>
-
safeUpperLimitOfStringSize
public int safeUpperLimitOfStringSize()
-
-