smiklosovic commented on code in PR #3903: URL: https://github.com/apache/cassandra/pull/3903#discussion_r1963071257
########## src/java/org/apache/cassandra/cql3/constraints/ColumnConstraint.java: ########## @@ -46,32 +53,57 @@ public enum ConstraintType // The order of that enum matters!! // We are serializing its enum position instead of its name. // Changing this enum would affect how that int is interpreted when deserializing. - COMPOSED(ColumnConstraints.serializer), - FUNCTION(FunctionColumnConstraint.serializer), - SCALAR(ScalarColumnConstraint.serializer), - UNARY_FUNCTION(UnaryFunctionColumnConstraint.serializer); + COMPOSED(ColumnConstraints.serializer, new DuplicatesChecker()), + FUNCTION(FunctionColumnConstraint.serializer, FunctionColumnConstraint.Functions.values()), + SCALAR(ScalarColumnConstraint.serializer, new ScalarColumnConstraintSatisfiabilityChecker()), + UNARY_FUNCTION(UnaryFunctionColumnConstraint.serializer, UnaryFunctionColumnConstraint.Functions.values()); private final MetadataSerializer<?> serializer; + private final SatisfiabilityChecker[] satisfiabilityCheckers; + + ConstraintType(MetadataSerializer<?> serializer, SatisfiabilityChecker satisfiabilityChecker) + { + this(serializer, new SatisfiabilityChecker[]{ satisfiabilityChecker }); + } - ConstraintType(MetadataSerializer<?> serializer) + ConstraintType(MetadataSerializer<?> serializer, SatisfiabilityChecker[] satisfiabilityCheckers) { this.serializer = serializer; + this.satisfiabilityCheckers = satisfiabilityCheckers; } public static MetadataSerializer<?> getSerializer(int i) { return ConstraintType.values()[i].serializer; } + + private static SatisfiabilityChecker[] getSatisfiabilityCheckers() + { + List<SatisfiabilityChecker> result = new ArrayList<>(); + for (ConstraintType constraintType : ConstraintType.values()) + result.addAll(Arrays.asList(constraintType.satisfiabilityCheckers)); + + return result.toArray(new SatisfiabilityChecker[0]); + } + } + + public abstract String name(); + + public String fullName() Review Comment: @bbotella We need to make a difference between "name of the function" which is just `LENGTH`, for example, and "full name" which also contains its operator. That is necessary to realize if there is a duplicate or not. `a CHECK LENGTH(a) > 0 AND LENGTH(a) > 10` This means that "full name" will be `LENGTH >` and `LENGTH >`. That means that we see that we have used same function with same operator twice - so we fail. This is what `DuplicatesChecker` is doing. If not done in DuplicatesChecker, we would need to check for duplicities in every specific satisfaction checker all the time all over again. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org