@Override
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
    if (arguments[0].get() == null || arguments[1].get() == null
        || arguments[2].get() == null) {
      return null;
    }
    String exprString = ((StringObjectInspector) argumentOIs[0])
        .getPrimitiveJavaObject(arguments[0].get());
    String fromString = ((StringObjectInspector) argumentOIs[1])
        .getPrimitiveJavaObject(arguments[1].get());
    String toString = ((StringObjectInspector) argumentOIs[2])
        .getPrimitiveJavaObject(arguments[2].get());

    char[] expr = exprString.toCharArray();
    char[] from = fromString.toCharArray();
    char[] to = toString.toCharArray();
    char[] result = new char[expr.length];
    System.arraycopy(expr, 0, result, 0, expr.length);
    Set<Character> seen = new HashSet<Character>();

    for (int i = 0; i < from.length; i++) {
      if (seen.contains(from[i])) {
        continue;
      }
      seen.add(from[i]);
      for (int j = 0; j < expr.length; j++) {
        if (expr[j] == from[i]) {
          result[j] = (i < to.length) ? to[i] : 0;
        }
      }
    }

    int pos = 0;
    for (int i = 0; i < result.length; i++) {
      if (result[i] != 0) {
        result[pos++] = result[i];
      }
    }
    resultText.set(new String(result, 0, pos));
    return resultText;
  }
Return a corresponding ordinal from an integer.
itests/util/src/main/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTestTranslate.java