@@ -0,0 +1,2246 @@
+package shaman.hive.udf;%0A%0Aimport java.util.List;%0A%0Aimport org.apache.hadoop.hive.ql.exec.Description;%0Aimport org.apache.hadoop.hive.ql.exec.UDFArgumentException;%0Aimport org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;%0Aimport org.apache.hadoop.hive.ql.metadata.HiveException;%0Aimport org.apache.hadoop.hive.ql.udf.generic.GenericUDF;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;%0Aimport org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;%0A%0A@Description(value=%22_FUNC_ sum values of a array%22, %0A        name=%22shaman_sum_array%22)%0Apublic class UDFArraySum extends GenericUDF %7B%0A%0A    private ListObjectInspector inputOI;%0A    private PrimitiveObjectInspector valueOI;%0A    %0A    @Override%0A    public ObjectInspector initialize(ObjectInspector%5B%5D arguments) throws UDFArgumentException %7B%0A        if (arguments.length != 1) %7B%0A            throw new UDFArgumentLengthException(%22_FUNC_ take one arguments, array%22);%0A        %7D%0A        this.inputOI = (ListObjectInspector) arguments%5B0%5D;%0A        valueOI = (PrimitiveObjectInspector) inputOI.getListElementObjectInspector();%0A        return PrimitiveObjectInspectorFactory.javaLongObjectInspector;%0A    %7D%0A%0A    @Override%0A    public Object evaluate(DeferredObject%5B%5D arguments) throws HiveException %7B%0A        %0A        long result = 0l;%0A        List%3C?%3E list = inputOI.getList(arguments%5B0%5D.get());%0A        for (Object l : list) %7B%0A            Object primitiveObject = valueOI.getPrimitiveJavaObject(l);%0A            if (primitiveObject instanceof Integer) %7B%0A                result += (Integer) primitiveObject;%0A            %7D else if (primitiveObject instanceof Long) %7B%0A                result += (Long) primitiveObject;%0A            %7D else if (primitiveObject instanceof Short) %7B%0A                result += (Short) primitiveObject;%0A            %7D else %7B%0A                throw new HiveException(%22can not cast %22 + primitiveObject);%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    @Override%0A    public String getDisplayString(String%5B%5D children) %7B%0A        return %22Sum the value array elements%22;%0A    %7D%0A%0A%7D%0A

add UDFArraySum.java