1 | #pragma once |
2 | |
3 | #include <DataTypes/IDataType.h> |
4 | #include <DataTypes/DataTypeWithSimpleSerialization.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | template <typename T> |
11 | class ColumnVector; |
12 | |
13 | /** Implements part of the IDataType interface, common to all numbers and for Date and DateTime. |
14 | */ |
15 | template <typename T> |
16 | class DataTypeNumberBase : public DataTypeWithSimpleSerialization |
17 | { |
18 | static_assert(IsNumber<T>); |
19 | |
20 | public: |
21 | static constexpr bool is_parametric = false; |
22 | using FieldType = T; |
23 | |
24 | using ColumnType = ColumnVector<T>; |
25 | |
26 | const char * getFamilyName() const override { return TypeName<T>::get(); } |
27 | TypeIndex getTypeId() const override { return TypeId<T>::value; } |
28 | |
29 | void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
30 | void deserializeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override; |
31 | void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override; |
32 | void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override; |
33 | void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override; |
34 | Field getDefault() const override; |
35 | |
36 | /** Format is platform-dependent. */ |
37 | void serializeBinary(const Field & field, WriteBuffer & ostr) const override; |
38 | void deserializeBinary(Field & field, ReadBuffer & istr) const override; |
39 | void serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; |
40 | void deserializeBinary(IColumn & column, ReadBuffer & istr) const override; |
41 | void serializeBinaryBulk(const IColumn & column, WriteBuffer & ostr, size_t offset, size_t limit) const override; |
42 | void deserializeBinaryBulk(IColumn & column, ReadBuffer & istr, size_t limit, double avg_value_size_hint) const override; |
43 | |
44 | void serializeProtobuf(const IColumn & column, size_t row_num, ProtobufWriter & protobuf, size_t & value_index) const override; |
45 | void deserializeProtobuf(IColumn & column, ProtobufReader & protobuf, bool allow_add_row, bool & row_added) const override; |
46 | |
47 | MutableColumnPtr createColumn() const override; |
48 | |
49 | bool isParametric() const override { return false; } |
50 | bool haveSubtypes() const override { return false; } |
51 | bool shouldAlignRightInPrettyFormats() const override { return true; } |
52 | bool textCanContainOnlyValidUTF8() const override { return true; } |
53 | bool isComparable() const override { return true; } |
54 | bool isValueRepresentedByNumber() const override { return true; } |
55 | bool isValueRepresentedByInteger() const override; |
56 | bool isValueRepresentedByUnsignedInteger() const override; |
57 | bool isValueUnambiguouslyRepresentedInContiguousMemoryRegion() const override { return true; } |
58 | bool haveMaximumSizeOfValue() const override { return true; } |
59 | size_t getSizeOfValueInMemory() const override { return sizeof(T); } |
60 | bool isCategorial() const override { return isValueRepresentedByInteger(); } |
61 | bool canBeInsideLowCardinality() const override { return true; } |
62 | }; |
63 | |
64 | } |
65 | |