2017-05-23 18:01:50 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterCheckQuery.h>
|
2020-01-26 09:49:53 +00:00
|
|
|
#include <Access/AccessFlags.h>
|
2018-08-05 06:01:41 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTCheckQuery.h>
|
2021-09-15 19:35:48 +00:00
|
|
|
#include <Processors/Sources/SourceFromSingleChunk.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2019-07-03 13:17:19 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2019-07-16 10:19:37 +00:00
|
|
|
#include <algorithm>
|
2015-10-12 14:53:16 +00:00
|
|
|
|
2014-08-05 10:52:06 +00:00
|
|
|
|
2015-06-18 02:11:05 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2014-08-05 10:52:06 +00:00
|
|
|
|
2019-07-03 13:17:19 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
NamesAndTypes getBlockStructure()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
{"part_path", std::make_shared<DataTypeString>()},
|
|
|
|
{"is_passed", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"message", std::make_shared<DataTypeString>()},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
InterpreterCheckQuery::InterpreterCheckQuery(const ASTPtr & query_ptr_, ContextPtr context_) : WithContext(context_), query_ptr(query_ptr_)
|
2015-10-12 14:53:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 02:11:05 +00:00
|
|
|
BlockIO InterpreterCheckQuery::execute()
|
2014-08-05 10:52:06 +00:00
|
|
|
{
|
2019-07-03 13:17:19 +00:00
|
|
|
const auto & check = query_ptr->as<ASTCheckQuery &>();
|
2021-04-10 23:33:54 +00:00
|
|
|
auto table_id = getContext()->resolveStorageID(check, Context::ResolveOrdinary);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
getContext()->checkAccess(AccessType::SHOW_TABLES, table_id);
|
|
|
|
StoragePtr table = DatabaseCatalog::instance().getTable(table_id, getContext());
|
|
|
|
auto check_results = table->checkData(query_ptr, getContext());
|
2019-07-03 13:17:19 +00:00
|
|
|
|
2019-07-16 10:19:37 +00:00
|
|
|
Block block;
|
2021-04-10 23:33:54 +00:00
|
|
|
if (getContext()->getSettingsRef().check_query_single_value_result)
|
2019-07-03 13:17:19 +00:00
|
|
|
{
|
2019-07-16 10:50:59 +00:00
|
|
|
bool result = std::all_of(check_results.begin(), check_results.end(), [] (const CheckResult & res) { return res.success; });
|
2019-07-16 10:19:37 +00:00
|
|
|
auto column = ColumnUInt8::create();
|
|
|
|
column->insertValue(UInt64(result));
|
|
|
|
block = Block{{std::move(column), std::make_shared<DataTypeUInt8>(), "result"}};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto block_structure = getBlockStructure();
|
|
|
|
auto path_column = block_structure[0].type->createColumn();
|
|
|
|
auto is_passed_column = block_structure[1].type->createColumn();
|
|
|
|
auto message_column = block_structure[2].type->createColumn();
|
|
|
|
|
|
|
|
for (const auto & check_result : check_results)
|
|
|
|
{
|
|
|
|
path_column->insert(check_result.fs_path);
|
|
|
|
is_passed_column->insert(static_cast<UInt8>(check_result.success));
|
|
|
|
message_column->insert(check_result.failure_message);
|
|
|
|
}
|
|
|
|
|
|
|
|
block = Block({
|
|
|
|
{std::move(path_column), block_structure[0].type, block_structure[0].name},
|
|
|
|
{std::move(is_passed_column), block_structure[1].type, block_structure[1].name},
|
|
|
|
{std::move(message_column), block_structure[2].type, block_structure[2].name}});
|
2019-07-03 13:17:19 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-08-05 06:01:41 +00:00
|
|
|
BlockIO res;
|
2021-09-15 19:35:48 +00:00
|
|
|
res.pipeline = QueryPipeline(std::make_shared<SourceFromSingleChunk>(std::move(block)));
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-08-05 06:01:41 +00:00
|
|
|
return res;
|
2014-08-05 10:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|