From 066ca787cc23334b13a060047eee04ef95dc15c5 Mon Sep 17 00:00:00 2001 From: rui-mo Date: Wed, 13 Sep 2023 11:57:59 +0800 Subject: [PATCH] Fix corr accuracy --- .../functions/prestosql/aggregates/CovarianceAggregates.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/velox/functions/prestosql/aggregates/CovarianceAggregates.cpp b/velox/functions/prestosql/aggregates/CovarianceAggregates.cpp index 1275d39444fb..3cdbdbfae5a6 100644 --- a/velox/functions/prestosql/aggregates/CovarianceAggregates.cpp +++ b/velox/functions/prestosql/aggregates/CovarianceAggregates.cpp @@ -236,9 +236,8 @@ struct CorrResultAccessor { } static double result(const CorrAccumulator& accumulator) { - double stddevX = std::sqrt(accumulator.m2X()); - double stddevY = std::sqrt(accumulator.m2Y()); - return accumulator.c2() / stddevX / stddevY; + // Modify the calculation order to maintain the same accuracy with spark. + return accumulator.c2() / std::sqrt(accumulator.m2X() * accumulator.m2Y()); } };