| 35 | |
| 36 | |
| 37 | BlockIO InterpreterCheckQuery::execute() |
| 38 | { |
| 39 | const auto & check = query_ptr->as<ASTCheckQuery &>(); |
| 40 | auto table_id = getContext()->resolveStorageID(check, Context::ResolveOrdinary); |
| 41 | |
| 42 | getContext()->checkAccess(AccessType::SHOW_TABLES, table_id); |
| 43 | StoragePtr table = DatabaseCatalog::instance().getTable(table_id, getContext()); |
| 44 | |
| 45 | CheckResults check_results; |
| 46 | if (check.auto_remove) |
| 47 | check_results = table->autoRemoveData(query_ptr, getContext()); |
| 48 | else |
| 49 | check_results = table->checkData(query_ptr, getContext()); |
| 50 | |
| 51 | Block block; |
| 52 | if (getContext()->getSettingsRef().check_query_single_value_result) |
| 53 | { |
| 54 | bool result = std::all_of(check_results.begin(), check_results.end(), [] (const CheckResult & res) { return res.success; }); |
| 55 | auto column = ColumnUInt8::create(); |
| 56 | column->insertValue(UInt64(result)); |
| 57 | block = Block{{std::move(column), std::make_shared<DataTypeUInt8>(), "result"}}; |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | auto block_structure = getBlockStructure(); |
| 62 | auto path_column = block_structure[0].type->createColumn(); |
| 63 | auto is_passed_column = block_structure[1].type->createColumn(); |
| 64 | auto message_column = block_structure[2].type->createColumn(); |
| 65 | |
| 66 | for (const auto & check_result : check_results) |
| 67 | { |
| 68 | path_column->insert(check_result.fs_path); |
| 69 | is_passed_column->insert(static_cast<UInt8>(check_result.success)); |
| 70 | message_column->insert(check_result.failure_message); |
| 71 | } |
| 72 | |
| 73 | block = Block({ |
| 74 | {std::move(path_column), block_structure[0].type, block_structure[0].name}, |
| 75 | {std::move(is_passed_column), block_structure[1].type, block_structure[1].name}, |
| 76 | {std::move(message_column), block_structure[2].type, block_structure[2].name}}); |
| 77 | } |
| 78 | |
| 79 | BlockIO res; |
| 80 | res.in = std::make_shared<OneBlockInputStream>(block); |
| 81 | |
| 82 | return res; |
| 83 | } |
| 84 | |
| 85 | } |
nothing calls this directly
no test coverage detected