private LogicalExpression handleDateTruncFunction(final List<LogicalExpression> args) {
assert args.get(0) instanceof ValueExpressions.QuotedString;
String timeUnitStr = ((ValueExpressions.QuotedString) args.get(0)).value.toUpperCase();
TimeUnit timeUnit = TimeUnit.valueOf(timeUnitStr);
switch (timeUnit) {
case YEAR:
case MONTH:
case DAY:
case HOUR:
case MINUTE:
case SECOND:
case WEEK:
case QUARTER:
case DECADE:
case CENTURY:
case MILLENNIUM:
final String functionPostfix = StringUtils.capitalize(timeUnitStr.toLowerCase());
return FunctionCallFactory.createExpression("date_trunc_" + functionPostfix, args.subList(1, 2));
}
throw new UnsupportedOperationException("date_trunc function supports the following time units: " +
"YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, WEEK, QUARTER, DECADE, CENTURY, MILLENNIUM");
}