Class TimeExtractionFunction

java.lang.Object
org.apache.calcite.adapter.druid.TimeExtractionFunction
All Implemented Interfaces:
DruidJson, ExtractionFunction

public class TimeExtractionFunction extends Object implements ExtractionFunction
Implementation of Druid time format extraction function.

These functions return the dimension value formatted according to the given format string, time zone, and locale.

For __time dimension values, this formats the time value bucketed by the aggregation granularity.

  • Constructor Details

  • Method Details

    • write

      public void write(com.fasterxml.jackson.core.JsonGenerator generator) throws IOException
      Specified by:
      write in interface DruidJson
      Throws:
      IOException
    • getFormat

      public String getFormat()
    • getGranularity

      public Granularity getGranularity()
    • createDefault

      public static TimeExtractionFunction createDefault(String timeZone)
      Creates the default time format extraction function.
      Returns:
      the time extraction function
    • createExtractFromGranularity

      public static TimeExtractionFunction createExtractFromGranularity(Granularity granularity, String timeZone)
      Creates the time format extraction function for the given granularity.
      Parameters:
      granularity - granularity to apply to the column
      Returns:
      the time extraction function corresponding to the granularity input unit VALID_TIME_EXTRACT for supported granularity
    • createFloorFromGranularity

      public static TimeExtractionFunction createFloorFromGranularity(Granularity granularity, String timeZone)
      Creates time format floor time extraction function using a given granularity.
      Parameters:
      granularity - granularity to apply to the column
      Returns:
      the time extraction function or null if granularity is not supported
    • isValidTimeExtract

      public static boolean isValidTimeExtract(RexNode rexNode)
      Returns whether the RexCall contains a valid extract unit that we can serialize to Druid.
      Parameters:
      rexNode - Extract expression
      Returns:
      true if the extract unit is valid
    • isValidTimeFloor

      public static boolean isValidTimeFloor(RexNode rexNode)
      Returns whether the RexCall contains a valid FLOOR unit that we can serialize to Druid.
      Parameters:
      rexNode - Extract expression
      Returns:
      true if the extract unit is valid
    • translateCastToTimeExtract

      public static @Nullable TimeExtractionFunction translateCastToTimeExtract(RexNode rexNode, TimeZone timeZone)
      Translates a CAST expression to a Druid Time extraction function, or null when can not translate the cast.
      Parameters:
      rexNode - CAST RexNode
      timeZone - Timezone