aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/System/StorageSystemModels.cpp
blob: d06f97a3f549848310997eb9078bd33fea5185fc (plain) (blame)
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
#include <Storages/System/StorageSystemModels.h>
#include <Common/ExternalModelInfo.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeEnum.h>
#include <Interpreters/Context.h>
#include <BridgeHelper/CatBoostLibraryBridgeHelper.h>


namespace DB
{

NamesAndTypesList StorageSystemModels::getNamesAndTypes()
{
    return {
        { "model_path", std::make_shared<DataTypeString>() },
        { "type", std::make_shared<DataTypeString>() },
        { "loading_start_time", std::make_shared<DataTypeDateTime>() },
        { "loading_duration", std::make_shared<DataTypeFloat32>() },
    };
}

void StorageSystemModels::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
{
    auto bridge_helper = std::make_unique<CatBoostLibraryBridgeHelper>(context);
    ExternalModelInfos infos = bridge_helper->listModels();

    for (const auto & info : infos)
    {
        res_columns[0]->insert(info.model_path);
        res_columns[1]->insert(info.model_type);
        res_columns[2]->insert(static_cast<UInt64>(std::chrono::system_clock::to_time_t(info.loading_start_time)));
        res_columns[3]->insert(std::chrono::duration_cast<std::chrono::duration<float>>(info.loading_duration).count());
    }
}

}