MCPcopy Create free account
hub / github.com/ByConity/ByConity / executeByInsertOverwrite

Method executeByInsertOverwrite

src/Storages/StorageMaterializedView.cpp:654–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654void StorageMaterializedView::executeByInsertOverwrite(AsyncRefreshParamPtr param, ContextMutablePtr local_context)
655{
656 if (param->insert_overwrite_query.empty())
657 throw Exception("materialized view refresh insert overwrite query is empty.", ErrorCodes::LOGICAL_ERROR);
658
659 auto create_command_context = [local_context](std::string sub_id) {
660 auto command_context = Context::createCopy(local_context);
661 command_context->setCurrentTransaction(nullptr, false);
662 command_context->setCurrentVW(nullptr);
663 command_context->setCurrentWorkerGroup(nullptr);
664 command_context->makeSessionContext();
665 command_context->makeQueryContext();
666 String query_id = fmt::format("{}_{}", command_context->getCurrentQueryId(), sub_id);
667 command_context->setCurrentQueryId(query_id);
668 auto settings = local_context->getSettings();
669 command_context->setSettings(settings);
670 command_context->setSetting("enable_materialized_view_rewrite", false);
671 return command_context;
672 };
673
674 auto insert_overwrite_context = create_command_context("mv_insert_overwrite");
675 auto & txn_coordinator = local_context->getCnchTransactionCoordinator();
676 auto server_txn = txn_coordinator.createTransaction(CreateTransactionOption().setType(CnchTransactionType::Implicit));
677 const_cast<Context &>(*insert_overwrite_context).setCurrentTransaction(server_txn);
678
679 /// Add commit and abort function for mv meta
680 auto mv_commit_func = [param = param, this](ContextPtr context) {
681 return context->getCnchCatalog()->constructMvMetaRequests(
682 UUIDHelpers::UUIDToString(this->getStorageUUID()), param->part_diff->add_partitions, param->part_diff->drop_partitions, toString(context->getTimestamp()));
683 };
684 auto mv_abort_func = [param = param, this](ContextPtr context) {
685 return context->getCnchCatalog()->constructMvMetaRequests(
686 UUIDHelpers::UUIDToString(this->getStorageUUID()), param->part_diff->add_partitions, param->part_diff->drop_partitions, toString(context->getTimestamp()));
687 };
688 insert_overwrite_context->getCurrentTransaction()->addCommitAbortFunc(mv_commit_func, mv_abort_func);
689
690 /// Insert refresh task log
691 auto start_time = std::chrono::system_clock::now();
692 insertRefreshTaskLog(param, RefreshViewTaskStatus::START, true, start_time, local_context);
693
694 std::optional<Exception> exception;
695 ThreadFromGlobalPool async_thread([&]() {
696 try
697 {
698 std::optional<CurrentThread::QueryScope> query_scope;
699 query_scope.emplace(insert_overwrite_context);
700 CurrentThread::get().pushTenantId(insert_overwrite_context->getSettingsRef().tenant_id);
701
702 LOG_DEBUG(log, "refresh sync materialized view refresh insert overwite query: {}", param->insert_overwrite_query);
703 BlockIO insert_io;
704 try
705 {
706 insert_io = executeQuery(param->insert_overwrite_query, insert_overwrite_context, false);
707 if (insert_io.pipeline.initialized())
708 {
709 auto & pipeline = insert_io.pipeline;
710 PullingAsyncPipelineExecutor executor(pipeline);
711 Block block;

Callers

nothing calls this directly

Calls 15

UUIDToStringFunction · 0.85
nowFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
setCurrentTransactionMethod · 0.80
setCurrentVWMethod · 0.80
setCurrentWorkerGroupMethod · 0.80
makeSessionContextMethod · 0.80
getCurrentQueryIdMethod · 0.80
setCurrentQueryIdMethod · 0.80

Tested by

no test coverage detected