Maxwell-Guo commented on code in PR #3800:
URL: https://github.com/apache/cassandra/pull/3800#discussion_r1920341574
##########
src/java/org/apache/cassandra/cql3/statements/schema/CopyTableStatement.java:
##########
@@ -114,14 +123,39 @@ public Keyspaces apply(ClusterMetadata metadata)
if (targetKeyspaceMeta.hasTable(targetTableName))
{
- if(ifNotExists)
+ if (ifNotExists)
return schema;
throw new AlreadyExistsException(targetKeyspace, targetTableName);
}
- // todo support udt for differenet ks latter
- if (!sourceKeyspace.equalsIgnoreCase(targetKeyspace) &&
!sourceTableMeta.getReferencedUserTypes().isEmpty())
- throw ire("Cannot use CREATE TABLE LIKE across different keyspace
when source table have UDTs.");
+
+ if (!sourceKeyspace.equalsIgnoreCase(targetKeyspace))
+ {
+ Set<String> missingUserTypes = Sets.newHashSet();
+ // for different keyspace, if source table used some udts and the
target table also need them
+ for (ByteBuffer sourceUserTypeName :
sourceTableMeta.getReferencedUserTypes())
+ {
+ Optional<UserType> targetUserType =
targetKeyspaceMeta.types.get(sourceUserTypeName);
+ Optional<UserType> sourceUserType =
sourceKeyspaceMeta.types.get(sourceUserTypeName);
+ if (targetUserType.isPresent() && sourceUserType.isPresent())
+ {
+ if
(!sourceUserType.get().equalsWithOutKs(targetUserType.get()))
+ throw ire("Target keyspace '%s' has same UDT name '%s'
as source keyspace '%s' but with different structure.",
+ targetKeyspace,
+
UTF8Type.instance.getString(targetUserType.get().name),
+ sourceKeyspace);
+ }
+ else
+ {
+
missingUserTypes.add(UTF8Type.instance.compose(sourceUserTypeName));
+ }
+ }
+
+ if (!missingUserTypes.isEmpty())
+ throw ire("UDTs %s do not exist in target keyspace '%s'.",
+
missingUserTypes.stream().sorted().collect(Collectors.joining(", ")),
Review Comment:
The reason of sorting missingUserTypes here is to ensure that the string
output by the test case is regular,otherwise the single test result is very
random
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]