1 | #pragma once |
2 | |
3 | #include <DataTypes/IDataType.h> |
4 | |
5 | #define MAX_FIXEDSTRING_SIZE 0xFFFFFF |
6 | |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | namespace ErrorCodes |
12 | { |
13 | extern const int ARGUMENT_OUT_OF_BOUND; |
14 | } |
15 | |
16 | |
17 | class DataTypeFixedString final : public IDataType |
18 | { |
19 | private: |
20 | size_t n; |
21 | |
22 | public: |
23 | static constexpr bool is_parametric = true; |
24 | |
25 | DataTypeFixedString(size_t n_, const String & type_name_ = "FixedString" ) : n(n_), type_name(type_name_) |
26 | { |
27 | if (n == 0) |
28 | throw Exception("FixedString size must be positive" , ErrorCodes::ARGUMENT_OUT_OF_BOUND); |
29 | if (n > MAX_FIXEDSTRING_SIZE) |
30 | throw Exception("FixedString size is too large" , ErrorCodes::ARGUMENT_OUT_OF_BOUND); |
31 | } |
32 | |
33 | std::string doGetName() const override; |
34 | TypeIndex getTypeId() const override { return TypeIndex::FixedString; } |
35 | |
36 | const char * getFamilyName() const override { return "FixedString" ; } |
37 | |
38 | size_t getN() const |
39 | { |
40 | return n; |
41 | } |
42 | |
43 | void serializeBinary(const Field & field, WriteBuffer & ostr) const override; |
44 | void deserializeBinary(Field & field, ReadBuffer & istr) const override; |
45 | void serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override; |
46 | void deserializeBinary(IColumn & column, ReadBuffer & istr) const override; |
47 | |
48 | void serializeBinaryBulk(const IColumn & column, WriteBuffer & ostr, size_t offset, size_t limit) const override; |
49 | void deserializeBinaryBulk(IColumn & column, ReadBuffer & istr, size_t limit, double avg_value_size_hint) const override; |
50 | |
51 | void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
52 | |
53 | void deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override; |
54 | |
55 | void serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
56 | void deserializeTextEscaped(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override; |
57 | |
58 | void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
59 | void deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override; |
60 | |
61 | void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
62 | void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override; |
63 | |
64 | void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
65 | |
66 | void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override; |
67 | void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override; |
68 | |
69 | void serializeProtobuf(const IColumn & column, size_t row_num, ProtobufWriter & protobuf, size_t & value_index) const override; |
70 | void deserializeProtobuf(IColumn & column, ProtobufReader & protobuf, bool allow_add_row, bool & row_added) const override; |
71 | |
72 | MutableColumnPtr createColumn() const override; |
73 | |
74 | Field getDefault() const override; |
75 | |
76 | bool equals(const IDataType & rhs) const override; |
77 | |
78 | bool isParametric() const override { return true; } |
79 | bool haveSubtypes() const override { return false; } |
80 | bool isComparable() const override { return true; } |
81 | bool isValueUnambiguouslyRepresentedInContiguousMemoryRegion() const override { return true; } |
82 | bool isValueUnambiguouslyRepresentedInFixedSizeContiguousMemoryRegion() const override { return true; } |
83 | bool haveMaximumSizeOfValue() const override { return true; } |
84 | size_t getSizeOfValueInMemory() const override { return n; } |
85 | bool isCategorial() const override { return true; } |
86 | bool canBeInsideNullable() const override { return true; } |
87 | bool canBeInsideLowCardinality() const override { return true; } |
88 | |
89 | private: |
90 | const String type_name; |
91 | }; |
92 | |
93 | } |
94 | |