Search in sources :

Example 6 with HasContainer

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

the class VertexSchema method toPredicates.

/**
 * Receives a list of vertices and converts them to predicates
 * @param vertices A list of vertices
 * @return Predicate holder
 */
default PredicatesHolder toPredicates(List<? extends Vertex> vertices) {
    if (vertices == null || vertices.size() == 0)
        return PredicatesHolderFactory.abort();
    HashSet<PredicatesHolder> predicates = new HashSet<>();
    vertices.stream().collect(Collectors.groupingBy(Vertex::label)).forEach((label, labelVertices) -> {
        HasContainer labelPredicate = new HasContainer(T.label.getAccessor(), P.eq(label));
        HasContainer ids = new HasContainer(T.id.getAccessor(), P.within(labelVertices.stream().map(Vertex::id).collect(Collectors.toSet())));
        PredicatesHolder labelPredicates = PredicatesHolderFactory.and(ids, labelPredicate);
        PredicatesHolder toPredicates = toPredicates(labelPredicates);
        predicates.add(toPredicates);
    });
    return PredicatesHolderFactory.or(predicates);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniVertex(org.unipop.structure.UniVertex) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 7 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.

the class SqlgRepeatStepBarrier method test.

public <S, E> boolean test(final Traverser.Admin<S> traverser, final Traversal.Admin<S, E> traversal) {
    if (this.untilHasContainer != null) {
        Element e = (Element) traverser.get();
        return this.untilHasContainer.getPredicate().test(e.value(this.untilHasContainer.getKey()));
    }
    if (traversal.getSteps().size() == 1 && traversal.getSteps().get(0) instanceof HasStep) {
        if (this.untilHasContainers == null) {
            HasStep hasStep = (HasStep) traversal.getSteps().get(0);
            this.untilHasContainers = hasStep.getHasContainers();
            if (this.untilHasContainers.size() == 1) {
                this.untilHasContainer = this.untilHasContainers.get(0);
                Element e = (Element) traverser.get();
                return this.untilHasContainer.getPredicate().test(e.value(this.untilHasContainer.getKey()));
            }
        }
        for (HasContainer hasContainer : this.untilHasContainers) {
            if (!hasContainer.test((Element) traverser.get())) {
                return false;
            }
        }
        return true;
    } else {
        final Traverser.Admin<S> split = traverser.split();
        split.setSideEffects(traversal.getSideEffects());
        split.setBulk(1l);
        traversal.reset();
        traversal.addStart(split);
        // filter
        return traversal.hasNext();
    }
}
Also used : HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) Element(org.apache.tinkerpop.gremlin.structure.Element) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 8 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.

the class BaseStrategy method optimizeInside.

private List<HasContainer> optimizeInside(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
    List<HasContainer> result = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainerKeyNotIdOrLabel(hasContainer) && hasContainer.getPredicate() instanceof AndP) {
            AndP<?> andP = (AndP) hasContainer.getPredicate();
            List<? extends P<?>> predicates = andP.getPredicates();
            if (predicates.size() == 2) {
                if (predicates.get(0).getBiPredicate() == Compare.gt && predicates.get(1).getBiPredicate() == Compare.lt) {
                    replacedStep.addHasContainer(hasContainer);
                    result.add(hasContainer);
                }
            }
        }
    }
    return result;
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

Example 9 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.

the class BaseStrategy method addHasContainerForIds.

void addHasContainerForIds(SqlgGraphStep sqlgGraphStep) {
    HasContainer idHasContainer = new HasContainer(T.id.getAccessor(), P.within(sqlgGraphStep.getIds()));
    this.currentReplacedStep.addIdHasContainer(idHasContainer);
    sqlgGraphStep.clearIds();
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

Example 10 with HasContainer

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer in project sqlg by pietermartin.

the class BaseStrategy method optimizeWithInOut.

private List<HasContainer> optimizeWithInOut(ReplacedStep<?, ?> replacedStep, List<HasContainer> hasContainers) {
    List<HasContainer> result = new ArrayList<>();
    for (HasContainer hasContainer : hasContainers) {
        if (hasContainerKeyNotIdOrLabel(hasContainer) && (hasContainer.getBiPredicate() == Contains.without || hasContainer.getBiPredicate() == Contains.within)) {
            replacedStep.addHasContainer(hasContainer);
            result.add(hasContainer);
        }
    }
    return result;
}
Also used : HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AndOrHasContainer(org.umlg.sqlg.sql.parse.AndOrHasContainer)

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