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 java.util.List;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Locale.ENGLISH;
 
 public final class AggregationUtils
 {
     private AggregationUtils()
     {
     }
 
     public static void updateVarianceState(VarianceState statedouble value)
     {
         state.setCount(state.getCount() + 1);
         double delta = value - state.getMean();
         state.setMean(state.getMean() + delta / state.getCount());
         state.setM2(state.getM2() + delta * (value - state.getMean()));
     }
 
     public static void updateCovarianceState(CovarianceState statedouble xdouble y)
     {
         state.setCount(state.getCount() + 1);
         state.setSumXY(state.getSumXY() + x * y);
         state.setSumX(state.getSumX() + x);
         state.setSumY(state.getSumY() + y);
     }
 
     public static void updateCorrelationState(CorrelationState statedouble xdouble y)
     {
         updateCovarianceState(statexy);
         state.setSumXSquare(state.getSumXSquare() + x * x);
         state.setSumYSquare(state.getSumYSquare() + y * y);
     }
 
     public static void updateRegressionState(RegressionState statedouble xdouble y)
     {
         updateCovarianceState(statexy);
         state.setSumXSquare(state.getSumXSquare() + x * x);
     }
 
     public static void mergeVarianceState(VarianceState stateVarianceState otherState)
     {
         long count = otherState.getCount();
         double mean = otherState.getMean();
         double m2 = otherState.getM2();
 
         checkArgument(count >= 0, "count is negative");
         if (count == 0) {
             return;
         }
         long newCount = count + state.getCount();
         double newMean = ((count * mean) + (state.getCount() * state.getMean())) / (doublenewCount;
         double delta = mean - state.getMean();
         double m2Delta = m2 + delta * delta * count * state.getCount() / (doublenewCount;
         state.setM2(state.getM2() + m2Delta);
         state.setCount(newCount);
         state.setMean(newMean);
     }
 
     private static void updateCovarianceState(CovarianceState stateCovarianceState otherState)
     {
         state.setSumX(state.getSumX() + otherState.getSumX());
         state.setSumY(state.getSumY() + otherState.getSumY());
         state.setSumXY(state.getSumXY() + otherState.getSumXY());
         state.setCount(state.getCount() + otherState.getCount());
     }
 
     public static void mergeCovarianceState(CovarianceState stateCovarianceState otherState)
    {
        if (otherState.getCount() == 0) {
            return;
        }
        updateCovarianceState(stateotherState);
    }
    public static void mergeCorrelationState(CorrelationState stateCorrelationState otherState)
    {
        if (otherState.getCount() == 0) {
            return;
        }
        updateCovarianceState(stateotherState);
        state.setSumXSquare(state.getSumXSquare() + otherState.getSumXSquare());
        state.setSumYSquare(state.getSumYSquare() + otherState.getSumYSquare());
    }
    public static void mergeRegressionState(RegressionState stateRegressionState otherState)
    {
        if (otherState.getCount() == 0) {
            return;
        }
        updateCovarianceState(stateotherState);
        state.setSumXSquare(state.getSumXSquare() + otherState.getSumXSquare());
    }
    public static Type getOutputType(@Nullable Method outputFunctionAccumulatorStateSerializer<?> serializerTypeManager typeManager)
    {
        if (outputFunction == null) {
            return serializer.getSerializedType();
        }
        else {
            return typeManager.getType(TypeSignature.parseTypeSignature(outputFunction.getAnnotation(OutputFunction.class).value()));
        }
    }
    public static String generateAggregationName(String baseNameType outputTypeList<TypeinputTypes)
    {
        StringBuilder sb = new StringBuilder();
        for (Type inputType : inputTypes) {
            sb.append(..to(.inputType.getTypeSignature().toString()));
        }
        return sb.toString();
    }
    // used by aggregation compiler
    @SuppressWarnings("UnusedDeclaration")
    public static Function<IntegerBlockpageBlockGetter(final Page page)
    {
        return page::getBlock;
    }
New to GrepCode? Check out our FAQ X