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