1 | #include "ExternalResultDescription.h" |
2 | #include <DataTypes/DataTypeDate.h> |
3 | #include <DataTypes/DataTypeDateTime.h> |
4 | #include <DataTypes/DataTypeNullable.h> |
5 | #include <DataTypes/DataTypeString.h> |
6 | #include <DataTypes/DataTypeUUID.h> |
7 | #include <DataTypes/DataTypesNumber.h> |
8 | #include <Common/typeid_cast.h> |
9 | #include <ext/range.h> |
10 | |
11 | |
12 | namespace DB |
13 | { |
14 | namespace ErrorCodes |
15 | { |
16 | extern const int UNKNOWN_TYPE; |
17 | } |
18 | |
19 | void ExternalResultDescription::init(const Block & sample_block_) |
20 | { |
21 | sample_block = sample_block_; |
22 | |
23 | types.reserve(sample_block.columns()); |
24 | |
25 | for (auto & elem : sample_block) |
26 | { |
27 | /// If default value for column was not provided, use default from data type. |
28 | if (elem.column->empty()) |
29 | elem.column = elem.type->createColumnConstWithDefaultValue(1)->convertToFullColumnIfConst(); |
30 | |
31 | bool is_nullable = elem.type->isNullable(); |
32 | DataTypePtr type_not_nullable = removeNullable(elem.type); |
33 | const IDataType * type = type_not_nullable.get(); |
34 | |
35 | if (typeid_cast<const DataTypeUInt8 *>(type)) |
36 | types.emplace_back(ValueType::vtUInt8, is_nullable); |
37 | else if (typeid_cast<const DataTypeUInt16 *>(type)) |
38 | types.emplace_back(ValueType::vtUInt16, is_nullable); |
39 | else if (typeid_cast<const DataTypeUInt32 *>(type)) |
40 | types.emplace_back(ValueType::vtUInt32, is_nullable); |
41 | else if (typeid_cast<const DataTypeUInt64 *>(type)) |
42 | types.emplace_back(ValueType::vtUInt64, is_nullable); |
43 | else if (typeid_cast<const DataTypeInt8 *>(type)) |
44 | types.emplace_back(ValueType::vtInt8, is_nullable); |
45 | else if (typeid_cast<const DataTypeInt16 *>(type)) |
46 | types.emplace_back(ValueType::vtInt16, is_nullable); |
47 | else if (typeid_cast<const DataTypeInt32 *>(type)) |
48 | types.emplace_back(ValueType::vtInt32, is_nullable); |
49 | else if (typeid_cast<const DataTypeInt64 *>(type)) |
50 | types.emplace_back(ValueType::vtInt64, is_nullable); |
51 | else if (typeid_cast<const DataTypeFloat32 *>(type)) |
52 | types.emplace_back(ValueType::vtFloat32, is_nullable); |
53 | else if (typeid_cast<const DataTypeFloat64 *>(type)) |
54 | types.emplace_back(ValueType::vtFloat64, is_nullable); |
55 | else if (typeid_cast<const DataTypeString *>(type)) |
56 | types.emplace_back(ValueType::vtString, is_nullable); |
57 | else if (typeid_cast<const DataTypeDate *>(type)) |
58 | types.emplace_back(ValueType::vtDate, is_nullable); |
59 | else if (typeid_cast<const DataTypeDateTime *>(type)) |
60 | types.emplace_back(ValueType::vtDateTime, is_nullable); |
61 | else if (typeid_cast<const DataTypeUUID *>(type)) |
62 | types.emplace_back(ValueType::vtUUID, is_nullable); |
63 | else |
64 | throw Exception{"Unsupported type " + type->getName(), ErrorCodes::UNKNOWN_TYPE}; |
65 | } |
66 | } |
67 | |
68 | } |
69 | |