ClickHouse/src/Common/FieldVisitorSum.cpp

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

45 lines
1.7 KiB
C++
Raw Normal View History

2021-06-14 04:13:35 +00:00
#include <Common/FieldVisitorSum.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
FieldVisitorSum::FieldVisitorSum(const Field & rhs_) : rhs(rhs_) {}
// We can add all ints as unsigned regardless of their actual signedness.
bool FieldVisitorSum::operator() (Int64 & x) const { return this->operator()(reinterpret_cast<UInt64 &>(x)); }
bool FieldVisitorSum::operator() (UInt64 & x) const
{
2022-09-18 03:16:08 +00:00
x += applyVisitor(FieldVisitorConvertToNumber<UInt64>(), rhs);
2021-06-14 04:13:35 +00:00
return x != 0;
}
2022-09-10 03:04:40 +00:00
bool FieldVisitorSum::operator() (Float64 & x) const { x += rhs.get<Float64>(); return x != 0; }
2021-06-14 04:13:35 +00:00
bool FieldVisitorSum::operator() (Null &) const
{
/// Do not add anything
return rhs != 0;
}
2021-06-14 04:13:35 +00:00
bool FieldVisitorSum::operator() (String &) const { throw Exception("Cannot sum Strings", ErrorCodes::LOGICAL_ERROR); }
bool FieldVisitorSum::operator() (Array &) const { throw Exception("Cannot sum Arrays", ErrorCodes::LOGICAL_ERROR); }
bool FieldVisitorSum::operator() (Tuple &) const { throw Exception("Cannot sum Tuples", ErrorCodes::LOGICAL_ERROR); }
bool FieldVisitorSum::operator() (Map &) const { throw Exception("Cannot sum Maps", ErrorCodes::LOGICAL_ERROR); }
2021-08-20 21:11:22 +00:00
bool FieldVisitorSum::operator() (Object &) const { throw Exception("Cannot sum Objects", ErrorCodes::LOGICAL_ERROR); }
2021-06-14 04:13:35 +00:00
bool FieldVisitorSum::operator() (UUID &) const { throw Exception("Cannot sum UUIDs", ErrorCodes::LOGICAL_ERROR); }
bool FieldVisitorSum::operator() (AggregateFunctionStateData &) const
{
throw Exception("Cannot sum AggregateFunctionStates", ErrorCodes::LOGICAL_ERROR);
}
bool FieldVisitorSum::operator() (bool &) const { throw Exception("Cannot sum Bools", ErrorCodes::LOGICAL_ERROR); }
2021-06-14 04:13:35 +00:00
}