Class PeriodGranularity
java.lang.Object
org.apache.druid.java.util.common.granularity.Granularity
org.apache.druid.java.util.common.granularity.PeriodGranularity
- All Implemented Interfaces:
com.fasterxml.jackson.databind.JsonSerializable,Cacheable
public class PeriodGranularity
extends Granularity
implements com.fasterxml.jackson.databind.JsonSerializable
PeriodGranularity buckets data based on any custom time period
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.druid.java.util.common.granularity.Granularity
Granularity.FormatterNested classes/interfaces inherited from interface com.fasterxml.jackson.databind.JsonSerializable
com.fasterxml.jackson.databind.JsonSerializable.Base -
Field Summary
Fields inherited from class org.apache.druid.java.util.common.granularity.Granularity
IS_FINER_THAN -
Constructor Summary
ConstructorsConstructorDescriptionPeriodGranularity(org.joda.time.Period period, org.joda.time.DateTime origin, org.joda.time.DateTimeZone tz) -
Method Summary
Modifier and TypeMethodDescriptionlongbucketStart(long time) org.joda.time.DateTimebucketStart(org.joda.time.DateTime time) booleancanBeMappedTo(PeriodGranularity target) Returns true if this granularity can be mapped to the target granularity.booleanbyte[]Get a byte array used as a cache key.org.joda.time.format.DateTimeFormatterorg.joda.time.DateTimeorg.joda.time.Periodorg.joda.time.DateTimeZoneinthashCode()longincrement(long t) org.joda.time.DateTimeincrement(org.joda.time.DateTime time) booleanisAligned(org.joda.time.Interval interval) Return true only if the time chunks populated by this granularity includes the given interval time chunk.voidserialize(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) voidserializeWithType(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSerializer) org.joda.time.DateTimetoDate(String filePath, Granularity.Formatter formatter) org.joda.time.DateTimetoDateTime(long offset) toString()Methods inherited from class org.apache.druid.java.util.common.granularity.Granularity
bucket, bucketEnd, fromString, getIterable, granularitiesFinerThan, isFinerThan, mergeGranularities, toDate, toPath
-
Constructor Details
-
PeriodGranularity
public PeriodGranularity(org.joda.time.Period period, org.joda.time.DateTime origin, org.joda.time.DateTimeZone tz)
-
-
Method Details
-
getPeriod
public org.joda.time.Period getPeriod() -
getTimeZone
public org.joda.time.DateTimeZone getTimeZone()- Overrides:
getTimeZonein classGranularity
-
getOrigin
@Nullable public org.joda.time.DateTime getOrigin() -
getFormatter
- Specified by:
getFormatterin classGranularity
-
bucketStart
public long bucketStart(long time) - Specified by:
bucketStartin classGranularity
-
increment
public long increment(long t) - Specified by:
incrementin classGranularity
-
increment
public org.joda.time.DateTime increment(org.joda.time.DateTime time) - Specified by:
incrementin classGranularity
-
bucketStart
public org.joda.time.DateTime bucketStart(org.joda.time.DateTime time) - Specified by:
bucketStartin classGranularity
-
toDate
- Specified by:
toDatein classGranularity
-
isAligned
public boolean isAligned(org.joda.time.Interval interval) Description copied from class:GranularityReturn 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- Specified by:
isAlignedin classGranularity
-
getCacheKey
public byte[] getCacheKey()Description copied from interface:CacheableGet a byte array used as a cache key.- Specified by:
getCacheKeyin interfaceCacheable- Returns:
- bytes to be used as cache key - or null if this object should not be cached.
-
toDateTime
public org.joda.time.DateTime toDateTime(long offset) - Overrides:
toDateTimein classGranularity
-
equals
-
hashCode
public int hashCode() -
toString
-
canBeMappedTo
Returns true if this granularity can be mapped to the target granularity. A granularity can be mapped when each interval of the source fits entirely within a single interval of the target under the given time zone.Examples:
Period("PT1H")in UTC can be mapped toPeriod("P1D")in UTC, since every hourly interval is fully contained within some day interval.Period("PT1H")inAmerica/Los_Angelescan be mapped toPeriod("PT1H")in UTC, since each hour in local time still fits inside a corresponding hour in UTC (even though offsets can differ due to daylight saving).Period("P1D")inAmerica/Los_Angelescannot be mapped toPeriod("P1D")in UTC, since local day boundaries may cross UTC days and are not fully contained within a single UTC day.Period("PT1H")inAsia/Kolkatacannot be mapped toPeriod("PT1H")in UTC, since the 30-minute offset causes local hour intervals to straddle two UTC hour intervals.
- Parameters:
target- the target granularity to check against- Returns:
trueif this granularity is fully contained within the target granularity;falseotherwise
-
serialize
public void serialize(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException - Specified by:
serializein interfacecom.fasterxml.jackson.databind.JsonSerializable- Throws:
IOException
-
serializeWithType
public void serializeWithType(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider, com.fasterxml.jackson.databind.jsontype.TypeSerializer typeSerializer) throws IOException - Specified by:
serializeWithTypein interfacecom.fasterxml.jackson.databind.JsonSerializable- Throws:
IOException
-