forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExternalResultDescription.cpp
More file actions
130 lines (118 loc) · 5.28 KB
/
Copy pathExternalResultDescription.cpp
File metadata and controls
130 lines (118 loc) · 5.28 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
119
120
121
122
123
124
125
126
127
128
129
130
#include <Core/ExternalResultDescription.h>
#include <Columns/ColumnConst.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeTime.h>
#include <DataTypes/DataTypeTime64.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeFixedString.h>
#include <DataTypes/DataTypeUUID.h>
#include <DataTypes/DataTypesDecimal.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeEnum.h>
#include <DataTypes/DataTypeCustomGeo.h>
#include <Common/typeid_cast.h>
#include <Common/logger_useful.h>
namespace DB
{
namespace ErrorCodes
{
extern const int UNKNOWN_TYPE;
}
ExternalResultDescription::ExternalResultDescription(const Block & sample_block_)
{
init(sample_block_);
}
void ExternalResultDescription::init(const Block & sample_block_)
{
sample_block = sample_block_;
types.reserve(sample_block.columns());
for (auto & elem : sample_block)
{
/// If default value for column was not provided, use default from data type.
if (elem.column->empty())
elem.column = elem.type->createColumnConstWithDefaultValue(1)->convertToFullColumnIfConst();
bool is_nullable = elem.type->isNullable();
DataTypePtr type_not_nullable = removeNullable(elem.type);
const IDataType * type = type_not_nullable.get();
if (dynamic_cast<const DataTypePointName *>(type->getCustomName()))
{
types.emplace_back(ValueType::vtPoint, is_nullable);
continue;
}
/// All the other geometric types (including the umbrella `Geometry` type) are read from a
/// WKB representation, see `vtGeometry` in `MySQLSource`.
if (dynamic_cast<const DataTypeMultiPointName *>(type->getCustomName())
|| dynamic_cast<const DataTypeLineStringName *>(type->getCustomName())
|| dynamic_cast<const DataTypeMultiLineStringName *>(type->getCustomName())
|| dynamic_cast<const DataTypeRingName *>(type->getCustomName())
|| dynamic_cast<const DataTypePolygonName *>(type->getCustomName())
|| dynamic_cast<const DataTypeMultiPolygonName *>(type->getCustomName())
|| dynamic_cast<const DataTypeGeometryName *>(type->getCustomName()))
{
types.emplace_back(ValueType::vtGeometry, is_nullable);
continue;
}
WhichDataType which(type);
if (which.isUInt8())
types.emplace_back(ValueType::vtUInt8, is_nullable);
else if (which.isUInt16())
types.emplace_back(ValueType::vtUInt16, is_nullable);
else if (which.isUInt32())
types.emplace_back(ValueType::vtUInt32, is_nullable);
else if (which.isUInt64())
types.emplace_back(ValueType::vtUInt64, is_nullable);
else if (which.isInt8())
types.emplace_back(ValueType::vtInt8, is_nullable);
else if (which.isInt16())
types.emplace_back(ValueType::vtInt16, is_nullable);
else if (which.isInt32())
types.emplace_back(ValueType::vtInt32, is_nullable);
else if (which.isInt64())
types.emplace_back(ValueType::vtInt64, is_nullable);
else if (which.isInt256())
types.emplace_back(ValueType::vtInt256, is_nullable);
else if (which.isFloat32())
types.emplace_back(ValueType::vtFloat32, is_nullable);
else if (which.isFloat64())
types.emplace_back(ValueType::vtFloat64, is_nullable);
else if (which.isString())
types.emplace_back(ValueType::vtString, is_nullable);
else if (which.isDate())
types.emplace_back(ValueType::vtDate, is_nullable);
else if (which.isDate32())
types.emplace_back(ValueType::vtDate32, is_nullable);
else if (which.isDateTime())
types.emplace_back(ValueType::vtDateTime, is_nullable);
else if (which.isUUID())
types.emplace_back(ValueType::vtUUID, is_nullable);
else if (which.isEnum8())
types.emplace_back(ValueType::vtEnum8, is_nullable);
else if (which.isEnum16())
types.emplace_back(ValueType::vtEnum16, is_nullable);
else if (which.isDateTime64())
types.emplace_back(ValueType::vtDateTime64, is_nullable);
else if (which.isTime())
types.emplace_back(ValueType::vtTime, is_nullable);
else if (which.isTime64())
types.emplace_back(ValueType::vtTime64, is_nullable);
else if (which.isDecimal32())
types.emplace_back(ValueType::vtDecimal32, is_nullable);
else if (which.isDecimal64())
types.emplace_back(ValueType::vtDecimal64, is_nullable);
else if (which.isDecimal128())
types.emplace_back(ValueType::vtDecimal128, is_nullable);
else if (which.isDecimal256())
types.emplace_back(ValueType::vtDecimal256, is_nullable);
else if (which.isArray())
types.emplace_back(ValueType::vtArray, is_nullable);
else if (which.isFixedString())
types.emplace_back(ValueType::vtFixedString, is_nullable);
else
throw Exception(ErrorCodes::UNKNOWN_TYPE, "Unsupported type {}", type->getName());
}
}
}