You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/10/26 07:07:29 UTC

[GitHub] [calcite] yanlin-Lynn commented on a change in pull request #1534: [CALCITE-3450] Support Intersect and Minus in RelMdTableReferences.

yanlin-Lynn commented on a change in pull request #1534: [CALCITE-3450] Support Intersect and Minus in RelMdTableReferences.
URL: https://github.com/apache/calcite/pull/1534#discussion_r339289527
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/rel/metadata/RelMdTableReferences.java
 ##########
 @@ -183,6 +185,72 @@ protected RelMdTableReferences() {}
     return result;
   }
 
+  /**
+   * Table references from Intersect.
+   */
+  public Set<RelTableRef> getTableReferences(Intersect intersect, final RelMetadataQuery mq) {
+    final Set<RelTableRef> result = new HashSet<>();
+
+    final Multimap<List<String>, RelTableRef> qualifiedNamesToRefs = HashMultimap.create();
+    for (RelNode input : intersect.getInputs()) {
+      final Map<RelTableRef, RelTableRef> currentTablesMapping = new HashMap<>();
+      final Set<RelTableRef> inputTableRefs = mq.getTableReferences(input);
+      if (inputTableRefs == null) {
+        return null;
+      }
+      for (RelTableRef tableRef : inputTableRefs) {
+        int shift = 0;
+        Collection<RelTableRef> lRefs = qualifiedNamesToRefs.get(
+                tableRef.getQualifiedName());
+        if (lRefs != null) {
+          shift = lRefs.size();
+        }
+        RelTableRef shiftTableRef = RelTableRef.of(
+                tableRef.getTable(), shift + tableRef.getEntityNumber());
+        assert !result.contains(shiftTableRef);
+        result.add(shiftTableRef);
+        currentTablesMapping.put(tableRef, shiftTableRef);
+      }
+      for (RelTableRef newRef : currentTablesMapping.values()) {
+        qualifiedNamesToRefs.put(newRef.getQualifiedName(), newRef);
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Table references from Minus.
+   */
+  public Set<RelTableRef> getTableReferences(Minus minus, final RelMetadataQuery mq) {
+    final Set<RelTableRef> result = new HashSet<>();
+
+    final Multimap<List<String>, RelTableRef> qualifiedNamesToRefs = HashMultimap.create();
+    for (RelNode input : minus.getInputs()) {
+      final Map<RelTableRef, RelTableRef> currentTablesMapping = new HashMap<>();
+      final Set<RelTableRef> inputTableRefs = mq.getTableReferences(input);
+      if (inputTableRefs == null) {
+        return null;
+      }
+      for (RelTableRef tableRef : inputTableRefs) {
+        int shift = 0;
+        Collection<RelTableRef> lRefs = qualifiedNamesToRefs.get(
+                tableRef.getQualifiedName());
+        if (lRefs != null) {
+          shift = lRefs.size();
+        }
+        RelTableRef shiftTableRef = RelTableRef.of(
+                tableRef.getTable(), shift + tableRef.getEntityNumber());
+        assert !result.contains(shiftTableRef);
+        result.add(shiftTableRef);
+        currentTablesMapping.put(tableRef, shiftTableRef);
+      }
+      for (RelTableRef newRef : currentTablesMapping.values()) {
+        qualifiedNamesToRefs.put(newRef.getQualifiedName(), newRef);
+      }
+    }
+    return result;
+  }
+
 
 Review comment:
   The implementation for getTableReferences of `Minus` and `Intersect` is basically the same with `Union`. Can you just put them together?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services