| 29 | } |
| 30 | |
| 31 | BlockIO InterpreterRefreshQuery::execute() |
| 32 | { |
| 33 | const auto & refresh = query_ptr->as<ASTRefreshQuery &>(); |
| 34 | if (refresh.settings_ast) |
| 35 | InterpreterSetQuery(refresh.settings_ast, getContext()).executeForCurrentContext(); |
| 36 | auto database = refresh.database.empty() ? getContext()->getCurrentDatabase() : refresh.database; |
| 37 | StoragePtr storage_ptr = DatabaseCatalog::instance().getTable({database, refresh.table}, getContext()); |
| 38 | if (auto * view = dynamic_cast<StorageMaterializedView *>(storage_ptr.get())) |
| 39 | { |
| 40 | if (view->async()) |
| 41 | { |
| 42 | if (getContext()->getSettingsRef().async_mv_refresh_task_submit_to_bg_thread) |
| 43 | { |
| 44 | auto bg_thread = getContext()->tryGetCnchBGThread(CnchBGThreadType::CnchRefreshMaterializedView, view->getStorageID()); |
| 45 | if (bg_thread) |
| 46 | { |
| 47 | auto * refresh_thread = dynamic_cast<CnchRefreshMaterializedViewThread *>(bg_thread.get()); |
| 48 | refresh_thread->start(); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | AsyncRefreshParamPtrs refersh_params = view->getAsyncRefreshParams(getContext(), true); |
| 53 | if (!refersh_params.empty()) |
| 54 | view->refreshAsync(refersh_params[0], getContext()); |
| 55 | } |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | AsyncRefreshParamPtrs refersh_params = view->getAsyncRefreshParams(getContext(), true); |
| 60 | if (!refersh_params.empty()) |
| 61 | view->refreshAsync(refersh_params[0], getContext()); |
| 62 | } |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | if (refresh.where_expr) |
| 67 | view->refreshWhere(refresh.where_expr, getContext(), refresh.async); |
| 68 | else if (refresh.partition) |
| 69 | view->refresh(refresh.partition, getContext(), refresh.async); |
| 70 | } |
| 71 | } |
| 72 | else |
| 73 | throw Exception("Table " + backQuoteIfNeed(database) + backQuoteIfNeed(refresh.table) + |
| 74 | " isn't a materialized view, can't be refreshed.", ErrorCodes::LOGICAL_ERROR); |
| 75 | getContext()->getCnchServerResource()->skipCleanWorker(); |
| 76 | return {}; |
| 77 | } |
| 78 | } |
nothing calls this directly
no test coverage detected