Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.operator.aggregation;
 
 
 import static com.facebook.presto.operator.aggregation.AggregationUtils.mergeVarianceState;
 import static com.facebook.presto.operator.aggregation.AggregationUtils.updateVarianceState;
 import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
 
 @AggregationFunction(""// Names are on output methods
 public final class VarianceAggregation
 {
     private VarianceAggregation() {}
 
     @InputFunction
     public static void doubleInput(VarianceState state, @SqlType(.double value)
     {
         updateVarianceState(statevalue);
     }
 
     @InputFunction
     public static void bigintInput(VarianceState state, @SqlType(.long value)
     {
         updateVarianceState(state, (doublevalue);
     }
 
     public static void combine(VarianceState stateVarianceState otherState)
     {
         mergeVarianceState(stateotherState);
     }
 
     @AggregationFunction(value = "variance", alias = "var_samp")
     public static void variance(VarianceState stateBlockBuilder out)
     {
         long count = state.getCount();
         if (count < 2) {
             out.appendNull();
         }
         else {
             double m2 = state.getM2();
             double result = m2 / (count - 1);
             .writeDouble(outresult);
         }
     }
 
     @AggregationFunction("var_pop")
     public static void variancePop(VarianceState stateBlockBuilder out)
     {
         long count = state.getCount();
         if (count == 0) {
             out.appendNull();
         }
         else {
             double m2 = state.getM2();
             double result = m2 / count;
             .writeDouble(outresult);
         }
     }
 
     @AggregationFunction(value = "stddev", alias = "stddev_samp")
     public static void stddev(VarianceState stateBlockBuilder out)
     {
         long count = state.getCount();
         if (count < 2) {
             out.appendNull();
         }
         else {
             double m2 = state.getM2();
             double result = m2 / (count - 1);
             result = Math.sqrt(result);
             .writeDouble(outresult);
         }
     }
 
     @AggregationFunction("stddev_pop")
     public static void stddevPop(VarianceState stateBlockBuilder out)
     {
         long count = state.getCount();
         if (count == 0) {
            out.appendNull();
        }
        else {
            double m2 = state.getM2();
            double result = m2 / count;
            result = Math.sqrt(result);
            .writeDouble(outresult);
        }
    }
New to GrepCode? Check out our FAQ X