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

      if (myagg.count <= 1) { // SQL standard - return null for zero or one elements
        return null;
      } else {
        getResult().set(
            calculateStdSampleResult(myagg.variance, myagg.count));
        return getResult();
      }
    }
Compute the sample standard deviation by extending
GenericUDAFVarianceEvaluator and overriding the terminate() method of the
evaluator.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStdSample.java