This is an automated email from the ASF dual-hosted git repository.

liyafan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new 474611c  [CALCITE-4747]: clean all outdated edges from graph.edges
474611c is described below

commit 474611c2350b8a882eb71c179bc9eb54d6b3109e
Author: dongjianhui03 <[email protected]>
AuthorDate: Thu Aug 19 13:10:04 2021 +0800

    [CALCITE-4747]: clean all outdated edges from graph.edges
---
 .../java/org/apache/calcite/util/graph/DefaultDirectedGraph.java     | 5 +++++
 .../test/java/org/apache/calcite/util/graph/DirectedGraphTest.java   | 3 +++
 2 files changed, 8 insertions(+)

diff --git 
a/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java 
b/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java
index c14c3c4..a5b0b97 100644
--- a/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java
+++ b/core/src/main/java/org/apache/calcite/util/graph/DefaultDirectedGraph.java
@@ -182,6 +182,11 @@ public class DefaultDirectedGraph<V, E extends DefaultEdge>
     } else {
       removeMinorityVertices(collection);
     }
+
+    // remove all edges ref from this.edges
+    for (V v: collection) {
+      edges.removeIf(e -> e.source.equals(v) || e.target.equals(v));
+    }
   }
 
   /** Implementation of {@link #removeAllVertices(Collection)} that is 
efficient
diff --git 
a/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java 
b/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
index 028fcc5..320758f 100644
--- a/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
+++ b/core/src/test/java/org/apache/calcite/util/graph/DirectedGraphTest.java
@@ -153,8 +153,11 @@ class DirectedGraphTest {
    * {@link DefaultDirectedGraph#removeAllVertices(java.util.Collection)}. */
   @Test void testRemoveAllVertices() {
     final DefaultDirectedGraph<String, DefaultEdge> graph = createDag();
+    assertEquals(6, graph.edgeSet().size());
     graph.removeAllVertices(Arrays.asList("B", "E"));
     assertEquals("[A, C, D, F]", graph.vertexSet().toString());
+    assertEquals(1, graph.edgeSet().size());
+    assertEquals("[C -> D]", graph.edgeSet().toString());
   }
 
   /** Unit test for {@link TopologicalOrderIterator}. */

Reply via email to