use of org.apache.tinkerpop.gremlin.structure.Element in project janusgraph by JanusGraph.
the class JanusGraphBaseTest method verifyElementOrder.
public static void verifyElementOrder(Iterator<? extends Element> elements, String key, Order order, int expectedCount) {
Comparable previous = null;
int count = 0;
while (elements.hasNext()) {
final Element element = elements.next();
final Comparable current = element.value(key);
if (previous != null) {
final int cmp = previous.compareTo(current);
assertTrue(order == Order.ASC ? cmp <= 0 : cmp >= 0, previous + " <> " + current + " @ " + count);
}
previous = current;
count++;
}
assertEquals(expectedCount, count);
}
use of org.apache.tinkerpop.gremlin.structure.Element in project grakn by graknlabs.
the class MatchBase method makeResults.
/**
* @param vars set of variables of interest
* @param tx the graph to get results from
* @param elements a map of vertices and edges where the key is the variable name
* @return a map of concepts where the key is the variable name
*/
private static Optional<Map<Var, Concept>> makeResults(Set<Var> vars, EmbeddedGraknTx<?> tx, Map<String, Element> elements) {
Map<Var, Concept> map = new HashMap<>();
for (Var var : vars) {
Element element = elements.get(var.name());
if (element == null) {
throw GraqlQueryException.unexpectedResult(var);
} else {
Concept concept = buildConcept(tx, element);
map.put(var, concept);
}
}
return Optional.of(map);
}
use of org.apache.tinkerpop.gremlin.structure.Element in project unipop by unipop-graph.
the class VirtualController method search.
@Override
public <E extends Element> Iterator<E> search(SearchQuery<E> uniQuery) {
if (uniQuery.getReturnType() != Vertex.class)
return EmptyIterator.instance();
PredicatesHolder predicates = uniQuery.getPredicates();
List<? extends VirtualVertexSchema> filteredSchemas = vertexSchemas.stream().filter(schema -> !schema.toPredicates(predicates).getClause().equals(PredicatesHolder.Clause.Abort)).collect(Collectors.toList());
Optional<HasContainer> ids = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.id.getAccessor())).findFirst();
Optional<HasContainer> labels = predicates.getPredicates().stream().filter(has -> has.getKey().equals(T.label.getAccessor())).findFirst();
if (!ids.isPresent() || !labels.isPresent()) {
return EmptyIterator.instance();
}
ArrayList<Map<String, Object>> elements = new ArrayList<>();
Object idObject = ids.get().getValue();
Collection<Object> idsCol = idObject instanceof Collection ? ((Collection) idObject) : Collections.singleton(idObject);
Object labelObject = labels.get().getValue();
Collection<Object> labelCol = labelObject instanceof Collection ? ((Collection) labelObject) : Collections.singleton(labelObject);
idsCol.forEach(id -> labelCol.forEach(label -> elements.add(createElement(id, label.toString()))));
return (Iterator<E>) elements.stream().flatMap(fields -> filteredSchemas.stream().flatMap(schema -> Stream.of(schema.createElement(fields)))).filter(v -> v != null).iterator();
}
use of org.apache.tinkerpop.gremlin.structure.Element in project cypher-for-gremlin by opencypher.
the class CustomFunction method finalizeElements.
private static Object finalizeElements(Object o) {
HashMap<Object, Object> result = new HashMap<>();
if (Tokens.NULL.equals(o)) {
return Tokens.NULL;
}
Element element = (Element) o;
result.put(ReturnProperties.ID, element.id());
result.put(ReturnProperties.LABEL, element.label());
element.properties().forEachRemaining(e -> result.put(e.key(), e.value()));
if (o instanceof Vertex) {
result.put(ReturnProperties.TYPE, ReturnProperties.NODE_TYPE);
} else {
Edge edge = (Edge) o;
result.put(ReturnProperties.TYPE, ReturnProperties.RELATIONSHIP_TYPE);
result.put(ReturnProperties.INV, edge.inVertex().id());
result.put(ReturnProperties.OUTV, edge.outVertex().id());
}
return result;
}
use of org.apache.tinkerpop.gremlin.structure.Element in project sqlg by pietermartin.
the class SqlgRepeatStepBarrier method doUntilBarrier.
private boolean doUntilBarrier(SqlgExpandableStepIterator<S> starts, List<Iterator<Traverser.Admin<S>>> toReturn, Multimap<String, Traverser.Admin<S>> startRecordIds) {
boolean foundSomething = false;
while (starts.hasNext()) {
foundSomething = true;
Traverser.Admin<S> cachedStart = starts.next();
cachedStart.incrLoops(this.getId());
List<Object> startObjects = cachedStart.path().objects();
StringBuilder recordIdConcatenated = new StringBuilder();
for (Object startObject : startObjects) {
if (startObject instanceof Element) {
Element e = (Element) startObject;
recordIdConcatenated.append(e.id().toString());
} else {
recordIdConcatenated.append(startObject.toString());
}
}
startRecordIds.put(recordIdConcatenated.toString(), cachedStart);
this.untilTraversal.addStart(cachedStart);
}
while (this.untilTraversal.hasNext()) {
Traverser.Admin<?> filterTraverser = this.untilTraversal.nextTraverser();
List<Object> filterTraverserObjects = filterTraverser.path().objects();
String startId = "";
for (Object filteredTraverserObject : filterTraverserObjects) {
if (filteredTraverserObject instanceof Element) {
Element e = (Element) filteredTraverserObject;
startId += e.id().toString();
} else {
startId += filteredTraverserObject.toString();
}
if (startRecordIds.containsKey(startId)) {
Collection<Traverser.Admin<S>> startsToReturn = startRecordIds.get(startId);
for (Traverser.Admin<S> start : startsToReturn) {
start.resetLoops();
toReturn.add(IteratorUtils.of(start));
}
startRecordIds.removeAll(startId);
}
if (startRecordIds.isEmpty()) {
break;
}
}
}
return foundSomething;
}
Aggregations