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

Method executeByDropInsert

src/Storages/StorageMaterializedView.cpp:498–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498void StorageMaterializedView::executeByDropInsert(AsyncRefreshParamPtr param, ContextMutablePtr local_context)
499{
500 if (param->drop_partition_query.empty() && param->insert_select_query.empty())
501 throw Exception("Materialized view refresh drop partition annd insert select query is empty.", ErrorCodes::LOGICAL_ERROR);
502
503 /// BEGIN
504 auto & txn_coordinator = local_context->getCnchTransactionCoordinator();
505 auto explicit_txn = txn_coordinator.createTransaction(CreateTransactionOption().setType(CnchTransactionType::Explicit));
506 const_cast<Context &>(*local_context).setCurrentTransaction(explicit_txn, true);
507
508 auto create_command_context = [local_context](std::string sub_id) {
509 auto command_context = Context::createCopy(local_context);
510 command_context->setCurrentTransaction(nullptr, false);
511 command_context->setCurrentVW(nullptr);
512 command_context->setCurrentWorkerGroup(nullptr);
513 command_context->makeSessionContext();
514 command_context->makeQueryContext();
515 String query_id = fmt::format("{}_{}", command_context->getCurrentQueryId(), sub_id);
516 command_context->setCurrentQueryId(query_id);
517 auto settings = local_context->getSettings();
518 command_context->setSettings(settings);
519 command_context->setSetting("enable_materialized_view_rewrite", false);
520 return command_context;
521 };
522 auto start_time = std::chrono::system_clock::now();
523 insertRefreshTaskLog(param, RefreshViewTaskStatus::START, false, start_time, local_context);
524
525 std::optional<Exception> exception;
526 /// DROP PARTITION
527 if (!param->drop_partition_query.empty())
528 {
529 LOG_DEBUG(log, "refresh sync materialized view execute drop partition query: {}", param->drop_partition_query);
530 auto drop_context = create_command_context("mv_drop");
531 ThreadFromGlobalPool drop_thread([&]() {
532 std::optional<CurrentThread::QueryScope> query_scope;
533 query_scope.emplace(drop_context);
534 BlockIO drop_io;
535 try
536 {
537 try
538 {
539 drop_io = executeQuery(param->drop_partition_query, drop_context);
540 if (drop_io.pipeline.initialized())
541 {
542 auto & pipeline = drop_io.pipeline;
543 PullingAsyncPipelineExecutor executor(pipeline);
544 Block block;
545 while (executor.pull(block))
546 {
547 }
548 }
549 else if (drop_io.in)
550 {
551 AsynchronousBlockInputStream async_in(drop_io.in);
552 async_in.readPrefix();
553 while (true)
554 {
555 const auto block = async_in.read();

Callers

nothing calls this directly

Calls 15

nowFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
UUIDToStringFunction · 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