@Override
    public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException {
      super.init(m, parameters);

      // initialize input
      if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {
        inputOI = (PrimitiveObjectInspector) parameters[0];
      } else {
        ndvFieldOI = (BinaryObjectInspector) parameters[0];
      }

      // initialize output
      if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {
        partialResult = new BytesWritable();
        return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
      } else {
        result = new BytesWritable();
        return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
      }
    }
GenericUDAFComputeBitVector. This UDAF will compute a bit vector using
HyperLogLog algorithm. The ndv_compute_bit_vector function can
be used on top of it to extract an estimate of the ndv from it.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFComputeBitVectorHLL.java