Search in sources :

Example 11 with Element

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);
}
Also used : Element(org.apache.tinkerpop.gremlin.structure.Element) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) JanusGraphElement(org.janusgraph.core.JanusGraphElement)

Example 12 with Element

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);
}
Also used : Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) HashMap(java.util.HashMap) Var(ai.grakn.graql.Var) Element(org.apache.tinkerpop.gremlin.structure.Element)

Example 13 with Element

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();
}
Also used : java.util(java.util) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) AddVertexQuery(org.unipop.query.mutation.AddVertexQuery) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SimpleController(org.unipop.query.controller.SimpleController) T(org.apache.tinkerpop.gremlin.structure.T) Maps(com.google.common.collect.Maps) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) Collectors(java.util.stream.Collectors) AddEdgeQuery(org.unipop.query.mutation.AddEdgeQuery) Element(org.apache.tinkerpop.gremlin.structure.Element) Stream(java.util.stream.Stream) RemoveQuery(org.unipop.query.mutation.RemoveQuery) NotImplementedException(org.apache.commons.lang.NotImplementedException) ElementSchema(org.unipop.schema.element.ElementSchema) UniGraph(org.unipop.structure.UniGraph) PropertyQuery(org.unipop.query.mutation.PropertyQuery) UniEdge(org.unipop.structure.UniEdge) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) SearchQuery(org.unipop.query.search.SearchQuery) Edge(org.apache.tinkerpop.gremlin.structure.Edge) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator)

Example 14 with Element

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;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) Element(org.apache.tinkerpop.gremlin.structure.Element) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 15 with Element

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;
}
Also used : Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) Element(org.apache.tinkerpop.gremlin.structure.Element)

Aggregations

Element (org.apache.tinkerpop.gremlin.structure.Element)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)10 Traverser (org.apache.tinkerpop.gremlin.process.traversal.Traverser)8 SqlgTraverser (org.umlg.sqlg.structure.SqlgTraverser)6 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)4 Edge (org.apache.tinkerpop.gremlin.structure.Edge)4 Test (org.junit.Test)4 BaseTest (org.umlg.sqlg.test.BaseTest)4 Var (ai.grakn.graql.Var)2 IOException (java.io.IOException)2 java.util (java.util)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)2 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 ConfigElement (org.janusgraph.diskstorage.configuration.ConfigElement)2 Concept (ai.grakn.concept.Concept)1 ConceptId (ai.grakn.concept.ConceptId)1 SchemaConcept (ai.grakn.concept.SchemaConcept)1 Match (ai.grakn.graql.Match)1