datafu-pig/src/main/java/datafu/pig/stats/LongVAR.java [161:188]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        public Double exec(Tuple input) throws IOException {
            try {
                DataBag b = (DataBag)input.get(0);
                Tuple combined = combine(b);

                Long sum = (Long)combined.get(0);
                Long sumSquare = (Long)combined.get(1);
                if(sum == null) {
                    return null;
                }
                Long count = (Long)combined.get(2);

                Double var = null;
                
                if (count > 0) {
                    Double avg = new Double((double)sum / count);
                    Double avgSquare = new Double((double)sumSquare / count);
                    var = avgSquare - avg*avg;
                }
                return var;
            } catch (ExecException ee) {
                throw ee;
            } catch (Exception e) {
                int errCode = 2106;
                String msg = "Error while computing variance in " + this.getClass().getSimpleName();
                throw new ExecException(msg, errCode, PigException.BUG, e);
            }
        }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



datafu-pig/src/main/java/datafu/pig/stats/IntVAR.java [160:187]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        public Double exec(Tuple input) throws IOException {
            try {
                DataBag b = (DataBag)input.get(0);
                Tuple combined = combine(b);

                Long sum = (Long)combined.get(0);
                Long sumSquare = (Long)combined.get(1);
                if(sum == null) {
                    return null;
                }
                Long count = (Long)combined.get(2);

                Double var = null;
                
                if (count > 0) {
                    Double avg = new Double((double)sum / count);
                    Double avgSquare = new Double((double)sumSquare / count);
                    var = avgSquare - avg*avg;
                }
                return var;
            } catch (ExecException ee) {
                throw ee;
            } catch (Exception e) {
                int errCode = 2106;
                String msg = "Error while computing variance in " + this.getClass().getSimpleName();
                throw new ExecException(msg, errCode, PigException.BUG, e);
            }
        }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



