private static final char processesPropertyType(Step step) { while (!(step instanceof EmptyStep)) { if (step instanceof FilterStep || step instanceof SideEffectStep) step = step.getPreviousStep(); else if (step instanceof GraphStep && ((GraphStep) step).returnsVertex()) return 'v'; else if (step instanceof EdgeVertexStep) return 'v'; else if (step instanceof VertexStep) return ((VertexStep) step).returnsVertex() ? 'v' : 'p'; else if (step instanceof PropertyMapStep || step instanceof PropertiesStep) return 'p'; else return 'x'; } return 'x'; }
/** * Checks whether a given step is optimizable or not. * * @param step the step to check * @return <code>true</code> if the step is optimizable, otherwise <code>false</code> */ private static boolean isOptimizable(final Step step) { return ((step instanceof VertexStep && ((VertexStep) step).returnsVertex()) || (step instanceof PropertiesStep && PropertyType.VALUE.equals(((PropertiesStep) step).getReturnType()))) && (step.getTraversal().getEndStep().getLabels().isEmpty() || step.getNextStep() instanceof CountGlobalStep); }
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; }
else if (step instanceof VertexStep) { if (state == 'u') return 'x'; state = ((VertexStep) step).returnsVertex() ? 'u' : 'e'; } else if (step instanceof EdgeVertexStep) { state = 'u';
@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)); } } }
private static final char processesPropertyType(Step step) { while (!(step instanceof EmptyStep)) { if (step instanceof FilterStep || step instanceof SideEffectStep) step = step.getPreviousStep(); else if (step instanceof GraphStep && ((GraphStep) step).returnsVertex()) return 'v'; else if (step instanceof EdgeVertexStep) return 'v'; else if (step instanceof VertexStep) return ((VertexStep) step).returnsVertex() ? 'v' : 'p'; else if (step instanceof PropertyMapStep || step instanceof PropertiesStep) return 'p'; else return 'x'; } return 'x'; }
/** * Checks whether a given step is optimizable or not. * * @param step the step to check * @return <code>true</code> if the step is optimizable, otherwise <code>false</code> */ private static boolean isOptimizable(final Step step) { return ((step instanceof VertexStep && ((VertexStep) step).returnsVertex()) || (step instanceof PropertiesStep && PropertyType.VALUE.equals(((PropertiesStep) step).getReturnType()))) && (step.getTraversal().getEndStep().getLabels().isEmpty() || step.getNextStep() instanceof CountGlobalStep); }
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; }
else if (step instanceof VertexStep) { if (state == 'u') return 'x'; state = ((VertexStep) step).returnsVertex() ? 'u' : 'e'; } else if (step instanceof EdgeVertexStep) { state = 'u';
public UniGraphVertexStep(VertexStep<E> vertexStep, UniGraph graph, ControllerManager controllerManager) { super(vertexStep.getTraversal(), graph); vertexStep.getLabels().forEach(this::addLabel); this.direction = vertexStep.getDirection(); this.returnClass = vertexStep.getReturnClass(); this.returnsVertex = vertexStep.returnsVertex(); if (vertexStep.getEdgeLabels().length > 0) { this.edgeLabels = vertexStep.getEdgeLabels(); HasContainer labelsPredicate = new HasContainer(T.label.getAccessor(), P.within(vertexStep.getEdgeLabels())); this.predicates = PredicatesHolderFactory.predicate(labelsPredicate); } else this.predicates = PredicatesHolderFactory.empty(); this.controllers = controllerManager.getControllers(SearchVertexQuery.SearchVertexController.class); this.deferredVertexControllers = controllerManager.getControllers(DeferredVertexQuery.DeferredVertexController.class); this.stepDescriptor = new StepDescriptor(this); limit = -1; }
@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)); } } }