ClickHouse/src/Common/FieldVisitorSum.h

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

54 lines
1.3 KiB
C++
Raw Normal View History

2021-06-14 04:13:35 +00:00
#pragma once
#include <Common/FieldVisitors.h>
2022-09-18 03:16:08 +00:00
#include <Common/FieldVisitorConvertToNumber.h>
2021-06-14 04:13:35 +00:00
namespace DB
{
/** Implements `+=` operation.
* Returns false if the result is zero.
*/
class FieldVisitorSum : public StaticVisitor<bool>
{
private:
const Field & rhs;
public:
explicit FieldVisitorSum(const Field & rhs_);
// We can add all ints as unsigned regardless of their actual signedness.
bool operator() (Int64 & x) const;
bool operator() (UInt64 & x) const;
bool operator() (Float64 & x) const;
bool operator() (Null &) const;
bool operator() (String &) const;
bool operator() (Array &) const;
bool operator() (Tuple &) const;
bool operator() (Map &) const;
2021-08-20 21:11:22 +00:00
bool operator() (Object &) const;
2021-06-14 04:13:35 +00:00
bool operator() (UUID &) const;
bool operator() (IPv4 &) const;
bool operator() (IPv6 &) const;
2021-06-14 04:13:35 +00:00
bool operator() (AggregateFunctionStateData &) const;
2023-02-03 16:07:02 +00:00
bool operator() (CustomType &) const;
bool operator() (bool &) const;
2021-06-14 04:13:35 +00:00
template <typename T>
bool operator() (DecimalField<T> & x) const
{
2022-09-10 03:04:40 +00:00
x += rhs.get<DecimalField<T>>();
2021-06-14 04:13:35 +00:00
return x.getValue() != T(0);
}
template <typename T>
requires is_big_int_v<T>
2021-06-14 04:13:35 +00:00
bool operator() (T & x) const
{
2022-09-18 03:16:08 +00:00
x += applyVisitor(FieldVisitorConvertToNumber<T>(), rhs);
2021-06-14 04:13:35 +00:00
return x != T(0);
}
};
}