1431 final RexBuilder rexBuilder = cx.getRexBuilder();
1432 final SqlLiteral unitLiteral = call.operand(0);
1433 TimeUnit unit = unitLiteral.symbolValue(TimeUnit.class);
1434 BigDecimal multiplier = BigDecimal.ONE;
1435 BigDecimal divider = BigDecimal.ONE;
1436 SqlTypeName sqlTypeName =
1437 unit == TimeUnit.NANOSECOND ? SqlTypeName.BIGINT : SqlTypeName.INTEGER;
1443 multiplier = BigDecimal.valueOf(DateTimeUtils.MILLIS_PER_SECOND);
1444 divider = unit.multiplier;
1445 unit = TimeUnit.SECOND;
1448 divider = unit.multiplier;
1449 unit = TimeUnit.MONTH;
1452 final SqlIntervalQualifier qualifier =
1453 new SqlIntervalQualifier(unit, null, SqlParserPos.ZERO);
1454 final RexNode op2 = cx.convertExpression(call.operand(2));
1455 final RexNode op1 = cx.convertExpression(call.operand(1));
1456 final RelDataType intervalType = cx.getTypeFactory().createTypeWithNullability(
1457 cx.getTypeFactory().createSqlIntervalType(qualifier),
1458 op1.getType().isNullable() || op2.getType().isNullable());
1459 final RexCall rexCall = (RexCall) rexBuilder.makeCall(
1460 intervalType, SqlStdOperatorTable.MINUS_DATE, ImmutableList.of(op2, op1));
1461 final RelDataType intType = cx.getTypeFactory().createTypeWithNullability(
1462 cx.getTypeFactory().createSqlType(sqlTypeName),
1463 SqlTypeUtil.containsNullable(rexCall.getType()));
1464 RexNode e = rexBuilder.makeCast(intType, rexCall);
1465 return rexBuilder.multiplyDivide(e, multiplier, divider);