Class DruidDateTimeUtils

java.lang.Object
org.apache.calcite.adapter.druid.DruidDateTimeUtils

public class DruidDateTimeUtils extends Object
Utilities for generating intervals from RexNode.
  • Field Details

    • LOGGER

      protected static final org.slf4j.Logger LOGGER
  • Method Details

    • createInterval

      public static @Nullable List<org.joda.time.Interval> createInterval(RexNode e)
      Generates a list of Intervals equivalent to a given expression. Assumes that all the predicates in the input reference a single column: the timestamp column.
    • toInterval

      protected static List<org.joda.time.Interval> toInterval(List<com.google.common.collect.Range<Long>> ranges)
    • extractRanges

      protected static @Nullable List<com.google.common.collect.Range<Long>> extractRanges(RexNode node, boolean withNot)
    • leafToRanges

      protected static @Nullable List<com.google.common.collect.Range<Long>> leafToRanges(RexCall call, boolean withNot)
    • literalValue

      protected static @Nullable Long literalValue(RexNode node)
      Returns the literal value for the given node, assuming it is a literal with datetime type, or a cast that only alters nullability on top of a literal with datetime type.
    • extractGranularity

      public static @Nullable Granularity extractGranularity(RexNode node, String timeZone)
      Infers granularity from a time unit. It supports FLOOR(<time> TO <timeunit>) and EXTRACT(<timeunit> FROM <time>). Returns null if it cannot be inferred.
      Parameters:
      node - the Rex node
      Returns:
      the granularity, or null if it cannot be inferred
    • toISOPeriodFormat

      public static @Nullable String toISOPeriodFormat(Granularity.Type type)
      Converts a granularity to ISO period format.
      Parameters:
      type - Druid Granularity to translate as period of time
      Returns:
      String representing the granularity as ISO8601 Period of Time; null for unknown case
    • toDruidGranularity

      public static @Nullable Granularity.Type toDruidGranularity(org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
      Translates a Calcite TimeUnitRange to a Druid Granularity.
      Parameters:
      timeUnit - Calcite Time unit to convert
      Returns:
      Druid Granularity or null