Package org.apache.calcite.adapter.druid
Class TimeExtractionFunction
- java.lang.Object
-
- org.apache.calcite.adapter.druid.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 Summary
Fields Modifier and Type Field Description private java.lang.String
format
private Granularity
granularity
static java.lang.String
ISO_TIME_FORMAT
private java.lang.String
local
private java.lang.String
timeZone
private static com.google.common.collect.ImmutableSet<org.apache.calcite.avatica.util.TimeUnitRange>
VALID_TIME_EXTRACT
private static com.google.common.collect.ImmutableSet<org.apache.calcite.avatica.util.TimeUnitRange>
VALID_TIME_FLOOR
-
Constructor Summary
Constructors Constructor Description TimeExtractionFunction(java.lang.String format, Granularity granularity, java.lang.String timeZone, java.lang.String local)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TimeExtractionFunction
createDefault(java.lang.String timeZone)
Creates the default time format extraction function.static TimeExtractionFunction
createExtractFromGranularity(Granularity granularity, java.lang.String timeZone)
Creates the time format extraction function for the given granularity.static TimeExtractionFunction
createFloorFromGranularity(Granularity granularity, java.lang.String timeZone)
Creates time format floor time extraction function using a given granularity.java.lang.String
getFormat()
Granularity
getGranularity()
static boolean
isValidTimeExtract(RexNode rexNode)
Returns whether the RexCall contains a valid extract unit that we can serialize to Druid.static boolean
isValidTimeFloor(RexNode rexNode)
Returns whether the RexCall contains a valid FLOOR unit that we can serialize to Druid.static TimeExtractionFunction
translateCastToTimeExtract(RexNode rexNode, java.util.TimeZone timeZone)
void
write(com.fasterxml.jackson.core.JsonGenerator generator)
-
-
-
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
-
ISO_TIME_FORMAT
public static final java.lang.String ISO_TIME_FORMAT
- See Also:
- Constant Field Values
-
format
private final java.lang.String format
-
granularity
private final Granularity granularity
-
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
-
getFormat
public java.lang.String getFormat()
-
getGranularity
public Granularity getGranularity()
-
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 RexNodetimeZone
- timezone- Returns:
- Druid Time extraction function or null when can not translate the cast.
-
-