-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSANDRA-20276 implementation of NOT_NULL constraint #3867
base: trunk
Are you sure you want to change the base?
Conversation
8187c9f
to
8e96d89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a not null constraint in SnapshotTest.testSimpleSnapshot()
, on line 54. That way we are also making sure that serialization/deserialization works.
|
||
public class NotNullConstraint implements ConstraintFunction | ||
{ | ||
public static final String FUNCTION_NAME = "NOT_NULL"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Technically, this is not a function anymore? What about CONSTRAINT_NAME?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It implements ConstraintFunction. It is a function. Unary one.
} | ||
} | ||
|
||
private static ConstraintFunction createConstraintFunction(String functionName, ColumnIdentifier columnName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, and some other methods are identical to the ones in FunctionColumnConstraint
. Should we share that logic with an abstract class? I mean, it is a "small" repetition, but still somehow annoys me to see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to do that but I was not sure how to abstract Functions
enum. That would need to be passed as a parameter and I was stuck doing that. Feel free to try it.
@@ -283,6 +284,21 @@ public void testLengthTableLevelConstraint() throws IOException | |||
} | |||
} | |||
|
|||
@Test | |||
public void testNotNullTableLevelConstraint() throws IOException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. For completion, I think we can also add a org.apache.cassandra.contraints.CreateTableWithColumnNotNullConstraintValidationTest
and a org.apache.cassandra.contraints.AlterTableWithNotNullConstraintValidationTest
with parametrized tests for all the Cassandra types. I can create a patch to this PR if you don't have the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure create it. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am extremely happy to see a new constraint coming down to increase Cassandra CQL features! The approach you took to support unary functions fits perfectly on the framework, and gives us a way cleaner alternative for such constraints. Thanks a lot for the PR @smiklosovic!!
a24e806
to
8e96d89
Compare
@Override | ||
public String toString() | ||
{ | ||
return function.getName() + '(' + columnName + ") "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah! Writing the tests I catched this bug. Look at the extra space on the closing parentheses. :-)
Don't worry about it. I'm fixing it on a PR to this PR.
|
||
import static org.apache.cassandra.cql3.constraints.ColumnConstraint.ConstraintType.UNARY_FUNCTION; | ||
|
||
public class UnaryFunctionColumnConstraint implements ColumnConstraint<UnaryFunctionColumnConstraint> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also found out that we are missing the equals override. Posting it on a PR to this PR
8e96d89
to
0c4918b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 (nb)
0c4918b
to
88fdee4
Compare
patch by Stefan Miklosovic; reviewed by Bernardo Botella, TBD for CASSANDRA-20276 Co-authored-by: Bernardo Botella Corbi <[email protected]>
88fdee4
to
c08802d
Compare
Thanks for sending a pull request! Here are some tips if you're new here:
Commit messages should follow the following format:
The Cassandra Jira