use of org.apache.tinkerpop.gremlin.process.traversal.step.filter.WherePredicateStep in project grakn by graknlabs.
the class JanusPreviousPropertyStepStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
// Retrieve all graph (`V()`) steps - this is the step the strategy should replace
List<GraphStep> graphSteps = TraversalHelper.getStepsOfAssignableClass(GraphStep.class, traversal);
for (GraphStep graphStep : graphSteps) {
if (!(graphStep.getNextStep() instanceof TraversalFilterStep))
continue;
TraversalFilterStep<Vertex> filterStep = (TraversalFilterStep<Vertex>) graphStep.getNextStep();
// Retrieve the filter steps e.g. `__.properties(a).where(P.eq(b))`
List<Step> steps = stepsFromFilterStep(filterStep);
if (steps.size() < 2)
continue;
// This is `properties(a)`
Step propertiesStep = steps.get(0);
// This is `filter(__.where(P.eq(b)))`
Step whereStep = steps.get(1);
// Get the property key `a`
if (!(propertiesStep instanceof PropertiesStep))
continue;
Optional<String> propertyKey = propertyFromPropertiesStep((PropertiesStep<Vertex>) propertiesStep);
if (!propertyKey.isPresent())
continue;
// Get the step label `b`
if (!(whereStep instanceof WherePredicateStep))
continue;
Optional<String> label = labelFromWhereEqPredicate((WherePredicateStep<Vertex>) whereStep);
if (!label.isPresent())
continue;
executeStrategy(traversal, graphStep, filterStep, propertyKey.get(), label.get());
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.filter.WherePredicateStep in project sqlg by pietermartin.
the class SqlgWhereStrategy method apply.
@SuppressWarnings("resource")
@Override
public void apply(Admin<?, ?> traversal) {
if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
return;
}
SqlgGraph sqlgGraph = (SqlgGraph) traversal.getGraph().get();
// The query will read from the cache if this is for a cached vertex
if (sqlgGraph.features().supportsBatchMode() && sqlgGraph.tx().isInNormalBatchMode()) {
sqlgGraph.tx().flush();
}
List<Step<?, ?>> steps = new ArrayList(traversal.asAdmin().getSteps());
ListIterator<Step<?, ?>> stepIterator = steps.listIterator();
// get all steps per label
Map<String, Object> stepsByLabel = new HashMap<>();
stepIterator = steps.listIterator();
Step<?, ?> previous = null;
int idx = 0;
while (stepIterator.hasNext()) {
Step<?, ?> step = stepIterator.next();
captureLabels(step, stepsByLabel);
if (step instanceof WherePredicateStep<?>) {
WherePredicateStep<?> wps = (WherePredicateStep<?>) step;
if (wps.getPredicate().isPresent() && wps.getPredicate().get().getBiPredicate() instanceof FullText) {
Object referTo = previous;
if (wps.getStartKey().isPresent()) {
referTo = stepsByLabel.get(wps.getStartKey().get());
}
if (referTo instanceof SqlgGraphStep<?, ?>) {
SqlgGraphStep<?, ?> sgs = (SqlgGraphStep<?, ?>) referTo;
if (sgs.getReplacedSteps().size() > 0) {
referTo = sgs.getReplacedSteps().get(sgs.getReplacedSteps().size() - 1);
}
}
if (referTo instanceof ReplacedStep<?, ?>) {
ReplacedStep<?, ?> rs = (ReplacedStep<?, ?>) referTo;
rs.addHasContainer(new HasContainer("__dummy__", wps.getPredicate().get()));
traversal.removeStep(idx);
}
}
}
previous = step;
idx++;
}
}
Aggregations