Class TimeExtractionFunction

  • All Implemented Interfaces:
    DruidJson, ExtractionFunction

    public class TimeExtractionFunction
    extends java.lang.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.

    • Field Detail

      • VALID_TIME_EXTRACT

        private static final com.google.common.collect.ImmutableSet<org.apache.calcite.avatica.util.TimeUnitRange> VALID_TIME_EXTRACT
      • VALID_TIME_FLOOR

        private static final com.google.common.collect.ImmutableSet<org.apache.calcite.avatica.util.TimeUnitRange> VALID_TIME_FLOOR
      • format

        private final java.lang.String format
      • timeZone

        private final java.lang.String timeZone
      • local

        private final java.lang.String local
    • Constructor Detail

      • TimeExtractionFunction

        public TimeExtractionFunction​(java.lang.String format,
                                      Granularity granularity,
                                      java.lang.String timeZone,
                                      java.lang.String local)
    • Method Detail

      • write

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

        public java.lang.String getFormat()
      • createDefault

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

        public static TimeExtractionFunction createExtractFromGranularity​(Granularity granularity,
                                                                          java.lang.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,
                                                                        java.lang.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

        @Nullable
        public static TimeExtractionFunction translateCastToTimeExtract​(RexNode rexNode,
                                                                        java.util.TimeZone timeZone)
        Parameters:
        rexNode - cast RexNode
        timeZone - timezone
        Returns:
        Druid Time extraction function or null when can not translate the cast.