nooneuse commented on code in PR #66307:
URL: https://github.com/apache/doris/pull/66307#discussion_r3775265398


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/constraint/ConstraintManager.java:
##########
@@ -893,6 +1100,74 @@ private void validateTableAndColumns(TableNameInfo 
tableNameInfo,
                         fk.getReferencedColumnNames(),
                         toKey(refTableInfo));
             }
+        } else if (constraint instanceof DistributionMappingConstraint) {
+            validateDistributionMappingConstraint(
+                    tableNameInfo, table, (DistributionMappingConstraint) 
constraint);
+        }
+        return table;
+    }
+
+    private TableIf resolveTableIfPresent(TableNameInfo tableNameInfo) {
+        try {
+            return resolveTableForValidation(tableNameInfo);
+        } catch (AnalysisException e) {
+            LOG.debug("Table {} is unavailable while synchronizing table-local 
constraints",
+                    tableNameInfo, e);
+            return null;
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private void putTableLocalConstraint(TableIf table, String constraintName, 
Constraint constraint) {
+        if (table instanceof Table) {
+            ((Table) 
table).getTableAttributes().getConstraintsMap().put(constraintName, constraint);
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private void removeTableLocalConstraint(TableIf table, String 
constraintName) {
+        if (table instanceof Table) {
+            ((Table) 
table).getTableAttributes().getConstraintsMap().remove(constraintName);
+        }
+    }
+
+    private void validateDistributionMappingConstraint(TableNameInfo 
tableNameInfo, TableIf table,
+            DistributionMappingConstraint constraint) {
+        if (!(table instanceof OlapTable)) {
+            throw new AnalysisException("Distribution mapping constraint only 
supports OLAP tables");
+        }
+        validateColumnsExist(table, constraint.getDeterminantColumnNames(), 
toKey(tableNameInfo));
+        validateColumnsExist(table, constraint.getDistributionColumnNames(), 
toKey(tableNameInfo));
+        TreeSet<String> determinantColumns = new 
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        determinantColumns.addAll(constraint.getDeterminantColumnNames());
+        if (determinantColumns.size() != 
constraint.getDeterminantColumnNames().size()) {
+            throw new AnalysisException("Determinant columns in distribution 
mapping constraint must be unique");
+        }
+        TreeSet<String> distributionColumns = new 
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        distributionColumns.addAll(constraint.getDistributionColumnNames());
+        if (distributionColumns.size() != 
constraint.getDistributionColumnNames().size()) {
+            throw new AnalysisException("Distribution columns in distribution 
mapping constraint must be unique");
+        }
+
+        OlapTable olapTable = (OlapTable) table;
+        if (!(olapTable.getDefaultDistributionInfo() instanceof 
HashDistributionInfo)) {

Review Comment:
   right.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to