2017-03-12 10:13:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
#include <type_traits>
|
2019-10-04 17:46:36 +00:00
|
|
|
#include <Core/Field.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeNumberBase.h>
|
2021-03-09 14:10:28 +00:00
|
|
|
#include <DataTypes/Serializations/SerializationNumber.h>
|
2017-03-12 10:13:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2023-09-12 18:06:57 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-03-12 10:13:45 +00:00
|
|
|
template <typename T>
|
2023-09-12 18:19:36 +00:00
|
|
|
class DataTypeNumber final : public DataTypeNumberBase<T>
|
2017-03-12 10:13:45 +00:00
|
|
|
{
|
2022-01-16 11:45:36 +00:00
|
|
|
public:
|
2023-09-12 18:06:57 +00:00
|
|
|
DataTypeNumber() = default;
|
|
|
|
|
2017-12-23 01:05:29 +00:00
|
|
|
bool equals(const IDataType & rhs) const override { return typeid(rhs) == typeid(*this); }
|
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
bool canBeUsedAsVersion() const override { return true; }
|
|
|
|
bool isSummable() const override { return true; }
|
|
|
|
bool canBeUsedInBitOperations() const override { return true; }
|
|
|
|
bool canBeUsedInBooleanContext() const override { return true; }
|
|
|
|
bool canBeInsideNullable() const override { return true; }
|
2019-01-25 13:06:21 +00:00
|
|
|
|
2019-01-25 14:16:23 +00:00
|
|
|
bool canBePromoted() const override { return true; }
|
|
|
|
DataTypePtr promoteNumericType() const override
|
2019-01-25 13:06:21 +00:00
|
|
|
{
|
2019-01-25 14:16:23 +00:00
|
|
|
using PromotedType = DataTypeNumber<NearestFieldType<T>>;
|
|
|
|
return std::make_shared<PromotedType>();
|
2019-01-25 13:06:21 +00:00
|
|
|
}
|
2021-03-09 14:10:28 +00:00
|
|
|
|
|
|
|
SerializationPtr doGetDefaultSerialization() const override
|
|
|
|
{
|
|
|
|
return std::make_shared<SerializationNumber<T>>();
|
|
|
|
}
|
2023-09-12 18:06:57 +00:00
|
|
|
|
|
|
|
/// Special constructor for unsigned integers that can also fit into signed integer.
|
|
|
|
/// It's used for better type inference from fields.
|
|
|
|
/// See getLeastSupertype.cpp::convertUInt64toInt64IfPossible and FieldToDataType.cpp
|
|
|
|
explicit DataTypeNumber(bool unsigned_can_be_signed_) : DataTypeNumberBase<T>(), unsigned_can_be_signed(unsigned_can_be_signed_)
|
|
|
|
{
|
|
|
|
if constexpr (std::is_signed_v<T>)
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "DataTypeNumber constructor with bool argument should not be used with signed integers");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canUnsignedBeSigned() const { return unsigned_can_be_signed; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool unsigned_can_be_signed = false;
|
2017-03-12 10:13:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using DataTypeUInt8 = DataTypeNumber<UInt8>;
|
|
|
|
using DataTypeUInt16 = DataTypeNumber<UInt16>;
|
|
|
|
using DataTypeUInt32 = DataTypeNumber<UInt32>;
|
|
|
|
using DataTypeUInt64 = DataTypeNumber<UInt64>;
|
|
|
|
using DataTypeInt8 = DataTypeNumber<Int8>;
|
|
|
|
using DataTypeInt16 = DataTypeNumber<Int16>;
|
|
|
|
using DataTypeInt32 = DataTypeNumber<Int32>;
|
|
|
|
using DataTypeInt64 = DataTypeNumber<Int64>;
|
|
|
|
using DataTypeFloat32 = DataTypeNumber<Float32>;
|
|
|
|
using DataTypeFloat64 = DataTypeNumber<Float64>;
|
|
|
|
|
2021-05-03 15:20:12 +00:00
|
|
|
using DataTypeUInt128 = DataTypeNumber<UInt128>;
|
2020-08-19 11:52:17 +00:00
|
|
|
using DataTypeInt128 = DataTypeNumber<Int128>;
|
2020-09-01 09:54:50 +00:00
|
|
|
using DataTypeUInt256 = DataTypeNumber<UInt256>;
|
|
|
|
using DataTypeInt256 = DataTypeNumber<Int256>;
|
2020-08-19 11:52:17 +00:00
|
|
|
|
2023-09-15 12:53:50 +00:00
|
|
|
bool isUInt64ThatCanBeInt64(const DataTypePtr & type);
|
|
|
|
|
2017-03-12 10:13:45 +00:00
|
|
|
}
|