public abstract class DateRangeRules extends Object
EXTRACT(timeUnit FROM dateTime) = constant,
FLOOR(dateTime to timeUnit = constant} and
CEIL(dateTime to timeUnit = constant} to
dateTime BETWEEN lower AND upper.
The rules allow conversion of queries on time dimension tables, such as
SELECT ... FROM sales JOIN time_by_day USING (time_id) WHERE time_by_day.the_year = 1997 AND time_by_day.the_month IN (4, 5, 6)
into
SELECT ... FROM sales JOIN time_by_day USING (time_id) WHERE the_date BETWEEN DATE '2016-04-01' AND DATE '2016-06-30'
and is especially useful for Druid, which has a single timestamp column.
| Modifier and Type | Class and Description |
|---|---|
private static class |
DateRangeRules.ExtractFinder
Visitor that searches for calls to
EXTRACT, FLOOR or
CEIL, building a list of distinct time units. |
(package private) static class |
DateRangeRules.ExtractShuttle
Walks over an expression, replacing calls to
EXTRACT, FLOOR and CEIL with date ranges. |
static class |
DateRangeRules.FilterDateRangeRule
Rule that converts EXTRACT, FLOOR and CEIL in a
Filter into a date
range. |
| Modifier and Type | Field and Description |
|---|---|
static RelOptRule |
FILTER_INSTANCE |
private static com.google.common.base.Predicate<Filter> |
FILTER_PREDICATE |
private static Map<org.apache.calcite.avatica.util.TimeUnitRange,Integer> |
TIME_UNIT_CODES |
private static Map<org.apache.calcite.avatica.util.TimeUnitRange,org.apache.calcite.avatica.util.TimeUnitRange> |
TIME_UNIT_PARENTS |
| Modifier | Constructor and Description |
|---|---|
private |
DateRangeRules() |
| Modifier and Type | Method and Description |
|---|---|
(package private) static com.google.common.collect.ImmutableSortedSet<org.apache.calcite.avatica.util.TimeUnitRange> |
extractTimeUnits(RexNode e)
Tests whether an expression contains one or more calls to the
EXTRACT function, and if so, returns the time units used. |
static RexNode |
replaceTimeUnits(RexBuilder rexBuilder,
RexNode e,
String timeZone)
Replaces calls to EXTRACT, FLOOR and CEIL in an expression.
|
private static final com.google.common.base.Predicate<Filter> FILTER_PREDICATE
public static final RelOptRule FILTER_INSTANCE
private static final Map<org.apache.calcite.avatica.util.TimeUnitRange,Integer> TIME_UNIT_CODES
private static final Map<org.apache.calcite.avatica.util.TimeUnitRange,org.apache.calcite.avatica.util.TimeUnitRange> TIME_UNIT_PARENTS
static com.google.common.collect.ImmutableSortedSet<org.apache.calcite.avatica.util.TimeUnitRange> extractTimeUnits(RexNode e)
EXTRACT function, and if so, returns the time units used.
The result is an immutable set in natural order. This is important, because code relies on the collection being sorted (so YEAR comes before MONTH before HOUR) and unique. A predicate on MONTH is not useful if there is no predicate on YEAR. Then when we apply the predicate on DAY it doesn't generate hundreds of ranges we'll later throw away.
public static RexNode replaceTimeUnits(RexBuilder rexBuilder, RexNode e, String timeZone)
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.