Package org.apache.calcite.adapter.druid
Class TimeExtractionFunction
java.lang.Object
org.apache.calcite.adapter.druid.TimeExtractionFunction
- All Implemented Interfaces:
DruidJson
,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 Summary
ConstructorDescriptionTimeExtractionFunction
(String format, Granularity granularity, String timeZone, String local) -
Method Summary
Modifier and TypeMethodDescriptionstatic TimeExtractionFunction
createDefault
(String timeZone) Creates the default time format extraction function.static TimeExtractionFunction
createExtractFromGranularity
(Granularity granularity, String timeZone) Creates the time format extraction function for the given granularity.static TimeExtractionFunction
createFloorFromGranularity
(Granularity granularity, String timeZone) Creates time format floor time extraction function using a given granularity.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 @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.void
write
(com.fasterxml.jackson.core.JsonGenerator generator)
-
Constructor Details
-
TimeExtractionFunction
public TimeExtractionFunction(String format, Granularity granularity, String timeZone, String local)
-
-
Method Details
-
write
- Specified by:
write
in interfaceDruidJson
- Throws:
IOException
-
getFormat
-
getGranularity
-
createDefault
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
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
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 RexNodetimeZone
- Timezone
-