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

      if (myagg.count == 0) { // SQL standard - return null for zero elements
        return null;
      } else {
        if (myagg.count > 1) {
          getResult().set(
              calculateStdResult(myagg.variance, myagg.count));
        } else { // for one element the variance is always 0
          getResult().set(0);
        }
        return getResult();
      }
    }
Compute the standard deviation by extending GenericUDAFVarianceEvaluator
and overriding the terminate() method of the evaluator.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFStd.java