Search in sources :

Example 1 with GraphTraversalSource

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource in project titan by thinkaurelius.

the class CassandraInputFormatIT method testReadGraphOfTheGods.

@Test
public void testReadGraphOfTheGods() {
    GraphOfTheGodsFactory.load(graph, null, true);
    assertEquals(12L, (long) graph.traversal().V().count().next());
    Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties");
    GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class));
    assertEquals(12L, (long) t.V().count().next());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Graph(org.apache.tinkerpop.gremlin.structure.Graph) SparkGraphComputer(org.apache.tinkerpop.gremlin.hadoop.process.computer.spark.SparkGraphComputer) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Example 2 with GraphTraversalSource

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource in project titan by thinkaurelius.

the class TitanGraphTest method testTinkerPopCardinality.

@Test
public void testTinkerPopCardinality() {
    PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
    PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make();
    PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make();
    mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex();
    finishSchema();
    GraphTraversalSource gts;
    Vertex v;
    v = graph.addVertex("id", 1);
    v.property(single, "name", "t1");
    graph.addVertex("id", 2, "names", "n1", "names", "n2");
    graph.tx().commit();
    gts = graph.traversal();
    v = gts.V().has("id", 1).next();
    v.property(single, "name", "t2");
    v = gts.V().has("id", 1).next();
    v.property(single, "name", "t3");
    assertCount(1, gts.V(v).properties("name"));
    assertCount(2, gts.V().has("id", 2).properties("names"));
    assertCount(2, gts.V().hasLabel("vertex"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 3 with GraphTraversalSource

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource in project titan by thinkaurelius.

the class TitanGraphTest method testTinkerPopOptimizationStrategies.

@Test
public void testTinkerPopOptimizationStrategies() {
    PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
    PropertyKey weight = mgmt.makePropertyKey("weight").cardinality(Cardinality.SINGLE).dataType(Integer.class).make();
    mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex();
    mgmt.buildIndex("byWeight", Vertex.class).addKey(weight).buildCompositeIndex();
    mgmt.buildIndex("byIdWeight", Vertex.class).addKey(id).addKey(weight).buildCompositeIndex();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").make();
    mgmt.buildEdgeIndex(knows, "byWeightDecr", Direction.OUT, decr, weight);
    mgmt.buildEdgeIndex(knows, "byWeightIncr", Direction.OUT, incr, weight);
    PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make();
    mgmt.buildPropertyIndex(names, "namesByWeight", decr, weight);
    finishSchema();
    int numV = 100;
    TitanVertex[] vs = new TitanVertex[numV];
    for (int i = 0; i < numV; i++) {
        vs[i] = graph.addVertex("id", i, "weight", i % 5);
    }
    int superV = 10;
    int sid = -1;
    TitanVertex[] sv = new TitanVertex[superV];
    for (int i = 0; i < superV; i++) {
        sv[i] = graph.addVertex("id", sid);
        for (int j = 0; j < numV; j++) {
            sv[i].addEdge("knows", vs[j], "weight", j % 5);
            sv[i].property(VertexProperty.Cardinality.list, "names", "n" + j, "weight", j % 5);
        }
    }
    Traversal t;
    TraversalMetrics metrics;
    GraphTraversalSource gts = graph.traversal();
    //Edge
    assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), TitanVertexStep.class);
    assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), TitanVertexStep.class);
    assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), TitanVertexStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), TitanVertexStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class);
    assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), TitanVertexStep.class, OrderGlobalStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), TitanVertexStep.class);
    assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class);
    assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class);
    assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class);
    assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class);
    assertNumStep(1, 1, gts.V(sv[0]).bothE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class);
    assertNumStep(1, 2, gts.V(sv[0]).bothE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class, TraversalFilterStep.class);
    //Property
    assertNumStep(numV / 5, 1, gts.V(sv[0]).properties("names").has("weight", 1), TitanPropertiesStep.class);
    assertNumStep(numV, 1, gts.V(sv[0]).properties("names"), TitanPropertiesStep.class);
    assertNumStep(10, 1, gts.V(sv[0]).local(__.properties("names").order().by("weight", decr).limit(10)), TitanPropertiesStep.class);
    assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").values("weight"), TitanVertexStep.class, TitanPropertiesStep.class);
    //Global graph queries
    assertNumStep(1, 1, gts.V().has("id", numV / 5), TitanGraphStep.class);
    assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5), TitanGraphStep.class);
    assertNumStep(numV / 5, 1, gts.V().has("weight", 1), TitanGraphStep.class);
    assertNumStep(10, 1, gts.V().has("weight", 1).range(0, 10), TitanGraphStep.class);
    assertNumStep(superV, 1, gts.V().has("id", sid), TitanGraphStep.class);
    //Ensure that as steps don't interfere
    assertNumStep(1, 1, gts.V().has("id", numV / 5).as("x"), TitanGraphStep.class);
    assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5).as("x"), TitanGraphStep.class);
    assertNumStep(superV * (numV / 5), 2, gts.V().has("id", sid).outE("knows").has("weight", 1), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, gts.V().has("id", sid).outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, gts.V().has("id", sid).outE("knows").has("weight", P.between(1, 3)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    clopen(option(USE_MULTIQUERY), true);
    gts = graph.traversal();
    assertNumStep(superV * (numV / 5), 2, gts.V().has("id", sid).outE("knows").has("weight", 1), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * (numV / 5 * 2), 2, gts.V().has("id", sid).outE("knows").has("weight", P.between(1, 3)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * 10, 2, gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)), TitanGraphStep.class, TitanVertexStep.class);
    assertNumStep(superV * numV, 2, gts.V().has("id", sid).values("names"), TitanGraphStep.class, TitanPropertiesStep.class);
    //Verify traversal metrics when all reads are from cache (i.e. no backend queries)
    t = gts.V().has("id", sid).local(__.outE("knows").has("weight", P.between(1, 3)).order().by("weight", decr).limit(10)).profile();
    assertCount(superV * 10, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    verifyMetrics(metrics.getMetrics(0), true, false);
    verifyMetrics(metrics.getMetrics(1), true, true);
    //Verify that properties also use multi query
    t = gts.V().has("id", sid).values("names").profile();
    assertCount(superV * numV, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    verifyMetrics(metrics.getMetrics(0), true, false);
    verifyMetrics(metrics.getMetrics(1), true, true);
    clopen(option(USE_MULTIQUERY), true);
    gts = graph.traversal();
    //Verify traversal metrics when having to read from backend [same query as above]
    t = gts.V().has("id", sid).local(__.outE("knows").has("weight", P.gte(1)).has("weight", P.lt(3)).order().by("weight", decr).limit(10)).profile();
    assertCount(superV * 10, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    //        System.out.println(metrics);
    verifyMetrics(metrics.getMetrics(0), false, false);
    verifyMetrics(metrics.getMetrics(1), false, true);
    //Verify that properties also use multi query [same query as above]
    t = gts.V().has("id", sid).values("names").profile();
    assertCount(superV * numV, t);
    metrics = (TraversalMetrics) t.asAdmin().getSideEffects().get("~metrics").get();
    //        System.out.println(metrics);
    verifyMetrics(metrics.getMetrics(0), false, false);
    verifyMetrics(metrics.getMetrics(1), false, true);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) Test(org.junit.Test)

Example 4 with GraphTraversalSource

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource in project titan by thinkaurelius.

the class CassandraInputFormatIT method testReadWideVertexWithManyProperties.

@Test
public void testReadWideVertexWithManyProperties() {
    int numProps = 1 << 16;
    long numV = 1;
    mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make();
    mgmt.commit();
    finishSchema();
    for (int j = 0; j < numV; j++) {
        Vertex v = graph.addVertex();
        for (int i = 0; i < numProps; i++) {
            v.property("p", i);
        }
    }
    graph.tx().commit();
    assertEquals(numV, (long) graph.traversal().V().count().next());
    Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next();
    List<?> valuesOnP = (List) propertiesOnVertex.values().iterator().next();
    assertEquals(numProps, valuesOnP.size());
    Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties");
    GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class));
    assertEquals(numV, (long) t.V().count().next());
    propertiesOnVertex = t.V().valueMap().next();
    valuesOnP = (List) propertiesOnVertex.values().iterator().next();
    assertEquals(numProps, valuesOnP.size());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) List(java.util.List) SparkGraphComputer(org.apache.tinkerpop.gremlin.hadoop.process.computer.spark.SparkGraphComputer) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Example 5 with GraphTraversalSource

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource in project titan by thinkaurelius.

the class OLAPTest method testBasicComputeJob.

@Test
public void testBasicComputeJob() throws Exception {
    GraphTraversalSource g = graph.traversal(GraphTraversalSource.computer());
    System.out.println(g.V().count().next());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Aggregations

GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)5 Test (org.junit.Test)5 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SparkGraphComputer (org.apache.tinkerpop.gremlin.hadoop.process.computer.spark.SparkGraphComputer)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)1 List (java.util.List)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 TraversalMetrics (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics)1