@Override
    public Object terminate(AggregationBuffer agg) throws HiveException {
      StdAgg myagg = (StdAgg) agg;

      if (myagg.count <= 1) {
        return null;
      } else {
        DoubleWritable result = getResult();
        result.set(myagg.covar / (myagg.count - 1));
        return result;
      }
    }
Compute the sample covariance by extending GenericUDAFCovarianceEvaluator and
overriding the terminate() method of the evaluator.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCovarianceSample.java