Class Granularity
- java.lang.Object
-
- org.apache.druid.java.util.common.granularity.Granularity
-
- All Implemented Interfaces:
Cacheable
- Direct Known Subclasses:
AllGranularity,DurationGranularity,NoneGranularity,PeriodGranularity
public abstract class Granularity extends Object implements Cacheable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGranularity.Formatter
-
Field Summary
Fields Modifier and Type Field Description static Comparator<Granularity>IS_FINER_THAN
-
Constructor Summary
Constructors Constructor Description Granularity()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description org.joda.time.Intervalbucket(org.joda.time.DateTime t)Return a granularity-sized Interval containing a particular DateTime.org.joda.time.DateTimebucketEnd(org.joda.time.DateTime time)abstract longbucketStart(long time)abstract org.joda.time.DateTimebucketStart(org.joda.time.DateTime time)static GranularityfromString(String str)abstract org.joda.time.format.DateTimeFormattergetFormatter(Granularity.Formatter type)Iterable<org.joda.time.Interval>getIterable(org.joda.time.Interval input)Return an iterable of granular buckets that overlap a particular interval.org.joda.time.DateTimeZonegetTimeZone()static List<Granularity>granularitiesFinerThan(Granularity gran0)Returns a list of standard granularities that are equal to, or finer than, a provided granularity.abstract longincrement(long time)abstract org.joda.time.DateTimeincrement(org.joda.time.DateTime time)abstract booleanisAligned(org.joda.time.Interval interval)Return true only if the time chunks populated by this granularity includes the given interval time chunk.booleanisFinerThan(Granularity g)Decides whether this granularity is finer than the other granularitystatic GranularitymergeGranularities(List<Granularity> toMerge)simple merge strategy on query granularity that checks if all are equal or else returns null.org.joda.time.DateTimetoDate(String filePath)abstract org.joda.time.DateTimetoDate(String filePath, Granularity.Formatter formatter)org.joda.time.DateTimetoDateTime(long offset)StringtoPath(org.joda.time.DateTime time)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.java.util.common.Cacheable
getCacheKey
-
-
-
-
Field Detail
-
IS_FINER_THAN
public static final Comparator<Granularity> IS_FINER_THAN
-
-
Method Detail
-
fromString
public static Granularity fromString(String str)
-
mergeGranularities
public static Granularity mergeGranularities(List<Granularity> toMerge)
simple merge strategy on query granularity that checks if all are equal or else returns null. this can be improved in future but is good enough for most use-cases.
-
granularitiesFinerThan
public static List<Granularity> granularitiesFinerThan(Granularity gran0)
Returns a list of standard granularities that are equal to, or finer than, a provided granularity. ALL will not be returned unless the provided granularity is ALL. NONE will never be returned, even if the provided granularity is NONE. This is because the main usage of this function in production is segment allocation, and we do not wish to generate NONE-granular segments. The list of granularities returned contains WEEK only if the requested granularity is WEEK.
-
getFormatter
public abstract org.joda.time.format.DateTimeFormatter getFormatter(Granularity.Formatter type)
-
increment
public abstract long increment(long time)
-
increment
public abstract org.joda.time.DateTime increment(org.joda.time.DateTime time)
-
bucketStart
public abstract long bucketStart(long time)
-
bucketStart
public abstract org.joda.time.DateTime bucketStart(org.joda.time.DateTime time)
-
toDate
public abstract org.joda.time.DateTime toDate(String filePath, Granularity.Formatter formatter)
-
isAligned
public abstract boolean isAligned(org.joda.time.Interval interval)
Return true only if the time chunks populated by this granularity includes the given interval time chunk. The interval must fit exactly into the scheme of the granularity for this to return true
-
getTimeZone
public org.joda.time.DateTimeZone getTimeZone()
-
bucketEnd
public org.joda.time.DateTime bucketEnd(org.joda.time.DateTime time)
-
toDateTime
public org.joda.time.DateTime toDateTime(long offset)
-
toDate
public org.joda.time.DateTime toDate(String filePath)
-
toPath
public final String toPath(org.joda.time.DateTime time)
-
bucket
public final org.joda.time.Interval bucket(org.joda.time.DateTime t)
Return a granularity-sized Interval containing a particular DateTime.
-
isFinerThan
public boolean isFinerThan(Granularity g)
Decides whether this granularity is finer than the other granularity- Returns:
- true if this
Granularityis finer than the passed one
-
getIterable
public Iterable<org.joda.time.Interval> getIterable(org.joda.time.Interval input)
Return an iterable of granular buckets that overlap a particular interval. In cases where the number of granular buckets is very large, the Iterable returned by this method will take an excessive amount of time to compute, and materializing it into a collection will take an excessive amount of memory. For example, this happens in the extreme case of an input interval ofIntervals.ETERNITYand any granularity other thanGranularities.ALL, as well as cases like an input interval of ten years withGranularities.SECOND. To avoid issues stemming from large numbers of buckets, this method should be avoided, and code that uses this method should be rewritten to use some other approach. For example: rather than computing all possible buckets in a wide time range, only process buckets related to actual data points that appear.
-
-