JingDas commented on code in PR #3264:
URL: https://github.com/apache/calcite/pull/3264#discussion_r1239151614


##########
core/src/main/java/org/apache/calcite/rel/rules/ProjectJoinRemoveRule.java:
##########
@@ -127,6 +163,46 @@ public ProjectJoinRemoveRule(
     call.transformTo(node);
   }
 
+  /**
+   * Check as following:
+   * 1. Make sure that every foreign column is always a foreign key.
+   * 2. The target of foreign key is the correct corresponding unique key.
+   */
+  private static boolean areForeignKeysValid(List<Integer> foreignColumns,
+      List<Integer> uniqueColumns, ImmutableBitSet foreignKeys, 
RelMetadataQuery mq,
+      RelNode foreignSideRel, RelNode uniqueSideRel) {
+    if (foreignKeys.isEmpty()) {
+      return false;
+    }
+    if (!foreignKeys.contains(ImmutableBitSet.of(foreignColumns))) {
+      return false;
+    }
+    List<RelReferentialConstraint> referentialConstraints;
+    for (IntPair foreignUniqueKey : IntPair.zip(foreignColumns, 
uniqueColumns)) {
+      RelColumnOrigin foreignOrigin = mq.getColumnOrigin(foreignSideRel, 
foreignUniqueKey.source);
+      RelColumnOrigin uniqueOrigin = mq.getColumnOrigin(uniqueSideRel, 
foreignUniqueKey.target);
+      if (foreignOrigin == null || uniqueOrigin == null) {
+        return false;
+      }

Review Comment:
   OK, I agree with you. Thanks for the suggestion.



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

Reply via email to