in s2core/src/main/java/org/apache/s2graph/core/io/tinkerpop/optimize/S2GraphStep.java [59:112]
public S2GraphStep(final GraphStep<S, E> originalStep) {
super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.isStartStep(), originalStep.getIds());
if (!(traversal.asAdmin().getGraph().get() instanceof S2Graph)) return ;
foldInHasContainers(originalStep);
originalStep.getLabels().forEach(this::addLabel);
// 1. build S2Graph QueryParams for this step.
// 2. graph.vertices(this.ids, queryParams) or graph.edges(this.ids, queryParams)
// 3. vertices/edges lookup indexProvider, then return Seq[EdgeId/VertexId]
this.setIteratorSupplier(() -> {
final S2Graph graph = (S2Graph)traversal.asAdmin().getGraph().get();
if (this.ids != null && this.ids.length > 0) {
return iteratorList((Iterator)graph.vertices(this.ids));
}
// full scan
Boolean isVertex = Vertex.class.isAssignableFrom(this.returnClass);
if (hasContainers.isEmpty()) {
return (Iterator) (isVertex ? graph.vertices() : graph.edges());
} else {
List<VertexId> vids = new ArrayList<>();
List<EdgeId> eids = new ArrayList<>();
List<HasContainer> filtered = new ArrayList<>();
hasContainers.forEach(c -> {
if (c.getKey() == T.id.getAccessor()) {
if (c.getValue() instanceof List<?>) {
((List<?>)c.getValue()).forEach(o -> {
if (isVertex) vids.add((VertexId) o);
else eids.add((EdgeId) o);
});
} else {
if (isVertex) vids.add((VertexId)c.getValue());
else eids.add((EdgeId)c.getValue());
}
} else {
filtered.add(c);
}
});
if (isVertex) {
List<VertexId> ids = graph.indexProvider().fetchVertexIds(filtered.stream().distinct().collect(Collectors.toList()));
if (ids.isEmpty()) return (Iterator) graph.vertices();
else return (Iterator) graph.vertices(ids.toArray());
} else {
List<EdgeId> ids = graph.indexProvider().fetchEdgeIds(filtered.stream().distinct().collect(Collectors.toList()));
if (ids.isEmpty()) return (Iterator) graph.edges();
else return (Iterator) graph.edges(ids.toArray());
}
}
});
}