smiklosovic commented on code in PR #3562:
URL: https://github.com/apache/cassandra/pull/3562#discussion_r1778892552
##########
src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java:
##########
@@ -703,6 +705,79 @@ private void validateCanDropCompactStorage()
}
}
+ public static class DropConstraint extends AlterTableStatement
+ {
+ final ColumnIdentifier constraintName;
+
+ DropConstraint(String keyspaceName, String tableName, boolean
ifTableExists, ColumnIdentifier constraintName)
+ {
+ super(keyspaceName, tableName, ifTableExists);
+ this.constraintName = constraintName;
+ }
+
+ @Override
+ public KeyspaceMetadata apply(Epoch epoch, KeyspaceMetadata keyspace,
TableMetadata table, ClusterMetadata metadata)
+ {
+ boolean removed = false;
+ TableMetadata.Builder tableBuilder = table.unbuild().epoch(epoch);
+ for(CqlConstraint constraint : tableBuilder.constraints())
+ {
+ if (constraint.constraintName == constraintName)
+ {
+ tableBuilder.removeConstraint(constraint);
+ removed = true;
+ }
+ }
+ if (!removed)
+ {
+ throw new ConstraintViolationException("Constraint '" +
constraintName + "' does not exist");
+ }
+
+ Views.Builder viewsBuilder = keyspace.views.unbuild();
+ TableMetadata tableMetadata = tableBuilder.build();
+ tableMetadata.validate();
+
+ return
keyspace.withSwapped(keyspace.tables.withSwapped(tableMetadata))
+ .withSwapped(viewsBuilder.build());
+ }
+ }
+
+ public static class AddConstraint extends AlterTableStatement
+ {
+ final ColumnIdentifier constraintName;
+ final CqlConstraint constraint;
+
+ AddConstraint(String keyspaceName, String tableName, boolean
ifTableExists, ColumnIdentifier constraintName, CqlConstraint constraint)
+ {
+ super(keyspaceName, tableName, ifTableExists);
+ this.constraintName = constraintName;
+ this.constraint = constraint;
+ }
+
+ @Override
+ public KeyspaceMetadata apply(Epoch epoch, KeyspaceMetadata keyspace,
TableMetadata table, ClusterMetadata metadata)
+ {
+ TableMetadata.Builder tableBuilder = table.unbuild().epoch(epoch);
+
+ for (CqlConstraint con : tableBuilder.constraints())
+ {
+ if (con.constraintName == constraintName)
+ {
Review Comment:
braces redundant
--
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]