Search in sources :

Example 1 with JanusGraphStep

use of org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep in project janusgraph by JanusGraph.

the class JanusGraphStepStrategyTest method g_V.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static GraphTraversal.Admin<?, ?> g_V(final Object... hasKeyValues) {
    final GraphTraversal.Admin<?, ?> traversal = new DefaultGraphTraversal<>();
    final JanusGraphStep<Vertex, Vertex> graphStep = new JanusGraphStep<>(new GraphStep<>(traversal, Vertex.class, true));
    for (int i = 0; i < hasKeyValues.length; i++) {
        if (hasKeyValues[i].equals(T.id)) {
            graphStep.addIds(Collections.singletonList(hasKeyValues[i + 1]));
            i++;
        } else if (hasKeyValues[i] instanceof HasStepFolder.OrderEntry) {
            final HasStepFolder.OrderEntry orderEntry = (HasStepFolder.OrderEntry) hasKeyValues[i];
            graphStep.orderBy(orderEntry.key, orderEntry.order);
        } else if (hasKeyValues[i] instanceof DefaultGraphTraversal && ((DefaultGraphTraversal) hasKeyValues[i]).getStartStep() instanceof OrStep) {
            OrStep<?> orStep = (OrStep<?>) ((DefaultGraphTraversal) hasKeyValues[i]).getStartStep();
            for (final Traversal.Admin<?, ?> child : orStep.getLocalChildren()) {
                final JanusGraphStep<Vertex, Vertex> localGraphStep = ((JanusGraphStep<Vertex, Vertex>) ((DefaultGraphTraversal) child).getStartStep());
                graphStep.addLocalHasContainersConvertingAndPContainers(orStep, localGraphStep.getHasContainers());
                localGraphStep.getOrders().forEach(orderEntry -> graphStep.localOrderBy(orStep, localGraphStep.getHasContainers(), orderEntry.key, orderEntry.order));
                graphStep.setLocalLimit(orStep, localGraphStep.getHasContainers(), localGraphStep.getLowLimit(), localGraphStep.getHighLimit());
            }
        } else if (hasKeyValues[i] instanceof DefaultGraphTraversal && ((DefaultGraphTraversal) hasKeyValues[i]).getStartStep() instanceof RangeGlobalStep) {
            final RangeGlobalStep range = (RangeGlobalStep) ((DefaultGraphTraversal) hasKeyValues[i]).getStartStep();
            graphStep.setLimit((int) range.getLowRange(), (int) range.getHighRange());
        } else if (i < hasKeyValues.length - 1 && hasKeyValues[i + 1] instanceof ConnectiveP) {
            final ConnectiveJanusPredicate connectivePredicate = JanusGraphPredicateUtils.instanceConnectiveJanusPredicate((ConnectiveP) hasKeyValues[i + 1]);
            graphStep.addHasContainer(new HasContainer((String) hasKeyValues[i], new P<>(connectivePredicate, JanusGraphPredicateUtils.convert(((ConnectiveP<?>) hasKeyValues[i + 1]), connectivePredicate))));
            i++;
        } else {
            graphStep.addHasContainer(new HasContainer((String) hasKeyValues[i], (P) hasKeyValues[i + 1]));
            i++;
        }
    }
    return traversal.addStep(graphStep);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) ConnectiveJanusPredicate(org.janusgraph.graphdb.predicate.ConnectiveJanusPredicate) AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) JanusGraphStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep) OrStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) HasStepFolder(org.janusgraph.graphdb.tinkerpop.optimize.step.HasStepFolder)

Example 2 with JanusGraphStep

use of org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep in project janusgraph by JanusGraph.

the class JanusGraphStepStrategyTest method shouldTriggerHasContainerSplit.

@Test
public void shouldTriggerHasContainerSplit() {
    final GraphTraversal.Admin<?, ?> traversal = new DefaultGraphTraversal<>();
    final JanusGraphStep<Vertex, Vertex> graphStep = new JanusGraphStep<>(new GraphStep<>(traversal, Vertex.class, true));
    graphStep.addHasContainer(new HasContainer("age", P.between("1", "123")));
    assertEquals(2, graphStep.getHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) JanusGraphStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 JanusGraphStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep)2 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 OrStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep)1 RangeGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)1 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)1 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)1 OrP (org.apache.tinkerpop.gremlin.process.traversal.util.OrP)1 ConnectiveJanusPredicate (org.janusgraph.graphdb.predicate.ConnectiveJanusPredicate)1 HasStepFolder (org.janusgraph.graphdb.tinkerpop.optimize.step.HasStepFolder)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1