org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder.
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: BaseStrategy.java From sqlg with MIT License | 6 votes |
private boolean isNotWithMultipleColumnValue(HasContainerHolder currentStep) { for (HasContainer h : currentStep.getHasContainers()) { P<?> predicate = h.getPredicate(); //noinspection unchecked if (predicate.getValue() instanceof ZonedDateTime || predicate.getValue() instanceof Period || predicate.getValue() instanceof Duration || (predicate.getValue() instanceof List && containsWithMultipleColumnValue((List<Object>) predicate.getValue())) || (predicate instanceof ConnectiveP && isConnectivePWithMultipleColumnValue((ConnectiveP) h.getPredicate()))) { return false; } } return true; }
Example #2
Source File: Neo4jGraphStepStrategy.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final Neo4jGraphStep<?, ?> neo4jGraphStep = new Neo4jGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, neo4jGraphStep, traversal); Step<?, ?> currentStep = neo4jGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(neo4jGraphStep, hasContainer)) neo4jGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #3
Source File: TinkerGraphStepStrategy.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (TraversalHelper.onGraphComputer(traversal)) return; for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal); Step<?, ?> currentStep = tinkerGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer)) tinkerGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #4
Source File: BitsyTraversalStrategy.java From bitsy with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final BitsyGraphStep<?, ?> bitsyGraphStep = new BitsyGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, bitsyGraphStep, traversal); Step<?, ?> currentStep = bitsyGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(bitsyGraphStep, hasContainer)) bitsyGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #5
Source File: TinkerGraphStepStrategy.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (TraversalHelper.onGraphComputer(traversal)) return; for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal); Step<?, ?> currentStep = tinkerGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer)) tinkerGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #6
Source File: HasStepFolder.java From grakn with GNU Affero General Public License v3.0 | 6 votes |
static void foldInHasContainer(HasStepFolder janusgraphStep, Traversal.Admin<?, ?> traversal, Traversal<?, ?> rootTraversal) { Step<?, ?> currentStep = janusgraphStep.getNextStep(); while (true) { if (currentStep instanceof OrStep && janusgraphStep instanceof JanusGraphStep) { for (Traversal.Admin<?, ?> child : ((OrStep<?>) currentStep).getLocalChildren()) { if (!validFoldInHasContainer(child.getStartStep(), false)) { return; } } ((OrStep<?>) currentStep).getLocalChildren().forEach(t -> localFoldInHasContainer(janusgraphStep, t.getStartStep(), t, rootTraversal)); traversal.removeStep(currentStep); } else if (currentStep instanceof HasContainerHolder) { Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers().stream().map(c -> JanusGraphPredicate.Converter.convert(c)).collect(Collectors.toList()); if (validFoldInHasContainer(currentStep, true)) { janusgraphStep.addAll(containers); currentStep.getLabels().forEach(janusgraphStep::addLabel); traversal.removeStep(currentStep); } } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof NoOpBarrierStep) && !(currentStep instanceof HasContainerHolder)) { break; } currentStep = currentStep.getNextStep(); } }
Example #7
Source File: HasStepFolder.java From grakn with GNU Affero General Public License v3.0 | 6 votes |
static void localFoldInHasContainer(HasStepFolder janusgraphStep, Step<?, ?> tinkerpopStep, Traversal.Admin<?, ?> traversal, Traversal<?, ?> rootTraversal) { Step<?, ?> currentStep = tinkerpopStep; while (true) { if (currentStep instanceof HasContainerHolder) { Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers().stream().map(c -> JanusGraphPredicate.Converter.convert(c)).collect(Collectors.toList()); List<HasContainer> hasContainers = janusgraphStep.addLocalAll(containers); currentStep.getLabels().forEach(janusgraphStep::addLabel); traversal.removeStep(currentStep); currentStep = foldInOrder(janusgraphStep, currentStep, traversal, rootTraversal, janusgraphStep instanceof JanusGraphStep && ((JanusGraphStep) janusgraphStep).returnsVertex(), hasContainers); foldInRange(janusgraphStep, currentStep, traversal, hasContainers); } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof NoOpBarrierStep)) { break; } currentStep = currentStep.getNextStep(); } }
Example #8
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 6 votes |
public static void extractHasContainer(HugeGraphStep<?, ?> newStep, Traversal.Admin<?, ?> traversal) { Step<?, ?> step = newStep; do { step = step.getNextStep(); if (step instanceof HasStep) { HasContainerHolder holder = (HasContainerHolder) step; for (HasContainer has : holder.getHasContainers()) { if (!GraphStep.processHasContainerIds(newStep, has)) { newStep.addHasContainer(has); } } TraversalHelper.copyLabels(step, step.getPreviousStep(), false); traversal.removeStep(step); } } while (step instanceof HasStep || step instanceof NoOpBarrierStep); }
Example #9
Source File: HBaseVertexStepStrategy.java From hgraphdb with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final VertexStep originalVertexStep : TraversalHelper.getStepsOfClass(VertexStep.class, traversal)) { final HBaseVertexStep<?> hbaseVertexStep = new HBaseVertexStep<>(originalVertexStep); TraversalHelper.replaceStep(originalVertexStep, hbaseVertexStep, traversal); Step<?, ?> currentStep = hbaseVertexStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { hbaseVertexStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #10
Source File: HBaseGraphStepStrategy.java From hgraphdb with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final HBaseGraphStep<?, ?> hbaseGraphStep = new HBaseGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, hbaseGraphStep, traversal); Step<?, ?> currentStep = hbaseGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(hbaseGraphStep, hasContainer)) hbaseGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #11
Source File: HasStepFolder.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
public static void foldInHasContainer(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal) { Step<?, ?> currentStep = titanStep.getNextStep(); while (true) { if (currentStep instanceof HasContainerHolder) { Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers(); if (validTitanHas(containers)) { titanStep.addAll(containers); currentStep.getLabels().forEach(titanStep::addLabel); traversal.removeStep(currentStep); } } else if (currentStep instanceof IdentityStep) { // do nothing, has no impact } else { break; } currentStep = currentStep.getNextStep(); } }
Example #12
Source File: HasStepFolder.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
static boolean validFoldInHasContainer(Step<?, ?> tinkerpopStep, boolean defaultValue) { Step<?, ?> currentStep = tinkerpopStep; Boolean toReturn = null; while (!(currentStep instanceof EmptyStep)) { if (currentStep instanceof HasContainerHolder) { Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers(); toReturn = toReturn == null ? validJanusGraphHas(containers) : toReturn && validJanusGraphHas(containers); } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof NoOpBarrierStep) && !(currentStep instanceof RangeGlobalStep) && !(currentStep instanceof OrderGlobalStep)) { toReturn = toReturn != null && (toReturn && defaultValue); break; } currentStep = currentStep.getNextStep(); } return Boolean.TRUE.equals(toReturn); }
Example #13
Source File: ElementIdStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { TraversalHelper.getStepsOfAssignableClass(HasStep.class, traversal).stream() .filter(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).getKey().equals(T.id.getAccessor())) .forEach(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).setKey(this.idPropertyKey)); if (traversal.getStartStep() instanceof GraphStep) { final GraphStep graphStep = (GraphStep) traversal.getStartStep(); // only need to apply the custom id if ids were assigned - otherwise we want the full iterator. // note that it is then only necessary to replace the step if the id is a non-element. other tests // in the suite validate that items in getIds() is uniform so it is ok to just test the first item // in the list. if (graphStep.getIds().length > 0 && !(graphStep.getIds()[0] instanceof Element)) { if (graphStep instanceof HasContainerHolder) ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, P.within(Arrays.asList(graphStep.getIds())))); else TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, P.within(Arrays.asList(graphStep.getIds())))), graphStep, traversal); graphStep.clearIds(); } } TraversalHelper.getStepsOfAssignableClass(IdStep.class, traversal).stream().forEach(step -> { TraversalHelper.replaceStep(step, new PropertiesStep(traversal, PropertyType.VALUE, idPropertyKey), traversal); }); // in each case below, determine if the T.id is present and if so, replace T.id with the idPropertyKey or if // it is not present then shove it in there and generate an id traversal.getSteps().forEach(step -> { if (step instanceof AddVertexStep || step instanceof AddVertexStartStep || step instanceof AddEdgeStep) { final Parameterizing parameterizing = (Parameterizing) step; if (parameterizing.getParameters().contains(T.id)) parameterizing.getParameters().rename(T.id, this.idPropertyKey); else if (!parameterizing.getParameters().contains(this.idPropertyKey)) parameterizing.getParameters().set(null, this.idPropertyKey, idMaker.get()); } }); }
Example #14
Source File: HasStepFolder.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
static void foldInIds(HasStepFolder janusgraphStep, Traversal.Admin<?, ?> traversal) { Step<?, ?> currentStep = janusgraphStep.getNextStep(); while (true) { if (currentStep instanceof HasContainerHolder) { HasContainerHolder hasContainerHolder = (HasContainerHolder) currentStep; GraphStep graphStep = (GraphStep) janusgraphStep; // HasContainer collection that we get back is immutable so we keep track of which containers // need to be deleted after they've been folded into the JanusGraphStep and then remove them from their // step using HasContainer.removeHasContainer List<HasContainer> removableHasContainers = new ArrayList<>(); Set<String> stepLabels = currentStep.getLabels(); hasContainerHolder.getHasContainers().forEach(hasContainer -> { if (GraphStep.processHasContainerIds(graphStep, hasContainer)) { stepLabels.forEach(janusgraphStep::addLabel); // this has container is no longer needed because its ids will be folded into the JanusGraphStep removableHasContainers.add(hasContainer); } }); if (!removableHasContainers.isEmpty()) { removableHasContainers.forEach(hasContainerHolder::removeHasContainer); } // if all has containers have been removed, the current step can be removed if (hasContainerHolder.getHasContainers().isEmpty()) { traversal.removeStep(currentStep); } // } else if (currentStep instanceof IdentityStep) { // // do nothing, has no impact // } else if (currentStep instanceof NoOpBarrierStep) { // // do nothing, has no impact } else { break; } currentStep = currentStep.getNextStep(); } }
Example #15
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 5 votes |
public static void extractHasContainer(HugeVertexStep<?> newStep, Traversal.Admin<?, ?> traversal) { Step<?, ?> step = newStep; do { if (step instanceof HasStep) { HasContainerHolder holder = (HasContainerHolder) step; for (HasContainer has : holder.getHasContainers()) { newStep.addHasContainer(has); } TraversalHelper.copyLabels(step, step.getPreviousStep(), false); traversal.removeStep(step); } step = step.getNextStep(); } while (step instanceof HasStep || step instanceof NoOpBarrierStep); }
Example #16
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 4 votes |
public static void convHasStep(HugeGraph graph, HasStep<?> step) { HasContainerHolder holder = step; for (HasContainer has : holder.getHasContainers()) { convPredicateValue(graph, has); } }
Example #17
Source File: TraversalHelper.java From tinkerpop with Apache License 2.0 | 3 votes |
/** * Used to left-fold a {@link HasContainer} to a {@link HasContainerHolder} if it exists. Else, append a {@link HasStep}. * * @param traversal the traversal to fold or append. * @param hasContainer the container to add left or append. * @param <T> the traversal type * @return the has container folded or appended traversal */ public static <T extends Traversal.Admin<?, ?>> T addHasContainer(final T traversal, final HasContainer hasContainer) { if (traversal.getEndStep() instanceof HasContainerHolder) { ((HasContainerHolder) traversal.getEndStep()).addHasContainer(hasContainer); return traversal; } else return (T) traversal.addStep(new HasStep<>(traversal, hasContainer)); }