Search in sources :

Example 26 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer 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 27 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer 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)

Example 28 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project titan by thinkaurelius.

the class TitanVertexStep method makeQuery.

public <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    query.labels(getEdgeLabels());
    query.direction(getDirection());
    for (HasContainer condition : hasContainers) {
        query.has(condition.getKey(), TitanPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT)
        query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
Also used : BasicVertexCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 29 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project unipop by unipop-graph.

the class DateFieldPropertySchema method toPredicate.

@Override
public PredicatesHolder toPredicate(HasContainer has) {
    if (has.getPredicate() instanceof ConnectiveP) {
        List<P> predicates = ((ConnectiveP) has.getPredicate()).getPredicates();
        predicates.forEach(p -> {
            Object dateValue = p.getValue();
            Date parsedDate = fromDisplay(dateValue.toString());
            String formattedDate = toSource(parsedDate);
            p.setValue(formattedDate);
        });
        return PredicatesHolderFactory.predicate(new HasContainer(this.field, has.getPredicate()));
    }
    Object dateValue = has.getValue();
    Date parsedDate = fromDisplay(dateValue.toString());
    String formattedDate = toSource(parsedDate);
    P predicated = has.getPredicate().clone();
    predicated.setValue(formattedDate);
    return PredicatesHolderFactory.predicate(new HasContainer(this.field, predicated));
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) JSONObject(org.json.JSONObject)

Example 30 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project unipop by unipop-graph.

the class ConcatenateFieldPropertySchema method stringValueToPredicate.

private PredicatesHolder stringValueToPredicate(String value, HasContainer has, boolean collection) {
    String[] values = value.split(delimiter);
    if (values.length < schemas.size())
        return PredicatesHolderFactory.abort();
    Set<PredicatesHolder> predicates = new HashSet<>();
    for (int i = 0; i < schemas.size(); i++) {
        P predicate = has.getPredicate().clone();
        final Object currentValue = values[i];
        P p = new P(predicate.getBiPredicate(), collection ? Arrays.asList(currentValue) : currentValue);
        PredicatesHolder predicatesHolder = schemas.get(i).toPredicates(PredicatesHolderFactory.predicate(new HasContainer(has.getKey(), p)));
        predicates.add(predicatesHolder);
    }
    return PredicatesHolderFactory.and(predicates);
}
Also used : P(org.apache.tinkerpop.gremlin.process.traversal.P) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) JSONObject(org.json.JSONObject)

Aggregations

HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)56 AndOrHasContainer (org.umlg.sqlg.sql.parse.AndOrHasContainer)13 P (org.apache.tinkerpop.gremlin.process.traversal.P)9 Collectors (java.util.stream.Collectors)7 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)6 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)6 FullText (org.umlg.sqlg.predicate.FullText)6 PredicatesHolder (org.unipop.query.predicates.PredicatesHolder)6 java.util (java.util)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 BiPredicate (java.util.function.BiPredicate)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)5 JSONObject (org.json.JSONObject)5 GraphStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep)4 BasicVertexCentricQueryBuilder (org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder)4 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)3 HasContainerHolder (org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder)3 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)3 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)3