// two intervals are exactly the same
if (leftTypeId == rightTypeId)
return leftType.getNullabilityType(nullable);
// two intervals are of the same *type*
else if ((typeFormatId = leftTypeId.getTypeFormatId()) == rightTypeId.getTypeFormatId())
return new DataTypeDescriptor(typeFormatId == TypeId.FormatIds.INTERVAL_DAY_SECOND_ID ?
TypeId.INTERVAL_SECOND_ID : TypeId.INTERVAL_MONTH_ID,
nullable);
// varchar
DataTypeDescriptor varcharType;
if ((varcharType = leftType).getTypeId().isStringTypeId() && rightTypeId.isIntervalTypeId()||
(varcharType = rightType).getTypeId().isStringTypeId() && leftTypeId.isIntervalTypeId()
&& operator.equals(PLUS_OP)) // when left is interval, only + is legal
return new DataTypeDescriptor(varcharType.getPrecision() > 10 ? TypeId.DATETIME_ID : TypeId.DATE_ID, nullable);
}
else if (operator.equals(TIMES_OP) || operator.equals(DIVIDE_OP) || operator.equals(DIV_OP))
{
// numeric / varchar and interval
TypeId intervalId = null;
if ((intervalId = leftTypeId).isIntervalTypeId() &&
(rightTypeId.isNumericTypeId() || rightTypeId.isStringTypeId())||
(intervalId = rightTypeId).isIntervalTypeId() &&
(leftTypeId.isNumericTypeId() || leftTypeId.isStringTypeId()) &&
operator.equals(TIMES_OP)) // when right is interval, only * is legal
return new DataTypeDescriptor(intervalId, nullable);
}
// Unsupported
return super.resolveArithmeticOperation(leftType, rightType, operator);
}