public TitanVertexStep(VertexStep<E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.getDirection(), originalStep.getEdgeLabels()); originalStep.getLabels().forEach(this::addLabel); this.hasContainers = new ArrayList<>(); this.limit = Query.NO_LIMIT; }
public JanusGraphVertexStep(VertexStep<E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.getDirection(), originalStep.getEdgeLabels()); originalStep.getLabels().forEach(this::addLabel); this.hasContainers = new ArrayList<>(); this.limit = Query.NO_LIMIT; }
VertexStep vstep = (VertexStep)currentStep; if (vstep.returnsEdge() && (direction==Direction.BOTH || direction.equals(vstep.getDirection().opposite()))) {
VertexStep vertexStep = (VertexStep) currentStep; if (vertexStep.returnsEdge() && (direction == Direction.BOTH || direction.equals(vertexStep.getDirection().opposite()))) {
private static Direction getDirection(final Traversal.Admin<Vertex, Edge> incidentTraversal) { final VertexStep step = TraversalHelper.getLastStepOfAssignableClass(VertexStep.class, incidentTraversal).get(); return step.getDirection(); } }
private static Direction getOppositeDirection(final Traversal.Admin<Vertex, Edge> incidentTraversal) { final VertexStep step = TraversalHelper.getLastStepOfAssignableClass(VertexStep.class, incidentTraversal).get(); return step.getDirection().opposite(); } }
public HugeVertexStep(final VertexStep<E> originVertexStep) { super(originVertexStep.getTraversal(), originVertexStep.getReturnClass(), originVertexStep.getDirection(), originVertexStep.getEdgeLabels()); originVertexStep.getLabels().forEach(this::addLabel); }
final Map<String, Legal> map = this.edgeLegality.get(step.getDirection()); if (step.returnsEdge()) { if (step.getEdgeLabels().length == 0) if (union.getStartStep() instanceof VertexStep) { final VertexStep vertexStep = (VertexStep) union.getStartStep(); final Map<String, Legal> map = this.edgeLegality.get(vertexStep.getDirection()); if (vertexStep.returnsEdge()) { if (vertexStep.getEdgeLabels().length == 0)
TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal).forEach(step -> { final Direction direction = step.getDirection().equals(Direction.IN) && step.returnsEdge() ? Direction.BOTH : step.getDirection(); final String[] edgeLabels = step.getEdgeLabels(); if (edgeLabels.length == 0)
public static final boolean endsWithElement(Step<?, ?> currentStep) { while (!(currentStep instanceof EmptyStep)) { if (currentStep instanceof VertexStep) // only inE, in, and out send messages return (((VertexStep) currentStep).returnsVertex() || !((VertexStep) currentStep).getDirection().equals(Direction.OUT)); else if (currentStep instanceof EdgeVertexStep) // TODO: add GraphStep but only if its mid-traversal V()/E() return true; else if (currentStep instanceof TraversalFlatMapStep || currentStep instanceof TraversalMapStep || currentStep instanceof LocalStep) return endsWithElement(((TraversalParent) currentStep).getLocalChildren().get(0).getEndStep()); else if (!(currentStep instanceof FilterStep || currentStep instanceof SideEffectStep || currentStep instanceof IdentityStep || currentStep instanceof Barrier)) return false; currentStep = currentStep.getPreviousStep(); } return false; }
/** * 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; }
/** * Optimizes the given step if possible. Basically this method converts <code>.out()</code> to <code>.outE()</code> * and <code>.values()</code> to <code>.properties()</code>. * * @param traversal the traversal that holds the given step * @param step the step to replace */ private static void optimizeStep(final Traversal.Admin traversal, final Step step) { final Step newStep; if (step instanceof VertexStep) { final VertexStep vs = (VertexStep) step; newStep = new VertexStep<>(traversal, Edge.class, vs.getDirection(), vs.getEdgeLabels()); } else if (step instanceof PropertiesStep) { final PropertiesStep ps = (PropertiesStep) step; newStep = new PropertiesStep(traversal, PropertyType.PROPERTY, ps.getPropertyKeys()); } else { return; } TraversalHelper.replaceStep(step, newStep, traversal); }
/** * Optimizes the given edge-emitting step and the vertex-emitting step by replacing them with a single * vertex-emitting step. * * @param traversal the traversal that holds the given steps * @param step1 the edge-emitting step to replace * @param step2 the vertex-emitting step to replace */ private static void optimizeSteps(final Traversal.Admin traversal, final VertexStep step1, final Step step2) { final Step newStep = new VertexStep(traversal, Vertex.class, step1.getDirection(), step1.getEdgeLabels()); for (final String label : (Iterable<String>) step2.getLabels()) { newStep.addLabel(label); } TraversalHelper.replaceStep(step1, newStep, traversal); traversal.removeStep(step2); }
final VertexStep<Edge> newVertexStep = new VertexStep<>(traversal, Edge.class, previousStep.getDirection(), edgeLabels.toArray(new String[edgeLabels.size()])); TraversalHelper.replaceStep(previousStep, newVertexStep, traversal); TraversalHelper.copyLabels(previousStep, newVertexStep, false);
@Override public void apply(final Traversal.Admin<?, ?> traversal) { final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // best guess at what the graph will be as its dynamically determined for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) { final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone(); if (!computerTraversal.isLocked()) computerTraversal.applyStrategies(); /// boolean doesMessagePass = TraversalHelper.hasStepOfAssignableClassRecursively(Scope.global, MULTI_ITERATION_CLASSES, computerTraversal); if (!doesMessagePass) { for (final VertexStep vertexStep : TraversalHelper.getStepsOfAssignableClassRecursively(Scope.global, VertexStep.class, computerTraversal)) { if (vertexStep.returnsVertex() || !vertexStep.getDirection().equals(Direction.OUT)) { // in-edges require message pass in OLAP doesMessagePass = true; break; } } } if (!doesMessagePass && !MessagePassingReductionStrategy.endsWithElement(computerTraversal.getEndStep()) && !(computerTraversal.getTraverserRequirements().contains(TraverserRequirement.LABELED_PATH) || // TODO: remove this when dynamic detachment is available in 3.3.0 computerTraversal.getTraverserRequirements().contains(TraverserRequirement.PATH))) { // TODO: remove this when dynamic detachment is available in 3.3.0 step.setComputer(step.getComputer() // if no message passing, don't partition the loaded graph .configure(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, true) // if no message passing, don't cache the loaded graph .configure(Constants.GREMLIN_SPARK_SKIP_GRAPH_CACHE, true)); } } }
TraversalHelper.insertAfterStep(new TraversalFilterStep<>(traversal, (Traversal) this.vertexCriterion.clone()), step, traversal); } else { final VertexStep<Edge> someEStep = new VertexStep<>(traversal, Edge.class, step.getDirection(), step.getEdgeLabels()); final boolean addsPathRequirement; final Step<Edge, Vertex> someVStep = (addsPathRequirement = step.getDirection() == Direction.BOTH) ? new EdgeOtherVertexStep(traversal) : new EdgeVertexStep(traversal, step.getDirection().opposite());
private static Direction getDirection(Traversal.Admin<Vertex, Edge> incidentTraversal) { VertexStep<?> step = TraversalHelper.getLastStepOfAssignableClass(VertexStep.class, incidentTraversal).get(); return step.getDirection(); } }
private static Direction getDirection(final Traversal.Admin<Vertex, Edge> incidentTraversal) { final VertexStep step = TraversalHelper.getLastStepOfAssignableClass(VertexStep.class, incidentTraversal).get(); return step.getDirection(); } }
public TitanVertexStep(VertexStep<E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.getDirection(), originalStep.getEdgeLabels()); originalStep.getLabels().forEach(this::addLabel); this.hasContainers = new ArrayList<>(); this.limit = Query.NO_LIMIT; }
@SuppressWarnings("unchecked") public HBaseVertexStep(final VertexStep<E> originalVertexStep) { super(originalVertexStep.getTraversal(), originalVertexStep.getReturnClass(), originalVertexStep.getDirection(), originalVertexStep.getEdgeLabels()); originalVertexStep.getLabels().forEach(this::addLabel); }