2011-08-28 00:31:30 +00:00
|
|
|
#pragma once
|
2010-03-01 16:59:51 +00:00
|
|
|
|
|
|
|
#include <string>
|
2012-10-24 18:14:36 +00:00
|
|
|
#include <vector>
|
2018-07-20 19:05:07 +00:00
|
|
|
#include <cstdint>
|
2010-03-01 16:59:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-09 07:32:32 +00:00
|
|
|
/// Data types for representing elementary values from a database in RAM.
|
2010-03-01 16:59:51 +00:00
|
|
|
|
2017-12-09 07:32:32 +00:00
|
|
|
struct Null {};
|
2010-03-01 16:59:51 +00:00
|
|
|
|
2018-07-20 19:05:07 +00:00
|
|
|
using UInt8 = uint8_t;
|
|
|
|
using UInt16 = uint16_t;
|
|
|
|
using UInt32 = uint32_t;
|
|
|
|
using UInt64 = uint64_t;
|
2010-03-01 16:59:51 +00:00
|
|
|
|
2018-07-20 19:05:07 +00:00
|
|
|
using Int8 = int8_t;
|
|
|
|
using Int16 = int16_t;
|
|
|
|
using Int32 = int32_t;
|
|
|
|
using Int64 = int64_t;
|
2010-03-01 16:59:51 +00:00
|
|
|
|
2016-05-28 10:35:44 +00:00
|
|
|
using Float32 = float;
|
|
|
|
using Float64 = double;
|
2010-03-01 16:59:51 +00:00
|
|
|
|
2016-05-28 10:35:44 +00:00
|
|
|
using String = std::string;
|
2016-08-04 15:06:27 +00:00
|
|
|
|
2011-08-28 00:31:30 +00:00
|
|
|
|
2017-12-09 07:32:32 +00:00
|
|
|
/** Note that for types not used in DB, IsNumber is false.
|
|
|
|
*/
|
2017-12-09 10:19:02 +00:00
|
|
|
template <typename T> constexpr bool IsNumber = false;
|
|
|
|
|
|
|
|
template <> constexpr bool IsNumber<UInt8> = true;
|
|
|
|
template <> constexpr bool IsNumber<UInt16> = true;
|
|
|
|
template <> constexpr bool IsNumber<UInt32> = true;
|
|
|
|
template <> constexpr bool IsNumber<UInt64> = true;
|
|
|
|
template <> constexpr bool IsNumber<Int8> = true;
|
|
|
|
template <> constexpr bool IsNumber<Int16> = true;
|
|
|
|
template <> constexpr bool IsNumber<Int32> = true;
|
|
|
|
template <> constexpr bool IsNumber<Int64> = true;
|
|
|
|
template <> constexpr bool IsNumber<Float32> = true;
|
|
|
|
template <> constexpr bool IsNumber<Float64> = true;
|
2011-08-28 00:31:30 +00:00
|
|
|
|
|
|
|
template <typename T> struct TypeName;
|
|
|
|
|
2017-07-16 03:05:40 +00:00
|
|
|
template <> struct TypeName<UInt8> { static const char * get() { return "UInt8"; } };
|
|
|
|
template <> struct TypeName<UInt16> { static const char * get() { return "UInt16"; } };
|
|
|
|
template <> struct TypeName<UInt32> { static const char * get() { return "UInt32"; } };
|
|
|
|
template <> struct TypeName<UInt64> { static const char * get() { return "UInt64"; } };
|
|
|
|
template <> struct TypeName<Int8> { static const char * get() { return "Int8"; } };
|
|
|
|
template <> struct TypeName<Int16> { static const char * get() { return "Int16"; } };
|
|
|
|
template <> struct TypeName<Int32> { static const char * get() { return "Int32"; } };
|
|
|
|
template <> struct TypeName<Int64> { static const char * get() { return "Int64"; } };
|
|
|
|
template <> struct TypeName<Float32> { static const char * get() { return "Float32"; } };
|
|
|
|
template <> struct TypeName<Float64> { static const char * get() { return "Float64"; } };
|
|
|
|
template <> struct TypeName<String> { static const char * get() { return "String"; } };
|
2015-11-29 08:06:29 +00:00
|
|
|
|
2018-08-20 15:17:55 +00:00
|
|
|
enum class TypeIndex
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
UInt8,
|
|
|
|
UInt16,
|
|
|
|
UInt32,
|
|
|
|
UInt64,
|
|
|
|
UInt128,
|
|
|
|
Int8,
|
|
|
|
Int16,
|
|
|
|
Int32,
|
|
|
|
Int64,
|
|
|
|
Int128,
|
|
|
|
Float32,
|
|
|
|
Float64,
|
|
|
|
Date,
|
|
|
|
DateTime,
|
|
|
|
String,
|
|
|
|
FixedString,
|
|
|
|
Enum8,
|
|
|
|
Enum16,
|
|
|
|
Dec32,
|
|
|
|
Dec64,
|
|
|
|
Dec128,
|
|
|
|
UUID,
|
|
|
|
};
|
2018-07-26 15:28:14 +00:00
|
|
|
|
2018-08-20 15:17:55 +00:00
|
|
|
template <typename T> struct TypeId;
|
|
|
|
template <> struct TypeId<UInt8> { static constexpr const TypeIndex value = TypeIndex::UInt8; };
|
|
|
|
template <> struct TypeId<UInt16> { static constexpr const TypeIndex value = TypeIndex::UInt16; };
|
|
|
|
template <> struct TypeId<UInt32> { static constexpr const TypeIndex value = TypeIndex::UInt32; };
|
|
|
|
template <> struct TypeId<UInt64> { static constexpr const TypeIndex value = TypeIndex::UInt64; };
|
|
|
|
template <> struct TypeId<Int8> { static constexpr const TypeIndex value = TypeIndex::Int8; };
|
|
|
|
template <> struct TypeId<Int16> { static constexpr const TypeIndex value = TypeIndex::Int16; };
|
|
|
|
template <> struct TypeId<Int32> { static constexpr const TypeIndex value = TypeIndex::Int32; };
|
|
|
|
template <> struct TypeId<Int64> { static constexpr const TypeIndex value = TypeIndex::Int64; };
|
|
|
|
template <> struct TypeId<Float32> { static constexpr const TypeIndex value = TypeIndex::Float32; };
|
|
|
|
template <> struct TypeId<Float64> { static constexpr const TypeIndex value = TypeIndex::Float64; };
|
2017-10-14 04:39:14 +00:00
|
|
|
|
2017-12-09 07:32:32 +00:00
|
|
|
/// Not a data type in database, defined just for convenience.
|
|
|
|
using Strings = std::vector<String>;
|
|
|
|
|
2011-08-28 00:31:30 +00:00
|
|
|
}
|
2018-07-25 19:38:21 +00:00
|
|
|
|
|
|
|
#if 1 /// __int128
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
using Int128 = __int128;
|
|
|
|
template <> constexpr bool IsNumber<Int128> = true;
|
|
|
|
template <> struct TypeName<Int128> { static const char * get() { return "Int128"; } };
|
2018-08-20 15:17:55 +00:00
|
|
|
template <> struct TypeId<Int128> { static constexpr const TypeIndex value = TypeIndex::Int128; };
|
2018-07-25 19:38:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <> struct is_signed<__int128>
|
|
|
|
{
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct is_unsigned<__int128>
|
|
|
|
{
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct is_integral<__int128>
|
|
|
|
{
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct is_arithmetic<__int128>
|
|
|
|
{
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2018-08-07 13:57:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/// Own FieldType for Decimal
|
|
|
|
template <typename T>
|
2018-08-15 13:27:22 +00:00
|
|
|
struct Dec
|
2018-08-07 13:57:28 +00:00
|
|
|
{
|
|
|
|
using NativeType = T;
|
|
|
|
|
|
|
|
Dec() = default;
|
|
|
|
Dec(Dec<T> &&) = default;
|
|
|
|
Dec(const Dec<T> &) = default;
|
|
|
|
|
|
|
|
Dec(const T & value_)
|
|
|
|
: value(value_)
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
Dec(const Dec<U> & x)
|
|
|
|
: value(x)
|
|
|
|
{}
|
|
|
|
|
|
|
|
constexpr Dec<T> & operator = (Dec<T> &&) = default;
|
|
|
|
constexpr Dec<T> & operator = (const Dec<T> &) = default;
|
|
|
|
|
|
|
|
operator T () const { return value; }
|
|
|
|
|
|
|
|
const Dec<T> & operator += (const T & x) { value += x; return *this; }
|
|
|
|
const Dec<T> & operator -= (const T & x) { value -= x; return *this; }
|
|
|
|
const Dec<T> & operator *= (const T & x) { value *= x; return *this; }
|
|
|
|
const Dec<T> & operator /= (const T & x) { value /= x; return *this; }
|
|
|
|
const Dec<T> & operator %= (const T & x) { value %= x; return *this; }
|
|
|
|
|
|
|
|
T value;
|
|
|
|
};
|
|
|
|
|
|
|
|
using Dec32 = Dec<Int32>;
|
|
|
|
using Dec64 = Dec<Int64>;
|
|
|
|
using Dec128 = Dec<Int128>;
|
|
|
|
|
|
|
|
template <> struct TypeName<Dec32> { static const char * get() { return "Dec32"; } };
|
|
|
|
template <> struct TypeName<Dec64> { static const char * get() { return "Dec64"; } };
|
|
|
|
template <> struct TypeName<Dec128> { static const char * get() { return "Dec128"; } };
|
|
|
|
|
2018-08-20 15:17:55 +00:00
|
|
|
template <> struct TypeId<Dec32> { static constexpr const TypeIndex value = TypeIndex::Dec32; };
|
|
|
|
template <> struct TypeId<Dec64> { static constexpr const TypeIndex value = TypeIndex::Dec64; };
|
|
|
|
template <> struct TypeId<Dec128> { static constexpr const TypeIndex value = TypeIndex::Dec128; };
|
2018-08-08 10:36:03 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline constexpr bool decTrait() { return false; }
|
|
|
|
template <> constexpr bool decTrait<Dec32>() { return true; }
|
|
|
|
template <> constexpr bool decTrait<Dec64>() { return true; }
|
|
|
|
template <> constexpr bool decTrait<Dec128>() { return true; }
|
2018-08-07 13:57:28 +00:00
|
|
|
}
|