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);
}
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();
}
}
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;
}
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();
}
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;
}
Aggregations