1#pragma once
2
3#include <DataTypes/DataTypeWithSimpleSerialization.h>
4
5
6namespace DB
7{
8
9
10class DataTypeArray final : public DataTypeWithSimpleSerialization
11{
12private:
13 /// The type of array elements.
14 DataTypePtr nested;
15
16public:
17 static constexpr bool is_parametric = true;
18
19 DataTypeArray(const DataTypePtr & nested_);
20
21 TypeIndex getTypeId() const override { return TypeIndex::Array; }
22
23 std::string doGetName() const override
24 {
25 return "Array(" + nested->getName() + ")";
26 }
27
28 const char * getFamilyName() const override
29 {
30 return "Array";
31 }
32
33 bool canBeInsideNullable() const override
34 {
35 return false;
36 }
37
38 void serializeBinary(const Field & field, WriteBuffer & ostr) const override;
39 void deserializeBinary(Field & field, ReadBuffer & istr) const override;
40 void serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override;
41 void deserializeBinary(IColumn & column, ReadBuffer & istr) const override;
42
43 void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
44 void deserializeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
45
46 void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
47 void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
48
49 void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
50
51 void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
52 void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
53
54 /** Streaming serialization of arrays is arranged in a special way:
55 * - elements placed in a row are written/read without array sizes;
56 * - the sizes are written/read in a separate stream,
57 * This is necessary, because when implementing nested structures, several arrays can have common sizes.
58 */
59
60 void enumerateStreams(const StreamCallback & callback, SubstreamPath & path) const override;
61
62 void serializeBinaryBulkStatePrefix(
63 SerializeBinaryBulkSettings & settings,
64 SerializeBinaryBulkStatePtr & state) const override;
65
66 void serializeBinaryBulkStateSuffix(
67 SerializeBinaryBulkSettings & settings,
68 SerializeBinaryBulkStatePtr & state) const override;
69
70 void deserializeBinaryBulkStatePrefix(
71 DeserializeBinaryBulkSettings & settings,
72 DeserializeBinaryBulkStatePtr & state) const override;
73
74 void serializeBinaryBulkWithMultipleStreams(
75 const IColumn & column,
76 size_t offset,
77 size_t limit,
78 SerializeBinaryBulkSettings & settings,
79 SerializeBinaryBulkStatePtr & state) const override;
80
81 void deserializeBinaryBulkWithMultipleStreams(
82 IColumn & column,
83 size_t limit,
84 DeserializeBinaryBulkSettings & settings,
85 DeserializeBinaryBulkStatePtr & state) const override;
86
87 void serializeProtobuf(const IColumn & column,
88 size_t row_num,
89 ProtobufWriter & protobuf,
90 size_t & value_index) const override;
91 void deserializeProtobuf(IColumn & column,
92 ProtobufReader & protobuf,
93 bool allow_add_row,
94 bool & row_added) const override;
95
96 MutableColumnPtr createColumn() const override;
97
98 Field getDefault() const override;
99
100 bool equals(const IDataType & rhs) const override;
101
102 bool isParametric() const override { return true; }
103 bool haveSubtypes() const override { return true; }
104 bool cannotBeStoredInTables() const override { return nested->cannotBeStoredInTables(); }
105 bool textCanContainOnlyValidUTF8() const override { return nested->textCanContainOnlyValidUTF8(); }
106 bool isComparable() const override { return nested->isComparable(); }
107 bool canBeComparedWithCollation() const override { return nested->canBeComparedWithCollation(); }
108
109 bool isValueUnambiguouslyRepresentedInContiguousMemoryRegion() const override
110 {
111 return nested->isValueUnambiguouslyRepresentedInFixedSizeContiguousMemoryRegion();
112 }
113
114 const DataTypePtr & getNestedType() const { return nested; }
115
116 /// 1 for plain array, 2 for array of arrays and so on.
117 size_t getNumberOfDimensions() const;
118};
119
120}
121