datafu-pig/src/main/java/datafu/pig/stats/IntVAR.java [295:370]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            }catch(RuntimeException exp) {
                int errCode = 2103;
                String msg = "Problem while computing sum of squared values.";
                throw new ExecException(msg, errCode, PigException.BUG, exp);
            }
        }

        if(sawNonNull) {
            return new Long(sumSquare);
        } else {
            return null;
        }
    }

    @Override
    public Schema outputSchema(Schema input) {
        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE));
    }

    /* Accumulator interface implementation */
    private Long intermediateSumSquare = null;
    private Long intermediateSum = null;
    private Long intermediateCount = null;
    
    @Override
    public void accumulate(Tuple b) throws IOException {
        try {
            Long sum = sum(b);
            if(sum == null) {
                return;
            }
            
            Long sumSquare = sumSquare(b);
            if(sumSquare == null) {
                return;
            }
            
            // set default values
            if (intermediateSum == null || intermediateCount == null) {
                intermediateSumSquare = (long) 0;
                intermediateSum = (long) 0;
                intermediateCount = (long) 0;
            }
            
            long count = (Long)count(b);

            if (count > 0) {
                intermediateCount += count;
                intermediateSum += sum;
                intermediateSumSquare += sumSquare;
            }
        } 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);
        }
    }

    @Override
    public void cleanup() {
        intermediateSumSquare = null;
        intermediateSum = null;
        intermediateCount = null;
    }

    @Override
    public Double getValue() {
        Double var = null;
        if (intermediateCount != null && intermediateCount > 0) {
            Double avg = new Double((double)intermediateSum / intermediateCount);
            Double avgSquare = new Double((double)intermediateSumSquare / intermediateCount);
            var = avgSquare - avg*avg;
        }
        return var;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



datafu-pig/src/main/java/datafu/pig/stats/LongVAR.java [296:371]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            }catch(RuntimeException exp) {
                int errCode = 2103;
                String msg = "Problem while computing sum of squared values.";
                throw new ExecException(msg, errCode, PigException.BUG, exp);
            }
        }

        if(sawNonNull) {
            return new Long(sumSquare);
        } else {
            return null;
        }
    }

    @Override
    public Schema outputSchema(Schema input) {
        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE));
    }

    /* Accumulator interface implementation */
    private Long intermediateSumSquare = null;
    private Long intermediateSum = null;
    private Long intermediateCount = null;
    
    @Override
    public void accumulate(Tuple b) throws IOException {
        try {
            Long sum = sum(b);
            if(sum == null) {
                return;
            }
            
            Long sumSquare = sumSquare(b);
            if(sumSquare == null) {
                return;
            }
            
            // set default values
            if (intermediateSum == null || intermediateCount == null) {
                intermediateSumSquare = (long) 0;
                intermediateSum = (long) 0;
                intermediateCount = (long) 0;
            }
            
            long count = (Long)count(b);

            if (count > 0) {
                intermediateCount += count;
                intermediateSum += sum;
                intermediateSumSquare += sumSquare;
            }
        } 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);
        }
    }

    @Override
    public void cleanup() {
        intermediateSumSquare = null;
        intermediateSum = null;
        intermediateCount = null;
    }

    @Override
    public Double getValue() {
        Double var = null;
        if (intermediateCount != null && intermediateCount > 0) {
            Double avg = new Double((double)intermediateSum / intermediateCount);
            Double avgSquare = new Double((double)intermediateSumSquare / intermediateCount);
            var = avgSquare - avg*avg;
        }
        return var;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



