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 class
Granularity.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.Interval
bucket(org.joda.time.DateTime t)
Return a granularity-sized Interval containing a particular DateTime.org.joda.time.DateTime
bucketEnd(org.joda.time.DateTime time)
abstract long
bucketStart(long time)
abstract org.joda.time.DateTime
bucketStart(org.joda.time.DateTime time)
static Granularity
fromString(String str)
abstract org.joda.time.format.DateTimeFormatter
getFormatter(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.DateTimeZone
getTimeZone()
static List<Granularity>
granularitiesFinerThan(Granularity gran0)
Returns a list of standard granularities that are equal to, or finer than, a provided granularity.abstract long
increment(long time)
abstract org.joda.time.DateTime
increment(org.joda.time.DateTime time)
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.boolean
isFinerThan(Granularity g)
Decides whether this granularity is finer than the other granularitystatic Granularity
mergeGranularities(List<Granularity> toMerge)
simple merge strategy on query granularity that checks if all are equal or else returns null.org.joda.time.DateTime
toDate(String filePath)
abstract org.joda.time.DateTime
toDate(String filePath, Granularity.Formatter formatter)
org.joda.time.DateTime
toDateTime(long offset)
String
toPath(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.
-
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
Granularity
is 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.ETERNITY
and 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.
-
-