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

Method processTable

programs/dumper/Dumper.cpp:376–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376void ClickHouseDumper::processTable(const String & database, const String & table,
377 const String & partition,
378 const std::vector<String>& partitionlist,
379 const std::vector<String>& skippartitionlist)
380{
381 String db_table = database + "." + table;
382 String escaped_database = escapeForFileName(database);
383 String escaped_table = escapeForFileName(table);
384
385 /// Create storage from metadata
386 String attach_query_path = config().getString("path") + "/metadata/" + escaped_database + "/" + escaped_table + ".sql";
387 LOG_TRACE(log, " attach_query_path is {}", attach_query_path);
388 if (!Poco::File(attach_query_path).exists())
389 throw Exception("Table " + db_table + " doesn't exist.", ErrorCodes::UNKNOWN_TABLE);
390
391 ReadBufferFromFile in(attach_query_path, 1024);
392 String attach_query_str;
393 readStringUntilEOF(attach_query_str, in);
394
395 auto storage = createStorageFromCreateQuery(attach_query_str, database);
396 if (!storage)
397 {
398 LOG_ERROR(log, "{} is not MergeTree: {}", db_table, attach_query_str);
399 return;
400 }
401 auto & cloud = dynamic_cast<StorageCloudMergeTree &>(*storage);
402
403 /// Scan parts
404 String data_path = config().getString("path") + "/data/" + escaped_database + "/" + escaped_table;
405
406 LOG_DEBUG(log, "Scan parts in directory {}", data_path);
407
408 auto can_dump = [&](String partition_id) ->bool
409 {
410 if(!partition.empty() && partition_id != partition)
411 return false;
412
413 if(!partitionlist.empty() && std::find(std::begin(partitionlist),std::end(partitionlist),
414 partition_id) == std::end(partitionlist))
415 return false;
416
417 if(!skippartitionlist.empty() && std::find(std::begin(skippartitionlist),std::end(skippartitionlist),
418 partition_id) != std::end(skippartitionlist))
419 return false;
420
421 return true;
422 };
423
424 ActiveDataPartSet part_names(cloud.format_version);
425 for (Poco::DirectoryIterator it(data_path); it != Poco::DirectoryIterator(); ++it)
426 {
427 MergeTreePartInfo part_info;
428 if (!MergeTreePartInfo::tryParsePartName(it.name(), &part_info, cloud.format_version))
429 continue;
430
431 if(!can_dump(part_info.partition_id))
432 continue;
433

Callers

nothing calls this directly

Calls 15

escapeForFileNameFunction · 0.85
readStringUntilEOFFunction · 0.85
DirectoryIteratorClass · 0.85
UUIDToStringFunction · 0.85
generateV4Function · 0.85
getAnyDiskMethod · 0.80
configFunction · 0.50
FileClass · 0.50
ExceptionClass · 0.50
findFunction · 0.50

Tested by

no test coverage detected