ClickHouse/src/AggregateFunctions/AggregateFunctionContingencyCoefficient.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1018 B
C++
Raw Normal View History

2021-06-09 21:14:36 +00:00
#include <AggregateFunctions/AggregateFunctionFactory.h>
2022-01-02 18:50:41 +00:00
#include <AggregateFunctions/CrossTab.h>
2021-06-09 21:14:36 +00:00
#include <AggregateFunctions/FactoryHelpers.h>
#include <memory>
2022-01-02 18:50:41 +00:00
#include <cmath>
2021-06-09 21:14:36 +00:00
namespace DB
{
2022-01-02 18:50:41 +00:00
2021-06-09 21:14:36 +00:00
namespace
{
2022-01-03 13:45:02 +00:00
struct ContingencyData : CrossTabData
{
2022-01-03 18:39:04 +00:00
static const char * getName()
{
return "contingency";
}
2022-01-03 13:45:02 +00:00
Float64 getResult() const
2022-01-02 18:50:41 +00:00
{
2022-01-03 13:45:02 +00:00
if (count < 2)
return std::numeric_limits<Float64>::quiet_NaN();
2022-01-02 18:50:41 +00:00
2022-01-03 19:18:57 +00:00
Float64 phi = getPhiSquared();
2022-01-03 13:45:02 +00:00
return sqrt(phi / (phi + count));
}
};
2022-01-02 19:42:56 +00:00
}
2021-06-09 21:14:36 +00:00
2022-01-02 18:50:41 +00:00
void registerAggregateFunctionContingency(AggregateFunctionFactory & factory)
2021-06-09 21:14:36 +00:00
{
2022-01-02 18:50:41 +00:00
factory.registerFunction(ContingencyData::getName(),
[](const std::string & name, const DataTypes & argument_types, const Array & parameters, const Settings *)
2022-01-02 18:50:41 +00:00
{
2022-01-03 18:39:04 +00:00
assertBinary(name, argument_types);
2022-01-02 18:50:41 +00:00
assertNoParameters(name, parameters);
return std::make_shared<AggregateFunctionCrossTab<ContingencyData>>(argument_types);
});
2021-06-09 21:14:36 +00:00
}
}