Java Code Examples for org.apache.calcite.avatica.util.TimeUnitRange#YEAR

The following examples show how to use org.apache.calcite.avatica.util.TimeUnitRange#YEAR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateRangeRules.java    From Quicksql with MIT License 6 votes vote down vote up
private boolean canRewriteExtract(RexNode operand) {
  // We rely on timeUnits being sorted (so YEAR comes before MONTH
  // before HOUR) and unique. If we have seen a predicate on YEAR,
  // operandRanges will not be empty. This checks whether we can rewrite
  // the "extract" condition. For example, in the condition
  //
  //   extract(MONTH from time) = someValue
  //   OR extract(YEAR from time) = someValue
  //
  // we cannot rewrite extract on MONTH.
  if (timeUnit == TimeUnitRange.YEAR) {
    return true;
  }
  final RangeSet<Calendar> calendarRangeSet = operandRanges.get(operand);
  if (calendarRangeSet == null || calendarRangeSet.isEmpty()) {
    return false;
  }
  for (Range<Calendar> range : calendarRangeSet.asRanges()) {
    // Cannot reWrite if range does not have an upper or lower bound
    if (!range.hasUpperBound() || !range.hasLowerBound()) {
      return false;
    }
  }
  return true;
}
 
Example 2
Source File: DateRangeRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
private boolean canRewriteExtract(RexNode operand) {
  // We rely on timeUnits being sorted (so YEAR comes before MONTH
  // before HOUR) and unique. If we have seen a predicate on YEAR,
  // operandRanges will not be empty. This checks whether we can rewrite
  // the "extract" condition. For example, in the condition
  //
  //   extract(MONTH from time) = someValue
  //   OR extract(YEAR from time) = someValue
  //
  // we cannot rewrite extract on MONTH.
  if (timeUnit == TimeUnitRange.YEAR) {
    return true;
  }
  final RangeSet<Calendar> calendarRangeSet = operandRanges.get(operand);
  if (calendarRangeSet == null || calendarRangeSet.isEmpty()) {
    return false;
  }
  for (Range<Calendar> range : calendarRangeSet.asRanges()) {
    // Cannot reWrite if range does not have an upper or lower bound
    if (!range.hasUpperBound() || !range.hasLowerBound()) {
      return false;
    }
  }
  return true;
}
 
Example 3
Source File: ExpressionConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private static TimeUnitRange intervalUnitToUnitRange(TimeIntervalUnit intervalUnit) {
	switch (intervalUnit) {
		case YEAR:
			return TimeUnitRange.YEAR;
		case YEAR_TO_MONTH:
			return TimeUnitRange.YEAR_TO_MONTH;
		case QUARTER:
			return TimeUnitRange.QUARTER;
		case MONTH:
			return TimeUnitRange.MONTH;
		case WEEK:
			return TimeUnitRange.WEEK;
		case DAY:
			return TimeUnitRange.DAY;
		case DAY_TO_HOUR:
			return TimeUnitRange.DAY_TO_HOUR;
		case DAY_TO_MINUTE:
			return TimeUnitRange.DAY_TO_MINUTE;
		case DAY_TO_SECOND:
			return TimeUnitRange.DAY_TO_SECOND;
		case HOUR:
			return TimeUnitRange.HOUR;
		case SECOND:
			return TimeUnitRange.SECOND;
		case HOUR_TO_MINUTE:
			return TimeUnitRange.HOUR_TO_MINUTE;
		case HOUR_TO_SECOND:
			return TimeUnitRange.HOUR_TO_SECOND;
		case MINUTE:
			return TimeUnitRange.MINUTE;
		case MINUTE_TO_SECOND:
			return TimeUnitRange.MINUTE_TO_SECOND;
		default:
			throw new UnsupportedOperationException("TimeIntervalUnit is: " + intervalUnit);
	}
}