MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / assertOrSetUUID

Method assertOrSetUUID

src/Interpreters/InterpreterCreateQuery.cpp:1437–1517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1435}
1436
1437void InterpreterCreateQuery::assertOrSetUUID(ASTCreateQuery & create, const DatabasePtr & database) const
1438{
1439 const auto * kind = create.is_dictionary ? "Dictionary" : "Table";
1440 const auto * kind_upper = create.is_dictionary ? "DICTIONARY" : "TABLE";
1441 bool is_replicated_database_internal = database->getEngineName() == "Replicated" && getContext()->getClientInfo().is_replicated_database_internal;
1442 bool from_path = create.has_attach_from_path;
1443 bool is_on_cluster = getContext()->isDDLOrOnClusterInternal();
1444
1445 if (database->getEngineName() == "Replicated" && create.uuid != UUIDHelpers::Nil && !is_replicated_database_internal && !internal && !is_on_cluster && !create.attach)
1446 {
1447 if (getContext()->getSettingsRef()[Setting::database_replicated_allow_explicit_uuid] == 0)
1448 {
1449 throw Exception(ErrorCodes::BAD_ARGUMENTS, "It's not allowed to explicitly specify UUIDs for tables in Replicated databases, "
1450 "see database_replicated_allow_explicit_uuid");
1451 }
1452 if (getContext()->getSettingsRef()[Setting::database_replicated_allow_explicit_uuid] == 1)
1453 {
1454 LOG_WARNING(
1455 &Poco::Logger::get("InterpreterCreateQuery"),
1456 "It's not recommended to explicitly specify UUIDs for tables in Replicated databases");
1457 }
1458 else if (getContext()->getSettingsRef()[Setting::database_replicated_allow_explicit_uuid] == 2)
1459 {
1460 UUID old_uuid = create.uuid;
1461 create.uuid = UUIDHelpers::Nil;
1462 create.generateRandomUUIDs();
1463 LOG_WARNING(
1464 &Poco::Logger::get("InterpreterCreateQuery"),
1465 "Replaced a user-provided UUID ({}) with a random one ({}) "
1466 "to make sure it's unique",
1467 old_uuid,
1468 create.uuid);
1469 }
1470 }
1471
1472 if (is_replicated_database_internal && !internal)
1473 {
1474 if (create.uuid == UUIDHelpers::Nil)
1475 throw Exception(ErrorCodes::LOGICAL_ERROR, "Table UUID is not specified in DDL log");
1476 }
1477
1478 if (database->getUUID() != UUIDHelpers::Nil)
1479 {
1480 if (create.attach && !from_path && create.uuid == UUIDHelpers::Nil)
1481 {
1482 throw Exception(ErrorCodes::INCORRECT_QUERY,
1483 "Incorrect ATTACH {} query for Atomic database engine. "
1484 "Use one of the following queries instead:\n"
1485 "1. ATTACH {} {};\n"
1486 "2. CREATE {} {} <table definition>;\n"
1487 "3. ATTACH {} {} FROM '/path/to/data/' <table definition>;\n"
1488 "4. ATTACH {} {} UUID '<uuid>' <table definition>;",
1489 kind_upper,
1490 kind_upper, create.table->formatForErrorMessage(),
1491 kind_upper, create.table->formatForErrorMessage(),
1492 kind_upper, create.table->formatForErrorMessage(),
1493 kind_upper, create.table->formatForErrorMessage());
1494 }

Callers

nothing calls this directly

Calls 11

generateRandomUUIDsMethod · 0.80
resetUUIDsMethod · 0.80
ExceptionClass · 0.70
getContextFunction · 0.50
getFunction · 0.50
getEngineNameMethod · 0.45
getUUIDMethod · 0.45
formatForErrorMessageMethod · 0.45
hasInnerUUIDsMethod · 0.45
getDatabaseMethod · 0.45

Tested by

no test coverage detected