| 1 | #include <DataStreams/OneBlockInputStream.h> |
| 2 | #include <Storages/System/StorageSystemDisks.h> |
| 3 | |
| 4 | namespace DB |
| 5 | { |
| 6 | |
| 7 | namespace ErrorCodes |
| 8 | { |
| 9 | } |
| 10 | |
| 11 | |
| 12 | StorageSystemDisks::StorageSystemDisks(const std::string & name_) |
| 13 | : name(name_) |
| 14 | { |
| 15 | setColumns(ColumnsDescription( |
| 16 | { |
| 17 | {"name" , std::make_shared<DataTypeString>()}, |
| 18 | {"path" , std::make_shared<DataTypeString>()}, |
| 19 | {"free_space" , std::make_shared<DataTypeUInt64>()}, |
| 20 | {"total_space" , std::make_shared<DataTypeUInt64>()}, |
| 21 | {"keep_free_space" , std::make_shared<DataTypeUInt64>()}, |
| 22 | })); |
| 23 | } |
| 24 | |
| 25 | BlockInputStreams StorageSystemDisks::read( |
| 26 | const Names & column_names, |
| 27 | const SelectQueryInfo & /*query_info*/, |
| 28 | const Context & context, |
| 29 | QueryProcessingStage::Enum /*processed_stage*/, |
| 30 | const size_t /*max_block_size*/, |
| 31 | const unsigned /*num_streams*/) |
| 32 | { |
| 33 | check(column_names); |
| 34 | |
| 35 | MutableColumnPtr col_name = ColumnString::create(); |
| 36 | MutableColumnPtr col_path = ColumnString::create(); |
| 37 | MutableColumnPtr col_free = ColumnUInt64::create(); |
| 38 | MutableColumnPtr col_total = ColumnUInt64::create(); |
| 39 | MutableColumnPtr col_keep = ColumnUInt64::create(); |
| 40 | |
| 41 | const auto & disk_selector = context.getDiskSelector(); |
| 42 | |
| 43 | for (const auto & [disk_name, disk_ptr] : disk_selector.getDisksMap()) |
| 44 | { |
| 45 | col_name->insert(disk_name); |
| 46 | col_path->insert(disk_ptr->getPath()); |
| 47 | col_free->insert(disk_ptr->getAvailableSpace()); |
| 48 | col_total->insert(disk_ptr->getTotalSpace()); |
| 49 | col_keep->insert(disk_ptr->getKeepingFreeSpace()); |
| 50 | } |
| 51 | |
| 52 | Block res = getSampleBlock().cloneEmpty(); |
| 53 | size_t col_num = 0; |
| 54 | res.getByPosition(col_num++).column = std::move(col_name); |
| 55 | res.getByPosition(col_num++).column = std::move(col_path); |
| 56 | res.getByPosition(col_num++).column = std::move(col_free); |
| 57 | res.getByPosition(col_num++).column = std::move(col_total); |
| 58 | res.getByPosition(col_num++).column = std::move(col_keep); |
| 59 | |
| 60 | return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(res)); |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | |