org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IncidentToAdjacentStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Checks whether a given step is optimizable or not. * * @param step1 an edge-emitting step * @param step2 a vertex-emitting step * @return <code>true</code> if step1 is not labeled and emits edges and step2 emits vertices, * otherwise <code>false</code> */ private static boolean isOptimizable(final Step step1, final Step step2) { if (step1 instanceof VertexStep && ((VertexStep) step1).returnsEdge() && step1.getLabels().isEmpty()) { final Direction step1Dir = ((VertexStep) step1).getDirection(); if (step1Dir.equals(Direction.BOTH)) { return step2 instanceof EdgeOtherVertexStep; } return step2 instanceof EdgeOtherVertexStep || (step2 instanceof EdgeVertexStep && ((EdgeVertexStep) step2).getDirection().equals(step1Dir.opposite())); } return false; }
Example #2
Source File: ReplacedStep.java From sqlg with MIT License | 5 votes |
private Set<SchemaTableTree> appendPath(SchemaTableTree schemaTableTree) { if (this.step instanceof VertexStep) { return appendPathForVertexStep(schemaTableTree); } else if (this.step instanceof EdgeVertexStep) { return appendPathForEdgeVertexStep(schemaTableTree); } else if (this.step instanceof EdgeOtherVertexStep) { return appendPathForEdgeOtherVertexStep(schemaTableTree); } else { throw new IllegalStateException("Only VertexStep, EdgeVertexStep and EdgeOtherVertexStep are handled! Found " + this.step.getClass().getName()); } }
Example #3
Source File: AdjacentVertexFilterOptimizerStrategy.java From grakn with GNU Affero General Public License v3.0 | 4 votes |
@Override public void apply(Traversal.Admin<?, ?> traversal) { TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal).forEach(originalStep -> { // Check if this filter traversal matches the pattern: _.inV/outV/otherV.is(x) Traversal.Admin<?, ?> filterTraversal = (Traversal.Admin<?, ?>) originalStep.getLocalChildren().get(0); List<Step> steps = filterTraversal.getSteps(); if (steps.size() == 2 && (steps.get(0) instanceof EdgeVertexStep || steps.get(0) instanceof EdgeOtherVertexStep) && (steps.get(1) instanceof IsStep)) { //Get the direction in which we filter on the adjacent vertex (or null if not a valid adjacency filter) Direction direction = null; if (steps.get(0) instanceof EdgeVertexStep) { EdgeVertexStep evs = (EdgeVertexStep) steps.get(0); if (evs.getDirection() != Direction.BOTH) direction = evs.getDirection(); } else { direction = Direction.BOTH; } P predicate = ((IsStep) steps.get(1)).getPredicate(); //Check that we have a valid direction and a valid vertex filter predicate if (direction != null && predicate.getBiPredicate() == Compare.eq && predicate.getValue() instanceof Vertex) { Vertex vertex = (Vertex) predicate.getValue(); //Now, check that this step is preceded by VertexStep that returns edges Step<?, ?> currentStep = originalStep.getPreviousStep(); while (currentStep != EmptyStep.instance()) { if (!(currentStep instanceof HasStep) && !(currentStep instanceof IdentityStep)) { break; } //We can jump over other steps as we move backward currentStep = currentStep.getPreviousStep(); } if (currentStep instanceof VertexStep) { VertexStep vertexStep = (VertexStep) currentStep; if (vertexStep.returnsEdge() && (direction == Direction.BOTH || direction.equals(vertexStep.getDirection().opposite()))) { //Now replace the step with a has condition TraversalHelper.replaceStep(originalStep, new HasStep(traversal, new HasContainer(ImplicitKey.ADJACENT_ID.name(), P.eq(vertex))), traversal); } } } } }); }
Example #4
Source File: ReplacedStep.java From sqlg with MIT License | 4 votes |
public boolean isEdgeOtherVertexStep() { return this.step instanceof EdgeOtherVertexStep; }
Example #5
Source File: GraphTraversal.java From tinkerpop with Apache License 2.0 | 2 votes |
/** * Map the {@link Edge} to the incident vertex that was not just traversed from in the path history. * * @return the traversal with an appended {@link EdgeOtherVertexStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#vertex-steps" target="_blank">Reference Documentation - Vertex Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, Vertex> otherV() { this.asAdmin().getBytecode().addStep(Symbols.otherV); return this.asAdmin().addStep(new EdgeOtherVertexStep(this.asAdmin())); }