Repository navigation
Expand file tree
/
Copy pathDataTypeArray.cpp
More file actions
118 lines (89 loc) · 3.45 KB
/
Copy pathDataTypeArray.cpp
File metadata and controls
118 lines (89 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <Columns/ColumnArray.h>
#include <Formats/FormatSettings.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeFactory.h>
#include <DataTypes/Serializations/SerializationArray.h>
#include <Parsers/IAST.h>
#include <Common/typeid_cast.h>
#include <Common/assert_cast.h>
#include <Core/NamesAndTypes.h>
#include <Columns/ColumnConst.h>
#include <IO/WriteHelpers.h>
#include <IO/Operators.h>
namespace DB
{
namespace ErrorCodes
{
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
using FieldType = Array;
DataTypeArray::DataTypeArray(const DataTypePtr & nested_)
: nested{nested_}
{
}
MutableColumnPtr DataTypeArray::createColumn() const
{
return ColumnArray::create(nested->createColumn(), ColumnArray::ColumnOffsets::create());
}
Field DataTypeArray::getDefault() const
{
return Array();
}
bool DataTypeArray::equals(const IDataType & rhs) const
{
return typeid(rhs) == typeid(*this) && nested->equals(*static_cast<const DataTypeArray &>(rhs).nested);
}
void DataTypeArray::updateHashImpl(SipHash & hash) const
{
nested->updateHash(hash);
}
SerializationPtr DataTypeArray::doGetDefaultSerialization() const
{
return std::make_shared<SerializationArray>(nested->getDefaultSerialization());
}
size_t DataTypeArray::getNumberOfDimensions() const
{
const DataTypeArray * nested_array = typeid_cast<const DataTypeArray *>(nested.get());
if (!nested_array)
return 1;
return 1 + nested_array->getNumberOfDimensions(); /// Every modern C++ compiler optimizes tail recursion.
}
String DataTypeArray::doGetPrettyName(size_t indent) const
{
WriteBufferFromOwnString s;
s << "Array(" << nested->getPrettyName(indent) << ')';
return s.str();
}
void DataTypeArray::forEachChild(const ChildCallback & callback) const
{
callback(*nested);
nested->forEachChild(callback);
}
std::unique_ptr<ISerialization::SubstreamData> DataTypeArray::getDynamicSubcolumnData(std::string_view subcolumn_name, const DB::IDataType::SubstreamData & data, bool throw_if_null) const
{
auto nested_type = assert_cast<const DataTypeArray &>(*data.type).nested;
auto nested_data = std::make_unique<ISerialization::SubstreamData>(nested_type->getDefaultSerialization());
nested_data->type = nested_type;
nested_data->column = data.column ? assert_cast<const ColumnArray &>(*data.column).getDataPtr() : nullptr;
auto nested_subcolumn_data = DB::IDataType::getSubcolumnData(subcolumn_name, *nested_data, throw_if_null);
if (!nested_subcolumn_data)
return nullptr;
auto creator = SerializationArray::SubcolumnCreator(data.column ? assert_cast<const ColumnArray &>(*data.column).getOffsetsPtr() : nullptr);
auto res = std::make_unique<ISerialization::SubstreamData>();
res->serialization = creator.create(nested_subcolumn_data->serialization, nested_subcolumn_data->type);
res->type = creator.create(nested_subcolumn_data->type);
if (data.column)
res->column = creator.create(nested_subcolumn_data->column);
return res;
}
static DataTypePtr create(const ASTPtr & arguments)
{
if (!arguments || arguments->children.size() != 1)
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Array data type family must have exactly one argument - type of elements");
return std::make_shared<DataTypeArray>(DataTypeFactory::instance().get(arguments->children[0]));
}
void registerDataTypeArray(DataTypeFactory & factory)
{
factory.registerDataType("Array", create);
}
}