public class SqlTimeConverter extends Object
DefaultTimeGrain
and a list of
SqlDatePartFunction
to create groupBy statements on intervals of time.Constructor and Description |
---|
SqlTimeConverter()
Builds a sql time converter which can group by, filter, and reparse dateTimes from a row in a ResultSet using the
buildDefaultGranularityToDateFunctionsMap() map. |
SqlTimeConverter(Map<Granularity,List<org.apache.calcite.sql.fun.SqlDatePartFunction>> granularityToDateFunctionMap)
Builds a sql time converter which can group by, filter, and reparse dateTimes from a row in a ResultSet.
|
Modifier and Type | Method and Description |
---|---|
static Map<Granularity,List<org.apache.calcite.sql.fun.SqlDatePartFunction>> |
buildDefaultGranularityToDateFunctionsMap()
Builds the default mapping between
Granularity and the SqlDatePartFunction s needed to group on
and read into a DateTime. |
List<org.apache.calcite.rex.RexNode> |
buildGroupBy(org.apache.calcite.tools.RelBuilder builder,
Granularity granularity,
String timeColumn)
Builds a list of
RexNode which will effectively groupBy the given Granularity . |
org.apache.calcite.rex.RexNode |
buildTimeFilters(org.apache.calcite.tools.RelBuilder builder,
DruidAggregationQuery<?> druidQuery,
String timestampColumn)
Builds the time filters to only select rows that occur within the intervals of the query.
|
org.joda.time.DateTime |
getIntervalStart(int offset,
String[] recordValues,
DruidAggregationQuery<?> druidQuery)
Given an array of strings (a row from a
ResultSet ) and the
Granularity used to make groupBy statements on time, it will parse out a DateTime
for the row which represents the beginning of the interval it was grouped on. |
protected void |
setDateTime(int value,
org.apache.calcite.sql.fun.SqlDatePartFunction sqlDatePartFn,
org.joda.time.MutableDateTime dateTime)
Sets the correct part of a
DateTime corresponding to a
SqlDatePartFunction . |
List<org.apache.calcite.sql.fun.SqlDatePartFunction> |
timeGrainToDatePartFunctions(Granularity granularity)
Gets a list of
SqlDatePartFunction to be performed on a timestamp
which can be used to group by the given Granularity . |
public SqlTimeConverter()
buildDefaultGranularityToDateFunctionsMap()
map.public SqlTimeConverter(Map<Granularity,List<org.apache.calcite.sql.fun.SqlDatePartFunction>> granularityToDateFunctionMap)
granularityToDateFunctionMap
- The mapping defining what granularity needs to be kept in order to properly
group by and reparse a dateTime.public static Map<Granularity,List<org.apache.calcite.sql.fun.SqlDatePartFunction>> buildDefaultGranularityToDateFunctionsMap()
Granularity
and the SqlDatePartFunction
s needed to group on
and read into a DateTime.Granularity
and SqlDatePartFunction
s.public List<org.apache.calcite.sql.fun.SqlDatePartFunction> timeGrainToDatePartFunctions(Granularity granularity)
SqlDatePartFunction
to be performed on a timestamp
which can be used to group by the given Granularity
.granularity
- The granularity to map to a list of SqlDatePartFunction
.public org.apache.calcite.rex.RexNode buildTimeFilters(org.apache.calcite.tools.RelBuilder builder, DruidAggregationQuery<?> druidQuery, String timestampColumn)
builder
- The RelBuilder used for building queries.druidQuery
- The druid query to build filters over.timestampColumn
- The name of the timestamp column in the database.public List<org.apache.calcite.rex.RexNode> buildGroupBy(org.apache.calcite.tools.RelBuilder builder, Granularity granularity, String timeColumn)
RexNode
which will effectively groupBy the given Granularity
.builder
- The RelBuilder used with calcite to build queries.granularity
- The granularity to build the groupBy for.timeColumn
- The name of the timestamp column.RexNode
needed in the groupBy.public org.joda.time.DateTime getIntervalStart(int offset, String[] recordValues, DruidAggregationQuery<?> druidQuery)
ResultSet
) and the
Granularity
used to make groupBy statements on time, it will parse out a DateTime
for the row which represents the beginning of the interval it was grouped on.offset
- the last column before the date fields.recordValues
- The results returned by Sql needed to read the time columns.druidQuery
- The original druid query which was made using calling
buildGroupBy(RelBuilder, Granularity, String)
.protected void setDateTime(int value, org.apache.calcite.sql.fun.SqlDatePartFunction sqlDatePartFn, org.joda.time.MutableDateTime dateTime)
DateTime
corresponding to a
SqlDatePartFunction
.value
- The value to be set for the dateTime with the sqlDatePartFnsqlDatePartFn
- The function used to extract part of a date with sql.dateTime
- The original dateTime to create a copy of.Copyright © 2016–2018 Yahoo! Inc.. All rights reserved.