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
  • 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:
      getTimeZone in class Granularity
    • getOrigin

      @Nullable public org.joda.time.DateTime getOrigin()
    • getFormatter

      public org.joda.time.format.DateTimeFormatter getFormatter(Granularity.Formatter type)
      Specified by:
      getFormatter in class Granularity
    • bucketStart

      public long bucketStart(long time)
      Specified by:
      bucketStart in class Granularity
    • increment

      public long increment(long t)
      Specified by:
      increment in class Granularity
    • increment

      public org.joda.time.DateTime increment(org.joda.time.DateTime time)
      Specified by:
      increment in class Granularity
    • bucketStart

      public org.joda.time.DateTime bucketStart(org.joda.time.DateTime time)
      Specified by:
      bucketStart in class Granularity
    • toDate

      public org.joda.time.DateTime toDate(String filePath, Granularity.Formatter formatter)
      Specified by:
      toDate in class Granularity
    • isAligned

      public boolean isAligned(org.joda.time.Interval interval)
      Description copied from class: Granularity
      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
      Specified by:
      isAligned in class Granularity
    • getCacheKey

      public byte[] getCacheKey()
      Description copied from interface: Cacheable
      Get a byte array used as a cache key.
      Specified by:
      getCacheKey in interface Cacheable
      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:
      toDateTime in class Granularity
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • canBeMappedTo

      public boolean canBeMappedTo(PeriodGranularity target)
      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 to Period("P1D") in UTC, since every hourly interval is fully contained within some day interval.
      • Period("PT1H") in America/Los_Angeles can be mapped to Period("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") in America/Los_Angeles cannot be mapped to Period("P1D") in UTC, since local day boundaries may cross UTC days and are not fully contained within a single UTC day.
      • Period("PT1H") in Asia/Kolkata cannot be mapped to Period("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:
      true if this granularity is fully contained within the target granularity; false otherwise
    • serialize

      public void serialize(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException
      Specified by:
      serialize in interface com.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:
      serializeWithType in interface com.fasterxml.jackson.databind.JsonSerializable
      Throws:
      IOException