Skip to content

Commit

Permalink
Enable corr, covar_pop and covar_samp (#147)
Browse files Browse the repository at this point in the history
* Enable corr covar_pop and covar_samp in aggregate.

* Adjust the accuracy to align with Spark.
  • Loading branch information
liujiayi771 authored and zhejiangxiaomai committed Mar 30, 2023
1 parent 462979e commit 799c054
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions velox/functions/prestosql/aggregates/CovarianceAggregates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,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;
// Need to modify the calculation order to maintain the same accuracy as spark
return accumulator.c2() / std::sqrt(accumulator.m2X() * accumulator.m2Y());
}
};

Expand Down
5 changes: 4 additions & 1 deletion velox/substrait/SubstraitToVeloxPlanValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,10 @@ bool SubstraitToVeloxPlanValidator::validate(
"var_samp",
"var_pop",
"bitwise_and_agg",
"bitwise_or_agg"};
"bitwise_or_agg",
"corr",
"covar_pop",
"covar_samp"};
for (const auto& funcSpec : funcSpecs) {
auto funcName = subParser_->getSubFunctionName(funcSpec);
if (supportedFuncs.find(funcName) == supportedFuncs.end()) {
Expand Down

0 comments on commit 799c054

Please sign in to comment.