#pragma once #include #include #include #include namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; } template class DataTypeNumber final : public DataTypeNumberBase { public: DataTypeNumber() = default; bool equals(const IDataType & rhs) const override { return typeid(rhs) == typeid(*this); } 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; } bool canBePromoted() const override { return true; } DataTypePtr promoteNumericType() const override { using PromotedType = DataTypeNumber>; return std::make_shared(); } SerializationPtr doGetDefaultSerialization() const override { return std::make_shared>(); } /// 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(), unsigned_can_be_signed(unsigned_can_be_signed_) { if constexpr (std::is_signed_v) 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; }; using DataTypeUInt8 = DataTypeNumber; using DataTypeUInt16 = DataTypeNumber; using DataTypeUInt32 = DataTypeNumber; using DataTypeUInt64 = DataTypeNumber; using DataTypeInt8 = DataTypeNumber; using DataTypeInt16 = DataTypeNumber; using DataTypeInt32 = DataTypeNumber; using DataTypeInt64 = DataTypeNumber; using DataTypeFloat32 = DataTypeNumber; using DataTypeFloat64 = DataTypeNumber; using DataTypeUInt128 = DataTypeNumber; using DataTypeInt128 = DataTypeNumber; using DataTypeUInt256 = DataTypeNumber; using DataTypeInt256 = DataTypeNumber; bool isUInt64ThatCanBeInt64(const DataTypePtr & type); }