case Tokens.SQL_TSI_FRAC_SECOND : {
long seconds = units / DTIType.limitNanoseconds;
int nanos = (int) (units % DTIType.limitNanoseconds);
t = Type.SQL_INTERVAL_SECOND_MAX_FRACTION;
o = new IntervalSecondData(seconds, nanos, t);
return dataType.add(source, o, t);
}
case Tokens.SQL_TSI_SECOND :
t = Type.SQL_INTERVAL_SECOND;
o = IntervalSecondData.newIntervalSeconds(units, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_MINUTE :
t = Type.SQL_INTERVAL_MINUTE;
o = IntervalSecondData.newIntervalMinute(units, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_HOUR :
t = Type.SQL_INTERVAL_HOUR;
o = IntervalSecondData.newIntervalHour(units, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_DAY :
t = Type.SQL_INTERVAL_DAY;
o = IntervalSecondData.newIntervalDay(units, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_WEEK :
t = Type.SQL_INTERVAL_DAY;
o = IntervalSecondData.newIntervalDay(units * 7, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_MONTH :
t = Type.SQL_INTERVAL_MONTH;
o = IntervalMonthData.newIntervalMonth(units, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_QUARTER :
t = Type.SQL_INTERVAL_MONTH;
o = IntervalMonthData.newIntervalMonth(units * 3, t);
return dataType.add(source, o, t);
case Tokens.SQL_TSI_YEAR :
t = Type.SQL_INTERVAL_YEAR;
o = IntervalMonthData.newIntervalMonth(units, t);
return dataType.add(source, o, t);
default :
throw Error.runtimeError(ErrorCode.U_S0500,
"FunctionCustom");
}
}
case FUNC_TIMESTAMPDIFF : {
if (data[1] == null || data[2] == null) {
return null;
}
int part = ((Number) nodes[0].valueData).intValue();
TimestampData a = (TimestampData) data[2];
TimestampData b = (TimestampData) data[1];
if (nodes[2].dataType.isDateTimeTypeWithZone()) {
a = (TimestampData) Type.SQL_TIMESTAMP.convertToType(
session, a, Type.SQL_TIMESTAMP_WITH_TIME_ZONE);
}
if (nodes[1].dataType.isDateTimeTypeWithZone()) {
b = (TimestampData) Type.SQL_TIMESTAMP.convertToType(
session, b, Type.SQL_TIMESTAMP_WITH_TIME_ZONE);
}
IntervalType t;
switch (part) {
case Tokens.SQL_TSI_FRAC_SECOND :
t = Type.SQL_INTERVAL_SECOND_MAX_PRECISION;
IntervalSecondData interval =
(IntervalSecondData) t.subtract(a, b, null);
return new Long(
DTIType.limitNanoseconds * interval.getSeconds()
+ interval.getNanos());
case Tokens.SQL_TSI_SECOND :
t = Type.SQL_INTERVAL_SECOND_MAX_PRECISION;
return new Long(t.convertToLong(t.subtract(a, b,