Search in sources :

Example 1 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method addVertex.

private void addVertex(int time, String text, double height, String[] phones) {
    newTx();
    JanusGraphVertex v = tx.addVertex("text", text, "time", time, "height", height);
    for (String phone : phones) {
        v.property("phone", phone);
    }
    newTx();
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex)

Example 2 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testContainsWithMultipleValues.

@Test
public // so we need to make sure that we don't apply AND twice.
void testContainsWithMultipleValues() {
    PropertyKey name = makeKey("name", String.class);
    mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX);
    mgmt.commit();
    JanusGraphVertex v1 = tx.addVertex();
    v1.property("name", "hercules was here");
    tx.commit();
    final JanusGraphVertex r = Iterables.get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0);
    Assert.assertEquals(r.property("name").value(), "hercules was here");
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 3 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testDateIndexing.

/**
 * Tests indexing dates
 */
@Test
public void testDateIndexing() {
    PropertyKey name = makeKey("date", Date.class);
    mgmt.buildIndex("dateIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();
    JanusGraphVertex v1 = graph.addVertex();
    v1.property("date", new Date(1));
    JanusGraphVertex v2 = graph.addVertex();
    v2.property("date", new Date(2000));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
    // Flush the index
    clopen();
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
    assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
    assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
    assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Date(java.util.Date) Test(org.junit.Test)

Example 4 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testIndexQueryWithScore.

@Test
public void testIndexQueryWithScore() {
    PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make();
    mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX);
    mgmt.commit();
    JanusGraphVertex v1 = tx.addVertex();
    JanusGraphVertex v2 = tx.addVertex();
    JanusGraphVertex v3 = tx.addVertex();
    v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello world");
    v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf");
    v3.property("text", "Hello Hello world world");
    tx.commit();
    final Set<Double> scores = graph.indexQuery("store1", "v.text:(Hello)").vertexStream().map(JanusGraphIndexQuery.Result::getScore).collect(Collectors.toSet());
    Assert.assertEquals(3, scores.size());
}
Also used : JanusGraphIndexQuery(org.janusgraph.core.JanusGraphIndexQuery) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 5 with JanusGraphVertex

use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testIndexing.

@Test
public void testIndexing() throws InterruptedException {
    PropertyKey text = makeKey("text", String.class);
    createExternalVertexIndex(text, INDEX);
    createExternalEdgeIndex(text, INDEX);
    PropertyKey name = makeKey("name", String.class);
    mgmt.addIndexKey(getExternalIndex(Vertex.class, INDEX), name, Parameter.of("mapping", Mapping.TEXT));
    mgmt.addIndexKey(getExternalIndex(Edge.class, INDEX), name, Parameter.of("mapping", Mapping.TEXT));
    PropertyKey location = makeKey("location", Geoshape.class);
    createExternalVertexIndex(location, INDEX);
    createExternalEdgeIndex(location, INDEX);
    PropertyKey boundary = makeKey("boundary", Geoshape.class);
    mgmt.addIndexKey(getExternalIndex(Vertex.class, INDEX), boundary, Parameter.of("mapping", Mapping.PREFIX_TREE), Parameter.of("index-geo-dist-error-pct", 0.0025));
    mgmt.addIndexKey(getExternalIndex(Edge.class, INDEX), boundary, Parameter.of("mapping", Mapping.PREFIX_TREE), Parameter.of("index-geo-dist-error-pct", 0.0025));
    PropertyKey time = makeKey("time", Long.class);
    createExternalVertexIndex(time, INDEX);
    createExternalEdgeIndex(time, INDEX);
    PropertyKey category = makeKey("category", Integer.class);
    mgmt.buildIndex("vcategory", Vertex.class).addKey(category).buildCompositeIndex();
    mgmt.buildIndex("ecategory", Edge.class).addKey(category).buildCompositeIndex();
    PropertyKey group = makeKey("group", Byte.class);
    createExternalVertexIndex(group, INDEX);
    createExternalEdgeIndex(group, INDEX);
    makeVertexIndexedKey("uid", Integer.class);
    ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(time).signature(location, boundary).make();
    finishSchema();
    clopen();
    String[] words = { "world", "aurelius", "janusgraph", "graph" };
    int numCategories = 5;
    int numGroups = 10;
    double distance, offset;
    int numV = 100;
    final int originalNumV = numV;
    for (int i = 0; i < numV; i++) {
        JanusGraphVertex v = tx.addVertex();
        v.property(VertexProperty.Cardinality.single, "uid", i);
        v.property(VertexProperty.Cardinality.single, "category", i % numCategories);
        v.property(VertexProperty.Cardinality.single, "group", i % numGroups);
        v.property(VertexProperty.Cardinality.single, "text", "Vertex " + words[i % words.length]);
        v.property(VertexProperty.Cardinality.single, "name", words[i % words.length]);
        v.property(VertexProperty.Cardinality.single, "time", i);
        offset = (i % 2 == 0 ? 1 : -1) * (i * 50.0 / numV);
        v.property(VertexProperty.Cardinality.single, "location", Geoshape.point(0.0 + offset, 0.0 + offset));
        if (i % 2 == 0) {
            v.property(VertexProperty.Cardinality.single, "boundary", Geoshape.line(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 } })));
        } else {
            v.property(VertexProperty.Cardinality.single, "boundary", Geoshape.polygon(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 }, { offset - 0.1, offset - 0.1 } })));
        }
        Edge e = v.addEdge("knows", getVertex("uid", Math.max(0, i - 1)));
        e.property("text", "Vertex " + words[i % words.length]);
        e.property("name", words[i % words.length]);
        e.property("time", i);
        e.property("category", i % numCategories);
        e.property("group", i % numGroups);
        e.property("location", Geoshape.point(0.0 + offset, 0.0 + offset));
        if (i % 2 == 0) {
            e.property("boundary", Geoshape.line(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 } })));
        } else {
            e.property("boundary", Geoshape.polygon(Arrays.asList(new double[][] { { offset - 0.1, offset - 0.1 }, { offset + 0.1, offset - 0.1 }, { offset + 0.1, offset + 0.1 }, { offset - 0.1, offset + 0.1 }, { offset - 0.1, offset - 0.1 } })));
        }
    }
    checkIndexingCounts(words, numV, originalNumV, true);
    // some indexing backends may guarantee only eventual consistency
    for (int retry = 0, status = 1; retry < RETRY_COUNT && status > 0; retry++) {
        clopen();
        try {
            checkIndexingCounts(words, numV, originalNumV, true);
            status = 0;
        } catch (AssertionError e) {
            if (retry >= RETRY_COUNT - 1)
                throw e;
            Thread.sleep(RETRY_INTERVAL);
        }
    }
    newTx();
    int numDelete = 12;
    for (int i = numV - numDelete; i < numV; i++) {
        getVertex("uid", i).remove();
    }
    numV -= numDelete;
    checkIndexingCounts(words, numV, originalNumV, false);
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Aggregations

JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)87 Test (org.junit.Test)72 PropertyKey (org.janusgraph.core.PropertyKey)54 EdgeLabel (org.janusgraph.core.EdgeLabel)20 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)18 Edge (org.apache.tinkerpop.gremlin.structure.Edge)17 VertexLabel (org.janusgraph.core.VertexLabel)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)13 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)12 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)11 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)8 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5 Random (java.util.Random)5 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)5 Direction (org.apache.tinkerpop.gremlin.structure.Direction)5 JanusGraph (org.janusgraph.core.JanusGraph)5