bbotella commented on code in PR #3867:
URL: https://github.com/apache/cassandra/pull/3867#discussion_r1942211985


##########
src/java/org/apache/cassandra/cql3/constraints/ColumnConstraint.java:
##########
@@ -41,7 +41,8 @@ enum ConstraintType
         // Changing this enum would affect how that int is interpreted when 
deserializing.
         COMPOSED(ColumnConstraints.serializer),
         FUNCTION(FunctionColumnConstraint.serializer),
-        SCALAR(ScalarColumnConstraint.serializer);
+        SCALAR(ScalarColumnConstraint.serializer),
+        UNARY_FUNCTION(UnaryFunctionColumnConstraint.serializer);

Review Comment:
   <3



##########
src/java/org/apache/cassandra/cql3/constraints/NotNullConstraint.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3.constraints;
+
+import java.nio.ByteBuffer;
+
+import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.cql3.Operator;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.schema.ColumnMetadata;
+
+public class NotNullConstraint implements ConstraintFunction
+{
+    public static final String FUNCTION_NAME = "NOT_NULL";

Review Comment:
   Nit: Technically, this is not a function anymore? What about CONSTRAINT_NAME?



##########
src/java/org/apache/cassandra/cql3/constraints/UnaryFunctionColumnConstraint.java:
##########
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3.constraints;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.function.Function;
+
+import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.cql3.CqlBuilder;
+import org.apache.cassandra.db.TypeSizes;
+import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.io.util.DataInputPlus;
+import org.apache.cassandra.io.util.DataOutputPlus;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.tcm.serialization.MetadataSerializer;
+import org.apache.cassandra.tcm.serialization.Version;
+import org.apache.cassandra.utils.LocalizeString;
+
+import static 
org.apache.cassandra.cql3.constraints.ColumnConstraint.ConstraintType.UNARY_FUNCTION;
+
+public class UnaryFunctionColumnConstraint implements 
ColumnConstraint<UnaryFunctionColumnConstraint>
+{
+    public static final Serializer serializer = new Serializer();
+
+    public final ConstraintFunction function;
+    public final ColumnIdentifier columnName;
+
+    public final static class Raw
+    {
+        public final ConstraintFunction function;
+        public final ColumnIdentifier columnName;
+
+        public Raw(ColumnIdentifier functionName, ColumnIdentifier columnName)
+        {
+            this.columnName = columnName;
+            function = createConstraintFunction(functionName.toCQLString(), 
columnName);
+        }
+
+        public UnaryFunctionColumnConstraint prepare()
+        {
+            return new UnaryFunctionColumnConstraint(function, columnName);
+        }
+    }
+
+    private enum Functions
+    {
+        NOT_NULL(NotNullConstraint::new);
+
+        private final Function<ColumnIdentifier, ConstraintFunction> 
functionCreator;
+
+        Functions(Function<ColumnIdentifier, ConstraintFunction> 
functionCreator)
+        {
+            this.functionCreator = functionCreator;
+        }
+    }
+
+    private static ConstraintFunction createConstraintFunction(String 
functionName, ColumnIdentifier columnName)

Review Comment:
   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.



##########
test/distributed/org/apache/cassandra/distributed/test/ColumnConstraintsTest.java:
##########
@@ -283,6 +284,21 @@ public void testLengthTableLevelConstraint() throws 
IOException
         }
     }
 
+    @Test
+    public void testNotNullTableLevelConstraint() throws IOException

Review Comment:
   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.



-- 
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

Reply via email to