Skip to content
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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

smiklosovic
Copy link
Contributor

Thanks for sending a pull request! Here are some tips if you're new here:

  • Ensure you have added or run the appropriate tests for your PR.
  • Be sure to keep the PR description updated to reflect all changes.
  • Write your PR title to summarize what this PR proposes.
  • If possible, provide a concise example to reproduce the issue for a faster review.
  • Read our contributor guidelines
  • If you're making a documentation change, see our guide to documentation contribution

Commit messages should follow the following format:

<One sentence description, usually Jira title or CHANGES.txt summary>

<Optional lengthier description (context on patch)>

patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####

Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>

The Cassandra Jira

@smiklosovic smiklosovic force-pushed the CASSANDRA-20276 branch 3 times, most recently from 8187c9f to 8e96d89 Compare February 4, 2025 15:21
Copy link
Contributor

@bbotella bbotella left a 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";
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

@smiklosovic smiklosovic Feb 5, 2025

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure create it. Thanks.

Copy link
Contributor

@bbotella bbotella left a 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!!

@Override
public String toString()
{
return function.getName() + '(' + columnName + ") ";
Copy link
Contributor

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>
Copy link
Contributor

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

Copy link
Contributor

@bbotella bbotella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 (nb)

smiklosovic and others added 2 commits February 6, 2025 18:34
patch by Stefan Miklosovic; reviewed by Bernardo Botella, TBD for CASSANDRA-20276

Co-authored-by: Bernardo Botella Corbi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants