public static String getOrdinal(int i) {
    int unit = i % 10;
    return (i <= 0) ? "" : (i != 11 && unit == 1) ? i + "st"
        : (i != 12 && unit == 2) ? i + "nd" : (i != 13 && unit == 3) ? i + "rd"
        : i + "th";
  }
Return an ordinal from an integer.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFUtils.java