This patch does the trick. As a side effect, UDAF can take complex arguments and return complex values - Hive will convert the object to the corresponding Java Class on the fly.
This patch also includes an example UDAF (average) that uses a static inner class with 2 fields: mCount and mSum to store the internal state. The terminatePartial function just returns an object of this inner class, and Hive is capable of reading the value out using reflection ObjectInspector. Then in the reducer, Hive converts a struct with these 2 fields into an object of this inner class by using the ReflectionStructObjectInspector(which implements SettableStructObjectInspector).