1 | #include <Storages/System/StorageSystemModels.h> |
2 | #include <DataTypes/DataTypeString.h> |
3 | #include <DataTypes/DataTypesNumber.h> |
4 | #include <DataTypes/DataTypeDateTime.h> |
5 | #include <DataTypes/DataTypeEnum.h> |
6 | #include <Interpreters/Context.h> |
7 | #include <Interpreters/ExternalModelsLoader.h> |
8 | #include <Interpreters/CatBoostModel.h> |
9 | |
10 | |
11 | namespace DB |
12 | { |
13 | |
14 | NamesAndTypesList StorageSystemModels::getNamesAndTypes() |
15 | { |
16 | return { |
17 | { "name" , std::make_shared<DataTypeString>() }, |
18 | { "status" , std::make_shared<DataTypeEnum8>(ExternalLoader::getStatusEnumAllPossibleValues()) }, |
19 | { "origin" , std::make_shared<DataTypeString>() }, |
20 | { "type" , std::make_shared<DataTypeString>() }, |
21 | { "loading_start_time" , std::make_shared<DataTypeDateTime>() }, |
22 | { "loading_duration" , std::make_shared<DataTypeFloat32>() }, |
23 | //{ "creation_time", std::make_shared<DataTypeDateTime>() }, |
24 | { "last_exception" , std::make_shared<DataTypeString>() }, |
25 | }; |
26 | } |
27 | |
28 | void StorageSystemModels::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const |
29 | { |
30 | const auto & external_models_loader = context.getExternalModelsLoader(); |
31 | auto load_results = external_models_loader.getCurrentLoadResults(); |
32 | |
33 | for (const auto & load_result : load_results) |
34 | { |
35 | res_columns[0]->insert(load_result.name); |
36 | res_columns[1]->insert(static_cast<Int8>(load_result.status)); |
37 | res_columns[2]->insert(load_result.origin); |
38 | |
39 | if (load_result.object) |
40 | { |
41 | const auto model_ptr = std::static_pointer_cast<const IModel>(load_result.object); |
42 | res_columns[3]->insert(model_ptr->getTypeName()); |
43 | } |
44 | else |
45 | { |
46 | res_columns[3]->insertDefault(); |
47 | } |
48 | |
49 | res_columns[4]->insert(static_cast<UInt64>(std::chrono::system_clock::to_time_t(load_result.loading_start_time))); |
50 | res_columns[5]->insert(std::chrono::duration_cast<std::chrono::duration<float>>(load_result.loading_duration).count()); |
51 | |
52 | if (load_result.exception) |
53 | res_columns[6]->insert(getExceptionMessage(load_result.exception, false)); |
54 | else |
55 | res_columns[6]->insertDefault(); |
56 | } |
57 | } |
58 | |
59 | } |
60 | |