XieJiann commented on code in PR #27627:
URL: https://github.com/apache/doris/pull/27627#discussion_r1409010780


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java:
##########
@@ -153,6 +156,80 @@ default int getBaseColumnIdxByName(String colName) {
 
     void write(DataOutput out) throws IOException;
 
+    default Map<String, Constraint> getConstraintMap() {
+        throw new RuntimeException("Not implemented constraint for table " + 
this.toString());
+    }
+
+    // Note this function is not thread safe
+    default void checkConstraintNotExistence(String name, Constraint 
primaryKeyConstraint,
+            Map<String, Constraint> constraintMap) {
+        if (constraintMap.containsKey(name)) {
+            throw new RuntimeException(String.format("Constraint name %s has 
existed", name));
+        }
+        for (Map.Entry<String, Constraint> entry : constraintMap.entrySet()) {
+            if (entry.getValue().equals(primaryKeyConstraint)) {
+                throw new RuntimeException(String.format(
+                        "Constraint %s has existed, named %s", 
primaryKeyConstraint, entry.getKey()));
+            }
+        }
+    }
+
+    default void addUniqueConstraint(String name, ImmutableList<Column> 
columns) {
+        writeLock();
+        try {
+            Map<String, Constraint> constraintMap = getConstraintMap();
+            UniqueConstraint uniqueConstraint =  new 
UniqueConstraint(ImmutableSet.copyOf(columns));
+            checkConstraintNotExistence(name, uniqueConstraint, constraintMap);
+            constraintMap.put(name, uniqueConstraint);

Review Comment:
   constraintMap is initiated when init table class. So it is always not null



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to