public class UDFExample { public static Integer fact( Integer x ) { if (x == null) return null; int x_t = x.intValue(); if (x_t < 0) return new Integer(0); int factResult = 1; while (x_t > 1) { factResult = factResult * x_t; x_t = x_t - 1; } return new Integer(factResult); } }