| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <type_traits> |
| 4 | #include <Core/Field.h> |
| 5 | #include <DataTypes/DataTypeNumberBase.h> |
| 6 | |
| 7 | |
| 8 | namespace DB |
| 9 | { |
| 10 | |
| 11 | template <typename T> |
| 12 | class DataTypeNumber final : public DataTypeNumberBase<T> |
| 13 | { |
| 14 | bool equals(const IDataType & rhs) const override { return typeid(rhs) == typeid(*this); } |
| 15 | |
| 16 | bool canBeUsedAsVersion() const override { return true; } |
| 17 | bool isSummable() const override { return true; } |
| 18 | bool canBeUsedInBitOperations() const override { return true; } |
| 19 | bool canBeUsedInBooleanContext() const override { return true; } |
| 20 | bool canBeInsideNullable() const override { return true; } |
| 21 | |
| 22 | bool canBePromoted() const override { return true; } |
| 23 | DataTypePtr promoteNumericType() const override |
| 24 | { |
| 25 | using PromotedType = DataTypeNumber<NearestFieldType<T>>; |
| 26 | return std::make_shared<PromotedType>(); |
| 27 | } |
| 28 | |
| 29 | public: |
| 30 | DataTypeNumber(const String & type_name_ = TypeName<T>::get()) : type_name(type_name_) {} |
| 31 | |
| 32 | String doGetName() const override { return type_name; } |
| 33 | private: |
| 34 | const String type_name; |
| 35 | }; |
| 36 | |
| 37 | using DataTypeUInt8 = DataTypeNumber<UInt8>; |
| 38 | using DataTypeUInt16 = DataTypeNumber<UInt16>; |
| 39 | using DataTypeUInt32 = DataTypeNumber<UInt32>; |
| 40 | using DataTypeUInt64 = DataTypeNumber<UInt64>; |
| 41 | using DataTypeInt8 = DataTypeNumber<Int8>; |
| 42 | using DataTypeInt16 = DataTypeNumber<Int16>; |
| 43 | using DataTypeInt32 = DataTypeNumber<Int32>; |
| 44 | using DataTypeInt64 = DataTypeNumber<Int64>; |
| 45 | using DataTypeFloat32 = DataTypeNumber<Float32>; |
| 46 | using DataTypeFloat64 = DataTypeNumber<Float64>; |
| 47 | |
| 48 | } |
| 49 |