Class DateRangeRules

java.lang.Object
org.apache.calcite.rel.rules.DateRangeRules

public abstract class DateRangeRules extends Object
Collection of planner rules that convert 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.

  • Field Details

    • FILTER_INSTANCE

      public static final RelOptRule FILTER_INSTANCE
      Rule that matches a Filter and converts calls to EXTRACT, FLOOR and CEIL functions to date ranges (typically using the BETWEEN operator).
  • Method Details

    • replaceTimeUnits

      public static RexNode replaceTimeUnits(RexBuilder rexBuilder, RexNode e, String timeZone)
      Replaces calls to EXTRACT, FLOOR and CEIL in an expression.