This commit is contained in:
Amos Bird 2021-08-30 03:00:00 +08:00
parent f2374a6916
commit d5d1873b45
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
6 changed files with 24 additions and 14 deletions

View File

@ -24,7 +24,7 @@ static inline void writeQuoted(const DecimalField<T> & x, WriteBuffer & buf)
writeChar('\'', buf);
}
String FieldVisitorDump::operator() (const Null & x) const { return x.is_negative_infinity ? "-Inf" : (x.is_positive_infinity ? "+Inf" : "NULL"); }
String FieldVisitorDump::operator() (const Null & x) const { return x.isNegativeInfinity() ? "-Inf" : (x.isPositiveInfinity() ? "+Inf" : "NULL"); }
String FieldVisitorDump::operator() (const UInt64 & x) const { return formatQuotedWithPrefix(x, "UInt64_"); }
String FieldVisitorDump::operator() (const Int64 & x) const { return formatQuotedWithPrefix(x, "Int64_"); }
String FieldVisitorDump::operator() (const Float64 & x) const { return formatQuotedWithPrefix(x, "Float64_"); }

View File

@ -52,7 +52,7 @@ static String formatFloat(const Float64 x)
}
String FieldVisitorToString::operator() (const Null & x) const { return x.is_negative_infinity ? "-Inf" : (x.is_positive_infinity ? "+Inf" : "NULL"); }
String FieldVisitorToString::operator() (const Null & x) const { return x.isNegativeInfinity() ? "-Inf" : (x.isPositiveInfinity() ? "+Inf" : "NULL"); }
String FieldVisitorToString::operator() (const UInt64 & x) const { return formatQuoted(x); }
String FieldVisitorToString::operator() (const Int64 & x) const { return formatQuoted(x); }
String FieldVisitorToString::operator() (const Float64 & x) const { return formatFloat(x); }

View File

@ -81,15 +81,15 @@ public:
{
if constexpr (std::is_same_v<T, Null> && std::is_same_v<U, Null>)
{
return l.is_negative_infinity && r.is_positive_infinity;
return l.isNegativeInfinity() && r.isPositiveInfinity();
}
else if constexpr (std::is_same_v<T, Null>)
{
return l.is_negative_infinity;
return l.isNegativeInfinity();
}
else if constexpr (std::is_same_v<U, Null>)
{
return r.is_positive_infinity;
return r.isPositiveInfinity();
}
else
{

View File

@ -486,9 +486,9 @@ template bool decimalLessOrEqual<DateTime64>(DateTime64 x, DateTime64 y, UInt32
inline void writeText(const Null & x, WriteBuffer & buf)
{
if (x.is_negative_infinity)
if (x.isNegativeInfinity())
writeText(std::string("-Inf"), buf);
if (x.is_positive_infinity)
if (x.isPositiveInfinity())
writeText(std::string("+Inf"), buf);
else
writeText(std::string("NULL"), buf);

View File

@ -28,8 +28,8 @@ namespace ErrorCodes
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
constexpr Null NEGATIVE_INFINITY{true, false};
constexpr Null POSITIVE_INFINITY{false, true};
constexpr Null NEGATIVE_INFINITY{Null::Value::NegativeInfinity};
constexpr Null POSITIVE_INFINITY{Null::Value::PositiveInfinity};
class Field;
using FieldVector = std::vector<Field, AllocatorWithMemoryTracking<Field>>;
@ -430,8 +430,8 @@ public:
return mutable_this->get<T>();
}
bool isNegativeInfinity() const { return which == Types::Null && get<Null>().is_negative_infinity; }
bool isPositiveInfinity() const { return which == Types::Null && get<Null>().is_positive_infinity; }
bool isNegativeInfinity() const { return which == Types::Null && get<Null>().isNegativeInfinity(); }
bool isPositiveInfinity() const { return which == Types::Null && get<Null>().isPositiveInfinity(); }
template <typename T>
T & reinterpret();

View File

@ -17,12 +17,22 @@ namespace DB
/// comparison which is used for nullable KeyCondition.
struct Null
{
bool is_negative_infinity = false;
bool is_positive_infinity = false;
enum class Value
{
Null,
PositiveInfinity,
NegativeInfinity,
};
Value value{Value::Null};
bool isNull() const { return value == Value::Null; }
bool isPositiveInfinity() const { return value == Value::PositiveInfinity; }
bool isNegativeInfinity() const { return value == Value::NegativeInfinity; }
bool operator==(const Null & other) const
{
return is_negative_infinity == other.is_negative_infinity && is_positive_infinity == other.is_positive_infinity;
return value == other.value;
}
bool operator!=(const Null & other) const