Search in sources :

Example 1 with ConnectiveJanusPredicate

use of org.janusgraph.graphdb.predicate.ConnectiveJanusPredicate 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 ConnectiveJanusPredicate

use of org.janusgraph.graphdb.predicate.ConnectiveJanusPredicate in project janusgraph by JanusGraph.

the class JanusGraphPredicateUtils method convert.

public static List<Object> convert(final ConnectiveP<?> predicate, final ConnectiveJanusPredicate connectivePredicate) {
    final List<Object> toReturn = new ArrayList<>();
    for (final P<?> p : predicate.getPredicates()) {
        if (p instanceof ConnectiveP) {
            final ConnectiveJanusPredicate subPredicate = instanceConnectiveJanusPredicate(p);
            toReturn.add(convert((ConnectiveP<?>) p, subPredicate));
            connectivePredicate.add(subPredicate);
        } else if (p.getBiPredicate() instanceof Text) {
            Text text = (Text) p.getBiPredicate();
            connectivePredicate.add(new TinkerPopTextWrappingPredicate(text));
            toReturn.add(p.getValue());
        } else {
            connectivePredicate.add(JanusGraphPredicateUtils.convert(p.getBiPredicate()));
            toReturn.add(p.getValue());
        }
    }
    return toReturn;
}
Also used : ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) ArrayList(java.util.ArrayList) Text(org.apache.tinkerpop.gremlin.process.traversal.Text) TinkerPopTextWrappingPredicate(org.janusgraph.core.attribute.TinkerPopTextWrappingPredicate) ConnectiveJanusPredicate(org.janusgraph.graphdb.predicate.ConnectiveJanusPredicate)

Aggregations

ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)2 ConnectiveJanusPredicate (org.janusgraph.graphdb.predicate.ConnectiveJanusPredicate)2 ArrayList (java.util.ArrayList)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 Text (org.apache.tinkerpop.gremlin.process.traversal.Text)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 OrStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep)1 RangeGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)1 OrP (org.apache.tinkerpop.gremlin.process.traversal.util.OrP)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 TinkerPopTextWrappingPredicate (org.janusgraph.core.attribute.TinkerPopTextWrappingPredicate)1 HasStepFolder (org.janusgraph.graphdb.tinkerpop.optimize.step.HasStepFolder)1 JanusGraphStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphStep)1