2024-01-09 06:33:48 +00:00
|
|
|
#include <Interpreters/InterpreterFactory.h>
|
2021-08-18 22:19:14 +00:00
|
|
|
#include <Interpreters/InterpreterBackupQuery.h>
|
2022-05-02 17:09:51 +00:00
|
|
|
|
2022-04-20 07:38:12 +00:00
|
|
|
#include <Backups/BackupsWorker.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
2022-05-02 17:09:51 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
2022-04-20 07:38:12 +00:00
|
|
|
#include <DataTypes/DataTypeEnum.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2022-05-02 17:09:51 +00:00
|
|
|
#include <DataTypes/DataTypeUUID.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2022-04-20 07:38:12 +00:00
|
|
|
#include <Processors/Sources/SourceFromSingleChunk.h>
|
2022-04-29 06:45:27 +00:00
|
|
|
#include <Common/logger_useful.h>
|
2021-08-18 22:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-01-28 17:33:35 +00:00
|
|
|
|
2022-05-01 13:36:32 +00:00
|
|
|
namespace
|
|
|
|
{
|
2023-08-10 10:29:20 +00:00
|
|
|
Block getResultRow(const BackupOperationInfo & info)
|
2021-08-18 22:19:14 +00:00
|
|
|
{
|
2022-07-22 16:01:24 +00:00
|
|
|
auto column_id = ColumnString::create();
|
2022-04-20 07:38:12 +00:00
|
|
|
auto column_status = ColumnInt8::create();
|
2022-07-20 19:44:51 +00:00
|
|
|
|
2022-07-22 16:01:24 +00:00
|
|
|
column_id->insert(info.id);
|
2022-07-26 09:17:08 +00:00
|
|
|
column_status->insert(static_cast<Int8>(info.status));
|
2022-07-20 19:44:51 +00:00
|
|
|
|
|
|
|
Block res_columns;
|
2022-07-22 16:01:24 +00:00
|
|
|
res_columns.insert(0, {std::move(column_id), std::make_shared<DataTypeString>(), "id"});
|
2022-07-22 09:05:10 +00:00
|
|
|
res_columns.insert(1, {std::move(column_status), std::make_shared<DataTypeEnum8>(getBackupStatusEnumValues()), "status"});
|
2022-04-20 07:38:12 +00:00
|
|
|
|
|
|
|
return res_columns;
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockIO InterpreterBackupQuery::execute()
|
|
|
|
{
|
2022-05-02 17:09:51 +00:00
|
|
|
auto & backups_worker = context->getBackupsWorker();
|
2022-07-22 16:01:24 +00:00
|
|
|
auto id = backups_worker.start(query_ptr, context);
|
2022-07-22 09:05:10 +00:00
|
|
|
|
2022-07-22 16:01:24 +00:00
|
|
|
auto info = backups_worker.getInfo(id);
|
2022-07-22 09:05:10 +00:00
|
|
|
if (info.exception)
|
|
|
|
std::rethrow_exception(info.exception);
|
|
|
|
|
2022-04-20 07:38:12 +00:00
|
|
|
BlockIO res_io;
|
2022-07-22 09:05:10 +00:00
|
|
|
res_io.pipeline = QueryPipeline(std::make_shared<SourceFromSingleChunk>(getResultRow(info)));
|
2022-04-20 07:38:12 +00:00
|
|
|
return res_io;
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|
|
|
|
|
2024-01-09 06:33:48 +00:00
|
|
|
void registerInterpreterBackupQuery(InterpreterFactory & factory)
|
|
|
|
{
|
|
|
|
auto create_fn = [] (const InterpreterFactory::Arguments & args)
|
|
|
|
{
|
|
|
|
return std::make_unique<InterpreterBackupQuery>(args.query, args.context);
|
|
|
|
};
|
|
|
|
factory.registerInterpreter("InterpreterBackupQuery", create_fn);
|
|
|
|
}
|
|
|
|
|
2021-08-18 22:19:14 +00:00
|
|
|
}
|