|
32 | 32 | import org.apache.hugegraph.iterator.FlatMapperIterator; |
33 | 33 | import org.apache.hugegraph.structure.HugeEdge; |
34 | 34 | import org.apache.hugegraph.util.E; |
| 35 | +import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; |
35 | 36 |
|
36 | 37 | public class CountTraverser extends HugeTraverser { |
37 | 38 |
|
@@ -78,19 +79,23 @@ public long count(Id source, List<EdgeStep> steps, |
78 | 79 | }); |
79 | 80 | } |
80 | 81 |
|
81 | | - // The last step, just query count |
82 | | - EdgeStep lastStep = steps.get(stepNum - 1); |
83 | | - while (edges.hasNext()) { |
84 | | - Id target = ((HugeEdge) edges.next()).id().otherVertexId(); |
85 | | - if (this.dedup(target)) { |
86 | | - continue; |
| 82 | + try { |
| 83 | + // The last step, just query count |
| 84 | + EdgeStep lastStep = steps.get(stepNum - 1); |
| 85 | + while (edges.hasNext()) { |
| 86 | + Id target = ((HugeEdge) edges.next()).id().otherVertexId(); |
| 87 | + if (this.dedup(target)) { |
| 88 | + continue; |
| 89 | + } |
| 90 | + // Count last layer vertices(without dedup size) |
| 91 | + long edgesCount = this.edgesCount(target, lastStep); |
| 92 | + this.count.add(edgesCount); |
87 | 93 | } |
88 | | - // Count last layer vertices(without dedup size) |
89 | | - long edgesCount = this.edgesCount(target, lastStep); |
90 | | - this.count.add(edgesCount); |
91 | | - } |
92 | 94 |
|
93 | | - return this.count.longValue(); |
| 95 | + return this.count.longValue(); |
| 96 | + } finally { |
| 97 | + CloseableIterator.closeIterator(edges); |
| 98 | + } |
94 | 99 | } |
95 | 100 |
|
96 | 101 | private Iterator<Edge> edgesOfVertexWithCount(Id source, EdgeStep step) { |
|
0 commit comments