Search in sources :

Example 1 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project orientdb by orientechnologies.

the class TestDirtyTrackingTreeRidBagRemote method test.

@Test
public void test() {
    final int max = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
    OrientGraph graph = new OrientGraph("remote:localhost:3064/" + TestDirtyTrackingTreeRidBagRemote.class.getSimpleName(), "root", "root");
    try {
        graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
        graph.createEdgeType("Edge");
        OIdentifiable oneVertex = null;
        Map<Object, Vertex> vertices = new HashMap<Object, Vertex>();
        for (int i = 0; i < max; i++) {
            Vertex v = graph.addVertex("class:V");
            v.setProperty("key", "foo" + i);
            graph.commit();
            vertices.put(v.getProperty("key"), v);
            if (i == max / 2 + 1)
                oneVertex = ((OrientVertex) v).getIdentity();
        }
        graph.commit();
        // Add the edges
        for (int i = 0; i < max; i++) {
            String codeUCD1 = "foo" + i;
            // Take the first vertex
            Vertex med1 = (Vertex) vertices.get(codeUCD1);
            // For the 2nd term
            for (int j = 0; j < max; j++) {
                String key = "foo" + j;
                // Take the second vertex
                Vertex med2 = (Vertex) vertices.get(key);
                // ((OrientVertex)med2).getRecord().reload();
                OrientEdge eInteraction = graph.addEdge(null, med1, med2, "Edge");
                assertNotNull(graph.getRawGraph().getTransaction().getRecordEntry(((OrientVertex) med2).getIdentity()));
            }
            // COMMIT
            graph.commit();
        }
        graph.getRawGraph().getLocalCache().clear();
        OrientVertex vertex = graph.getVertex(oneVertex);
        assertEquals(new GremlinPipeline<Vertex, Long>().start(vertex).in("Edge").count(), max);
    } finally {
        graph.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) HashMap(java.util.HashMap) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) Test(org.junit.Test)

Example 2 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project orientdb by orientechnologies.

the class OGremlinHelper method execute.

public static Object execute(final OrientBaseGraph graph, final String iText, final Map<Object, Object> iConfiguredParameters, Map<Object, Object> iCurrentParameters, final List<Object> iResult, final OGremlinCallback iBeforeExecution, final OGremlinCallback iAfterExecution) {
    try {
        final ScriptEngine engine = getGremlinEngine(graph);
        try {
            final String output = OGremlinHelper.bindParameters(engine, iConfiguredParameters, iCurrentParameters);
            if (iBeforeExecution != null)
                if (!iBeforeExecution.call(engine, graph))
                    return null;
            if (iText == null) {
                return null;
            }
            final Object scriptResult = engine.eval(iText);
            if (iAfterExecution != null)
                if (!iAfterExecution.call(engine, graph))
                    return null;
            // - Map -> ODocument
            if (output != null) {
                if (scriptResult instanceof GremlinPipeline) {
                    Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
                    while (it.hasNext()) // ignore iCurrentRecord but traverse still required
                    it.next();
                }
                final Map<String, Object> map = (Map<String, Object>) engine.get(output);
                ODocument oDocument = new ODocument(map);
                iResult.add(oDocument);
                return oDocument;
            }
            // returned for this call in the last pipe
            if (scriptResult instanceof GremlinPipeline) {
                final Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
                Object finalResult = null;
                List<Object> resultCollection = null;
                while (it.hasNext()) {
                    Object current = it.next();
                    if (finalResult != null) {
                        if (resultCollection == null) {
                            // CONVERT IT INTO A COLLECTION
                            resultCollection = new ArrayList<Object>();
                            resultCollection.add(finalResult);
                        }
                        resultCollection.add(current);
                    } else
                        finalResult = current;
                }
                if (resultCollection != null) {
                    iResult.addAll(resultCollection);
                    return resultCollection;
                } else {
                    if (finalResult != null)
                        iResult.add(finalResult);
                    return finalResult;
                }
            } else if (scriptResult != null)
                iResult.add(scriptResult);
            return scriptResult;
        } catch (Exception e) {
            throw OException.wrapException(new OCommandExecutionException("Error on execution of the GREMLIN script"), e);
        } finally {
            OGremlinHelper.global().releaseEngine(engine);
        }
    } finally {
        OGremlinHelper.global().releaseGraph(graph);
    }
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) GremlinGroovyScriptEngine(com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) ScriptEngine(javax.script.ScriptEngine) OException(com.orientechnologies.common.exception.OException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.

the class OrderStepTest method test_g_V_orderXa_nameXb_nameX_name.

public void test_g_V_orderXa_nameXb_nameX_name() {
    super.test_g_V_orderXa_nameXb_nameX_name(new GremlinPipeline(g.getVertices()).order(new PipeFunction<Pair<Vertex, Vertex>, Integer>() {

        public Integer compute(Pair<Vertex, Vertex> argument) {
            return ((String) argument.getB().getProperty("name")).compareTo((String) argument.getA().getProperty("name"));
        }
    }).property("name"));
    super.test_g_V_orderXa_nameXb_nameX_name(new GremlinPipeline(g.getVertices()).optimize(false).order(new PipeFunction<Pair<Vertex, Vertex>, Integer>() {

        public Integer compute(Pair<Vertex, Vertex> argument) {
            return ((String) argument.getB().getProperty("name")).compareTo((String) argument.getA().getProperty("name"));
        }
    }).property("name"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) Pair(com.tinkerpop.pipes.util.structures.Pair)

Example 4 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.

the class OrderStepTest method test_g_V_name_order.

public void test_g_V_name_order() {
    super.test_g_V_name_order(new GremlinPipeline(g.getVertices()).property("name").order());
    super.test_g_V_name_order(new GremlinPipeline(g).optimize(false).V().property("name").order());
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline)

Example 5 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.

the class PathStepTest method test_g_v1_out_pathXage__nameX.

public void test_g_v1_out_pathXage__nameX() {
    super.test_g_v1_out_pathXage__nameX(new GremlinPipeline(g.getVertex(1)).out().path(new PipeFunction<Vertex, Integer>() {

        public Integer compute(Vertex vertex) {
            return (Integer) vertex.getProperty("age");
        }
    }, new PipeFunction<Vertex, String>() {

        public String compute(Vertex vertex) {
            return (String) vertex.getProperty("name");
        }
    }));
    super.test_g_v1_out_pathXage__nameX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().path(new PipeFunction<Vertex, Integer>() {

        public Integer compute(Vertex vertex) {
            return (Integer) vertex.getProperty("age");
        }
    }, new PipeFunction<Vertex, String>() {

        public String compute(Vertex vertex) {
            return (String) vertex.getProperty("name");
        }
    }));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Aggregations

GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)93 Vertex (com.tinkerpop.blueprints.Vertex)28 PipeFunction (com.tinkerpop.pipes.PipeFunction)13 Pipe (com.tinkerpop.pipes.Pipe)6 HashMap (java.util.HashMap)4 Request (org.apache.atlas.catalog.Request)3 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)3 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)3 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)3 Test (org.testng.annotations.Test)3 LoopPipe (com.tinkerpop.pipes.branch.LoopPipe)2 PropertyFilterPipe (com.tinkerpop.pipes.filter.PropertyFilterPipe)2 Table (com.tinkerpop.pipes.util.structures.Table)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Test (org.junit.Test)2 OException (com.orientechnologies.common.exception.OException)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1