@Override
    public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException {
      GenericUDAFComputeBitVectorBase.NumericStatsAgg myagg = (GenericUDAFComputeBitVectorBase.NumericStatsAgg) agg;

      if (myagg.numDV == null) {
        myagg.numDV = HyperLogLog.builder().setSizeOptimized().build();
      }

      if (parameters[0] != null) {
        myagg.update(parameters[0], inputOI);
      }
    }
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