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

Method executeSpecial

src/Interpreters/InterpreterShowStatsQuery.cpp:414–482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

412}
413
414void InterpreterShowStatsQuery::executeSpecial()
415{
416 auto query = query_ptr->as<const ASTShowStatsQuery>();
417 auto context = getContext();
418 auto catalog = Statistics::createCatalogAdaptor(context);
419
420 // when special, cache settings will be invalid
421 if (collector_settings.cache_policy != StatisticsCachePolicy::Default)
422 {
423 throw Exception("cache policy is not supported for special functions", ErrorCodes::BAD_ARGUMENTS);
424 }
425
426 if (context->getSettingsRef().statistics_cache_policy != StatisticsCachePolicy::Default)
427 {
428 throw Exception(
429 "statistics_cache_policy is not supported for special functions, must set it to default", ErrorCodes::BAD_ARGUMENTS);
430 }
431
432 // refactor this into an explicit command
433 if (query->table == "__save")
434 {
435 catalog->checkHealth(/*is_write=*/false);
436 auto db_name = context->resolveDatabase(query->database);
437 auto path = context->getSettingsRef().graphviz_path.toString() + "/" + db_name + ".bin";
438
439 writeDbStats(context, db_name, path);
440 }
441 else if (query->table == "__load")
442 {
443 catalog->checkHealth(/*is_write=*/true);
444 auto db_name = query->database;
445 if (db_name.empty())
446 db_name = context->getCurrentDatabase();
447 auto path = context->getSettingsRef().graphviz_path.toString() + "/" + db_name + ".bin";
448 if (!std::filesystem::exists(path))
449 {
450 throw Exception("file " + path + " not exists", ErrorCodes::FILE_NOT_FOUND);
451 }
452
453 readDbStats(context, db_name, path);
454 }
455 else if (query->table == "__jsonsave")
456 {
457 catalog->checkHealth(/*is_write=*/false);
458 auto db_name = query->database;
459 if (db_name.empty())
460 db_name = context->getCurrentDatabase();
461 auto folder = context->getSettingsRef().graphviz_path.toString() + '/' + db_name;
462 writeDbStatsToJson(context, db_name, folder);
463 }
464 else if (query->table == "__jsonload")
465 {
466 catalog->checkHealth(/*is_write=*/true);
467 auto db_name = query->database;
468 if (db_name.empty())
469 db_name = context->getCurrentDatabase();
470 auto path = context->getSettingsRef().graphviz_path.toString() + '/' + db_name + "/stats.json";
471 if (!std::filesystem::exists(path))

Callers

nothing calls this directly

Calls 12

createCatalogAdaptorFunction · 0.85
writeDbStatsFunction · 0.85
readDbStatsFunction · 0.85
writeDbStatsToJsonFunction · 0.85
readDbStatsFromJsonFunction · 0.85
checkHealthMethod · 0.80
resolveDatabaseMethod · 0.80
getCurrentDatabaseMethod · 0.80
ExceptionClass · 0.70
existsFunction · 0.50
toStringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected