use of org.apache.tinkerpop.gremlin.process.traversal.Traverser in project sqlg by pietermartin.
the class SqlgOrStepBarrier method processNextStart.
@Override
protected Traverser.Admin<S> processNextStart() {
if (this.first) {
this.first = false;
Multimap<String, Traverser.Admin<S>> startRecordIds = LinkedListMultimap.create();
while (this.starts.hasNext()) {
Traverser.Admin<S> start = this.starts.next();
if (start instanceof SqlgTraverser) {
((SqlgTraverser) start).setRequiresOneBulk(true);
}
List<Object> startObjects = start.path().objects();
StringBuilder recordIdConcatenated = new StringBuilder();
for (Object startObject : startObjects) {
if (startObject instanceof Element) {
Element e = (Element) startObject;
recordIdConcatenated.append(e.id().toString());
} else {
recordIdConcatenated.append(startObject.toString());
}
}
startRecordIds.put(recordIdConcatenated.toString(), start);
}
for (Traversal.Admin<S, ?> orTraversal : this.orTraversals) {
for (Traverser.Admin<S> start : startRecordIds.values()) {
orTraversal.addStart(start);
}
while (orTraversal.hasNext()) {
Traverser.Admin<?> orTraverser = orTraversal.nextTraverser();
List<Object> filterTraverserObjects = orTraverser.path().objects();
String startId = "";
for (Object filteredTraverserObject : filterTraverserObjects) {
if (filteredTraverserObject instanceof Element) {
Element e = (Element) filteredTraverserObject;
startId += e.id().toString();
} else {
startId += filteredTraverserObject.toString();
}
if (startRecordIds.containsKey(startId)) {
this.results.addAll(startRecordIds.get(startId));
startRecordIds.removeAll(startId);
}
if (startRecordIds.isEmpty()) {
break;
}
}
}
}
this.results.sort((o1, o2) -> {
SqlgTraverser x = (SqlgTraverser) o1;
SqlgTraverser y = (SqlgTraverser) o2;
return Long.compare(x.getStartElementIndex(), y.getStartElementIndex());
});
this.resultIterator = this.results.iterator();
}
if (this.resultIterator.hasNext()) {
Traverser.Admin<S> traverser = this.resultIterator.next();
return traverser;
} else {
// The standard TraversalFilterStep.filter calls TraversalUtil.test which normally resets the traversal for every incoming start.
reset();
throw FastNoSuchElementException.instance();
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.Traverser in project unipop by unipop-graph.
the class UniGraphCoalesceStep method process.
@Override
protected Iterator<Traverser.Admin<E>> process(List<Traverser.Admin<S>> traversers) {
List<Traverser.Admin<E>> coalesce = new ArrayList<>();
List<Traverser.Admin<S>> traversersList = Lists.newArrayList(traversers);
traversersList.forEach(t -> {
t.setSideEffects(new DefaultTraversalSideEffects() {
{
register(t.toString(), () -> t, BinaryOperator.maxBy((o1, o2) -> 1));
set(t.toString(), t);
}
});
});
coalesceTraversals.forEach(t -> {
traversersList.forEach(t::addStart);
while (t.hasNext()) {
Traverser<E> item = (Traverser<E>) t.next();
((B_O_S_SE_SL_Traverser) item).getSideEffects().forEach((key, value) -> {
if (value != null && value instanceof Traverser)
traversersList.remove(value);
});
coalesce.add((item.asAdmin()));
}
});
return coalesce.iterator();
}
use of org.apache.tinkerpop.gremlin.process.traversal.Traverser in project unipop by unipop-graph.
the class UniGraphWhereTraversalStep method processNextStart.
@Override
protected Traverser.Admin<S> processNextStart() throws NoSuchElementException {
if (this.starts.hasNext()) {
this.starts.forEachRemaining(start -> {
start.setSideEffects(new DefaultTraversalSideEffects() {
{
register("_whereStep", () -> start, (sAdmin, sAdmin2) -> sAdmin);
}
});
whereTraversal.asAdmin().addStart(start);
originals.add(start);
if (whereTraversal.asAdmin().getStartStep() instanceof UniGraphWhereStartStep) {
((UniGraphWhereStartStep) whereTraversal.asAdmin().getStartStep()).addOriginal(start);
}
});
had = true;
}
if (had && !results.hasNext()) {
HashSet<Traverser.Admin<S>> resultsList = new HashSet<>();
while (whereTraversal.hasNext()) {
had = false;
B_O_S_SE_SL_Traverser next = (B_O_S_SE_SL_Traverser) whereTraversal.next();
Object whereStep = next.getSideEffects().get("_whereStep");
if (whereStep instanceof Traverser)
resultsList.add((Traverser.Admin<S>) whereStep);
else {
results = ((ArrayList<Traverser.Admin<S>>) whereStep).iterator();
}
}
if (resultsList.size() > 0)
results = resultsList.iterator();
}
return results.next();
}
use of org.apache.tinkerpop.gremlin.process.traversal.Traverser in project unipop by unipop-graph.
the class UniGraphEdgeOtherVertexStep method process.
@Override
protected Iterator<Traverser.Admin<Vertex>> process(List<Traverser.Admin<Edge>> traversers) {
List<Traverser.Admin<Vertex>> vertices = new ArrayList<>();
traversers.forEach(traverser -> {
final List<Object> objects = traverser.path().objects();
if (objects.get(objects.size() - 2) instanceof Vertex) {
Vertex vertex = ElementHelper.areEqual((Vertex) objects.get(objects.size() - 2), traverser.get().outVertex()) ? traverser.get().inVertex() : traverser.get().outVertex();
vertices.add(traverser.split(vertex, this));
}
});
if (propertyKeys == null || propertyKeys.size() > 0) {
List<DeferredVertex> v = vertices.stream().map(Attachable::get).filter(vertex -> vertex instanceof DeferredVertex).map(vertex -> ((DeferredVertex) vertex)).filter(DeferredVertex::isDeferred).collect(Collectors.toList());
if (v.size() > 0) {
DeferredVertexQuery query = new DeferredVertexQuery(v, propertyKeys, orders, stepDescriptor, traversal);
deferredVertexControllers.forEach(deferredVertexController -> deferredVertexController.fetchProperties(query));
}
}
return vertices.iterator();
}
use of org.apache.tinkerpop.gremlin.process.traversal.Traverser in project sqlg by pietermartin.
the class SqlgWhereTraversalStepBarrier method processNextStart.
@Override
protected Traverser.Admin<S> processNextStart() throws NoSuchElementException {
if (this.first) {
this.first = false;
while (this.starts.hasNext()) {
Traverser.Admin start = this.starts.next();
// However the traverser might have been created from a step and strategy that does not care for TraverserRequirement.ONE_BULK so we force it here.
if (start instanceof SqlgTraverser) {
((SqlgTraverser) start).setRequiresOneBulk(true);
}
List<Object> startObjects = start.path().objects();
StringBuilder recordIdConcatenated = new StringBuilder();
for (Object startObject : startObjects) {
if (startObject instanceof Element) {
Element e = (Element) startObject;
recordIdConcatenated.append(e.id().toString());
} else {
recordIdConcatenated.append(startObject.toString());
}
}
this.startRecordIds.put(recordIdConcatenated.toString(), start);
this.whereTraversal.addStart(start);
}
while (this.whereTraversal.hasNext()) {
Traverser.Admin<?> filterTraverser = this.whereTraversal.nextTraverser();
List<Object> filterTraverserObjects = filterTraverser.path().objects();
String startId = "";
for (Object filteredTraverserObject : filterTraverserObjects) {
if (filteredTraverserObject instanceof Element) {
Element e = (Element) filteredTraverserObject;
startId += e.id().toString();
} else {
startId += filteredTraverserObject.toString();
}
if (startRecordIds.containsKey(startId)) {
this.results.addAll(startRecordIds.get(startId));
startRecordIds.removeAll(startId);
}
if (startRecordIds.isEmpty()) {
break;
}
}
}
this.results.sort((o1, o2) -> {
SqlgTraverser x = (SqlgTraverser) o1;
SqlgTraverser y = (SqlgTraverser) o2;
return Long.compare(x.getStartElementIndex(), y.getStartElementIndex());
});
this.resultIterator = this.results.iterator();
}
if (this.resultIterator.hasNext()) {
Traverser.Admin<S> traverser = this.resultIterator.next();
return PathProcessor.processTraverserPathLabels(traverser, this.keepLabels);
} else {
// The standard TraversalFilterStep.filter calls TraversalUtil.test which normally resets the traversal for every incoming start.
reset();
throw FastNoSuchElementException.instance();
}
}
Aggregations