siddharthteotia commented on code in PR #9236: URL: https://github.com/apache/pinot/pull/9236#discussion_r953361062
########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/CovarianceAggregationFunction.java: ########## @@ -0,0 +1,225 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.pinot.core.query.aggregation.function; + +import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.core.common.BlockValSet; +import org.apache.pinot.core.query.aggregation.AggregationResultHolder; +import org.apache.pinot.core.query.aggregation.ObjectAggregationResultHolder; +import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder; +import org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder; +import org.apache.pinot.segment.local.customobject.CovarianceTuple; +import org.apache.pinot.segment.spi.AggregationFunctionType; + + +/** + * Aggregation function which returns the population covariance of 2 expressions. + * COVAR_POP(exp1, exp2) = mean(exp1 * exp2) - mean(exp1) * mean(exp2) + * COVAR_SAMP(exp1, exp2) = (sum(exp1 * exp2) - sum(exp1) * sum(exp2)) / (count - 1) + */ +public class CovarianceAggregationFunction implements AggregationFunction<CovarianceTuple, Double> { + private static final double DEFAULT_FINAL_RESULT = Double.NEGATIVE_INFINITY; + protected final ExpressionContext _expression1; + protected final ExpressionContext _expression2; + protected final boolean _isSample; + + public CovarianceAggregationFunction(List<ExpressionContext> arguments, boolean isSample) { + _expression1 = arguments.get(0); + _expression2 = arguments.get(1); + _isSample = isSample; + } + + @Override + public AggregationFunctionType getType() { + return AggregationFunctionType.COVARPOP; Review Comment: This should be changed if we are planning to use the same function/class for both population based and sample based -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org