1 | #include <Columns/ColumnArray.h> |
2 | #include <DataStreams/OneBlockInputStream.h> |
3 | #include <Storages/System/StorageSystemStoragePolicies.h> |
4 | #include <DataTypes/DataTypeArray.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | namespace ErrorCodes |
11 | { |
12 | } |
13 | |
14 | |
15 | StorageSystemStoragePolicies::StorageSystemStoragePolicies(const std::string & name_) |
16 | : name(name_) |
17 | { |
18 | setColumns( |
19 | ColumnsDescription({ |
20 | {"policy_name" , std::make_shared<DataTypeString>()}, |
21 | {"volume_name" , std::make_shared<DataTypeString>()}, |
22 | {"volume_priority" , std::make_shared<DataTypeUInt64>()}, |
23 | {"disks" , std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())}, |
24 | {"max_data_part_size" , std::make_shared<DataTypeUInt64>()}, |
25 | {"move_factor" , std::make_shared<DataTypeFloat32>()} |
26 | })); |
27 | } |
28 | |
29 | BlockInputStreams StorageSystemStoragePolicies::read( |
30 | const Names & column_names, |
31 | const SelectQueryInfo & /*query_info*/, |
32 | const Context & context, |
33 | QueryProcessingStage::Enum /*processed_stage*/, |
34 | const size_t /*max_block_size*/, |
35 | const unsigned /*num_streams*/) |
36 | { |
37 | check(column_names); |
38 | |
39 | MutableColumnPtr col_policy_name = ColumnString::create(); |
40 | MutableColumnPtr col_volume_name = ColumnString::create(); |
41 | MutableColumnPtr col_priority = ColumnUInt64::create(); |
42 | MutableColumnPtr col_disks = ColumnArray::create(ColumnString::create()); |
43 | MutableColumnPtr col_max_part_size = ColumnUInt64::create(); |
44 | MutableColumnPtr col_move_factor = ColumnFloat32::create(); |
45 | |
46 | const auto & policy_selector = context.getStoragePolicySelector(); |
47 | |
48 | for (const auto & [policy_name, policy_ptr] : policy_selector.getPoliciesMap()) |
49 | { |
50 | const auto & volumes = policy_ptr->getVolumes(); |
51 | for (size_t i = 0; i != volumes.size(); ++i) |
52 | { |
53 | col_policy_name->insert(policy_name); |
54 | col_volume_name->insert(volumes[i]->getName()); |
55 | col_priority->insert(i + 1); |
56 | Array disks; |
57 | disks.reserve(volumes[i]->disks.size()); |
58 | for (const auto & disk_ptr : volumes[i]->disks) |
59 | disks.push_back(disk_ptr->getName()); |
60 | col_disks->insert(disks); |
61 | col_max_part_size->insert(volumes[i]->max_data_part_size); |
62 | col_move_factor->insert(policy_ptr->getMoveFactor()); |
63 | } |
64 | } |
65 | |
66 | |
67 | Block res = getSampleBlock().cloneEmpty(); |
68 | |
69 | size_t col_num = 0; |
70 | res.getByPosition(col_num++).column = std::move(col_policy_name); |
71 | res.getByPosition(col_num++).column = std::move(col_volume_name); |
72 | res.getByPosition(col_num++).column = std::move(col_priority); |
73 | res.getByPosition(col_num++).column = std::move(col_disks); |
74 | res.getByPosition(col_num++).column = std::move(col_max_part_size); |
75 | res.getByPosition(col_num++).column = std::move(col_move_factor); |
76 | |
77 | return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(res)); |
78 | } |
79 | |
80 | } |
81 | |