| 1049 | } |
| 1050 | |
| 1051 | void InterpreterCreateQuery::assertOrSetUUID(ASTCreateQuery & create, const DatabasePtr & database) const |
| 1052 | { |
| 1053 | ///const auto * kind = create.is_dictionary ? "Dictionary" : "Table"; |
| 1054 | const auto * kind_upper = create.is_dictionary ? "DICTIONARY" : "TABLE"; |
| 1055 | |
| 1056 | if (database->getEngineName() == "Replicated" && getContext()->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY |
| 1057 | && !internal) |
| 1058 | { |
| 1059 | if (create.uuid == UUIDHelpers::Nil) |
| 1060 | throw Exception("Table UUID is not specified in DDL log", ErrorCodes::LOGICAL_ERROR); |
| 1061 | } |
| 1062 | |
| 1063 | bool from_path = create.attach_from_path.has_value(); |
| 1064 | |
| 1065 | if (database->getUUID() != UUIDHelpers::Nil) |
| 1066 | { |
| 1067 | if (create.attach && !from_path && create.uuid == UUIDHelpers::Nil) |
| 1068 | { |
| 1069 | throw Exception(ErrorCodes::INCORRECT_QUERY, |
| 1070 | "Incorrect ATTACH {} query for Atomic database engine. " |
| 1071 | "Use one of the following queries instead:\n" |
| 1072 | "1. ATTACH {} {};\n" |
| 1073 | "2. CREATE {} {} <table definition>;\n" |
| 1074 | "3. ATTACH {} {} FROM '/path/to/data/' <table definition>;\n" |
| 1075 | "4. ATTACH {} {} UUID '<uuid>' <table definition>;", |
| 1076 | kind_upper, |
| 1077 | kind_upper, create.table, |
| 1078 | kind_upper, create.table, |
| 1079 | kind_upper, create.table, |
| 1080 | kind_upper, create.table); |
| 1081 | } |
| 1082 | |
| 1083 | generateUUIDForTable(create); |
| 1084 | } |
| 1085 | /// CnchMergeTree shold always have the UUID. |
| 1086 | else if (database->getEngineName() == "Cnch") |
| 1087 | { |
| 1088 | generateUUIDForTable(create); |
| 1089 | } |
| 1090 | else |
| 1091 | { |
| 1092 | /// As table name is always not the same with it on server side, |
| 1093 | /// we may need UUID of table on worker side in Memory database engine to find CnchMergeTree when needed |
| 1094 | /// Anyway, here we may need some more graceful code |
| 1095 | |
| 1096 | //bool is_on_cluster = getContext()->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY; |
| 1097 | //bool has_uuid = create.uuid != UUIDHelpers::Nil || create.to_inner_uuid != UUIDHelpers::Nil; |
| 1098 | //if (has_uuid && !is_on_cluster) |
| 1099 | // throw Exception(ErrorCodes::INCORRECT_QUERY, |
| 1100 | // "{} UUID specified, but engine of database {} is not Atomic", kind, create.database); |
| 1101 | |
| 1102 | /// Ignore UUID if it's ON CLUSTER query |
| 1103 | //create.uuid = UUIDHelpers::Nil; |
| 1104 | //create.to_inner_uuid = UUIDHelpers::Nil; |
| 1105 | } |
| 1106 | |
| 1107 | if (create.replace_table) |
| 1108 | { |
nothing calls this directly
no test coverage detected