| 1704 | } |
| 1705 | |
| 1706 | void InterpreterCreateQuery::prepareOnClusterQuery(ASTCreateQuery & create, ContextPtr local_context, const String & cluster_name) |
| 1707 | { |
| 1708 | if (create.attach) |
| 1709 | return; |
| 1710 | |
| 1711 | /// For CREATE query generate UUID on initiator, so it will be the same on all hosts. |
| 1712 | /// It will be ignored if database does not support UUIDs. |
| 1713 | generateUUIDForTable(create); |
| 1714 | |
| 1715 | /// For cross-replication cluster we cannot use UUID in replica path. |
| 1716 | String cluster_name_expanded = local_context->getMacros()->expand(cluster_name); |
| 1717 | ClusterPtr cluster = local_context->getCluster(cluster_name_expanded); |
| 1718 | |
| 1719 | if (cluster->maybeCrossReplication()) |
| 1720 | { |
| 1721 | /// Check that {uuid} macro is not used in zookeeper_path for ReplicatedMergeTree. |
| 1722 | /// Otherwise replicas will generate different paths. |
| 1723 | if (!create.storage) |
| 1724 | return; |
| 1725 | if (!create.storage->engine) |
| 1726 | return; |
| 1727 | if (!startsWith(create.storage->engine->name, "Replicated")) |
| 1728 | return; |
| 1729 | |
| 1730 | bool has_explicit_zk_path_arg = create.storage->engine->arguments && |
| 1731 | create.storage->engine->arguments->children.size() >= 2 && |
| 1732 | create.storage->engine->arguments->children[0]->as<ASTLiteral>() && |
| 1733 | create.storage->engine->arguments->children[0]->as<ASTLiteral>()->value.getType() == Field::Types::String; |
| 1734 | |
| 1735 | if (has_explicit_zk_path_arg) |
| 1736 | { |
| 1737 | String zk_path = create.storage->engine->arguments->children[0]->as<ASTLiteral>()->value.get<String>(); |
| 1738 | Macros::MacroExpansionInfo info; |
| 1739 | info.table_id.uuid = create.uuid; |
| 1740 | info.ignore_unknown = true; |
| 1741 | local_context->getMacros()->expand(zk_path, info); |
| 1742 | if (!info.expanded_uuid) |
| 1743 | return; |
| 1744 | } |
| 1745 | |
| 1746 | throw Exception("Seems like cluster is configured for cross-replication, " |
| 1747 | "but zookeeper_path for ReplicatedMergeTree is not specified or contains {uuid} macro. " |
| 1748 | "It's not supported for cross replication, because tables must have different UUIDs. " |
| 1749 | "Please specify unique zookeeper_path explicitly.", ErrorCodes::INCORRECT_QUERY); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | BlockIO InterpreterCreateQuery::execute() |
| 1754 | { |
nothing calls this directly
no test coverage detected