Maxwell-Guo commented on code in PR #3800:
URL: https://github.com/apache/cassandra/pull/3800#discussion_r1918463433
##########
src/java/org/apache/cassandra/cql3/statements/schema/CopyTableStatement.java:
##########
@@ -119,9 +129,31 @@ public Keyspaces apply(ClusterMetadata metadata)
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.");
+
+ Set<UserType> userTypesToCreate = Sets.newHashSet();
+ if (!sourceKeyspace.equalsIgnoreCase(targetKeyspace))
+ {
+ // for different keyspace, if source table used some udts and the
target table also need them
+ Set<UserType> sourceuserTypeSet =
collectColumnsUdt(sourceTableMeta);
+ for (UserType userType : sourceuserTypeSet)
+ {
+ Optional<UserType> userTypeForTargetTb =
targetKeyspaceMeta.types.get(userType.name);
+ if (userTypeForTargetTb.isPresent())
+ {
+ if (!userType.equalsWithOutKs(userTypeForTargetTb.get()))
+ throw ire("Target Keyspace " + targetKeyspace + " has
same UDT name with " + sourceKeyspace + " but with different udt value.");
+ }
+ else
+ {
+ userTypesToCreate.add(userType);
Review Comment:
I think we can also break here is userTypeForTargetTb is not present , no
need to add the userType to userTypesToCreate.
The purpose of doing this here is to print out all the udts that need to be
created.
--
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]