Search in sources :

Example 66 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class QueryTest method testTextContainsPhraseWithoutIndex.

@Test
public void testTextContainsPhraseWithoutIndex() {
    JanusGraphManagement mgmt = graph.openManagement();
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.commit();
    tx.addVertex().property("name", "some value");
    tx.addVertex().property("name", "other value");
    tx.commit();
    assertEquals(2, graph.traversal().V().has("name", Text.textContainsPhrase("value")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textContainsPhrase("other value")).count().next());
    assertEquals(0, graph.traversal().V().has("name", Text.textContainsPhrase("final value")).count().next());
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Example 67 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class QueryTest method testQueryLimitAdjustment.

@Test
public void testQueryLimitAdjustment() {
    JanusGraphManagement mgmt = graph.openManagement();
    PropertyKey prop1Key = mgmt.makePropertyKey("prop1").dataType(String.class).make();
    PropertyKey prop2Key = mgmt.makePropertyKey("prop2").dataType(String.class).make();
    PropertyKey prop3Key = mgmt.makePropertyKey("prop3").dataType(String.class).make();
    PropertyKey prop4Key = mgmt.makePropertyKey("prop4").dataType(String.class).make();
    mgmt.buildIndex("prop1_idx", Vertex.class).addKey(prop1Key).buildCompositeIndex();
    mgmt.buildIndex("props_idx", Vertex.class).addKey(prop1Key).addKey(prop2Key).buildCompositeIndex();
    mgmt.commit();
    for (int i = 0; i < 20; i++) {
        tx.addVertex().property("prop1", "prop1val").element().property("prop2", "prop2val").element().property("prop3", "prop3val").element().property("prop4", "prop4val");
    }
    tx.commit();
    // Single condition, fully met by index prop1_idx. No need to adjust backend query limit.
    assertCount(5, graph.traversal().V().has("prop1", "prop1val").limit(5));
    assertEquals("multiKSQ[1]@5", getQueryAnnotation(graph.traversal().V().has("prop1", "prop1val").limit(5).profile().next()));
    // Two conditions, fully met by index props_idx. No need to adjust backend query limit.
    assertCount(5, graph.traversal().V().has("prop1", "prop1val").has("prop2", "prop2val").limit(5));
    assertEquals("multiKSQ[1]@5", getQueryAnnotation(graph.traversal().V().has("prop1", "prop1val").has("prop2", "prop2val").limit(5).profile().next()));
    // Two conditions, one of which met by index prop1_idx. Multiply original limit by two for sake of in-memory filtering.
    assertCount(5, graph.traversal().V().has("prop1", "prop1val").has("prop3", "prop3val").limit(5));
    assertEquals("multiKSQ[1]@10", getQueryAnnotation(graph.traversal().V().has("prop1", "prop1val").has("prop3", "prop3val").limit(5).profile().next()));
    // Three conditions, one of which met by index prop1_idx. Multiply original limit by four for sake of in-memory filtering.
    assertCount(5, graph.traversal().V().has("prop1", "prop1val").has("prop3", "prop3val").has("prop4", "prop4val").limit(5));
    assertEquals("multiKSQ[1]@20", getQueryAnnotation(graph.traversal().V().has("prop1", "prop1val").has("prop3", "prop3val").has("prop4", "prop4val").limit(5).profile().next()));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Example 68 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class QueryTest method testIndexQueryCache.

@Test
public void testIndexQueryCache() throws Exception {
    JanusGraphManagement mgmt = graph.openManagement();
    final PropertyKey prop = mgmt.makePropertyKey("prop").dataType(String.class).cardinality(Cardinality.SINGLE).make();
    final JanusGraphIndex index = mgmt.buildIndex("index", Vertex.class).addKey(prop).buildCompositeIndex();
    mgmt.commit();
    // cache is used when there is no result for given query
    assertBackendHit(graph.traversal().V().has("prop", "value").profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").profile().next());
    assertEquals(0, graph.traversal().V().has("prop", "value").toList().size());
    graph.tx().rollback();
    for (int i = 0; i < 100; i++) {
        tx.addVertex("prop", "value");
    }
    tx.commit();
    // cache is used when there are results for given query
    assertBackendHit(graph.traversal().V().has("prop", "value").profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").profile().next());
    assertEquals(100, graph.traversal().V().has("prop", "value").toList().size());
    graph.tx().rollback();
    // cache is used with limit
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(10).profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(10).profile().next());
    assertEquals(10, graph.traversal().V().has("prop", "value").limit(10).toList().size());
    graph.tx().rollback();
    // result is cached and cache is used with limit larger than number of possible results
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(1000).profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(1000).profile().next());
    assertEquals(100, graph.traversal().V().has("prop", "value").limit(1000).toList().size());
    graph.tx().rollback();
    // cache is not used when second query has higher limit
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(10).profile().next());
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(11).profile().next());
    assertEquals(11, graph.traversal().V().has("prop", "value").limit(11).toList().size());
    graph.tx().rollback();
    // cache is used when first query exhausts all results
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(200).profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(1000).profile().next());
    assertEquals(100, graph.traversal().V().has("prop", "value").limit(1000).toList().size());
    graph.tx().rollback();
    assertBackendHit(graph.traversal().V().has("prop", "value").profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(1000).profile().next());
    assertEquals(100, graph.traversal().V().has("prop", "value").limit(1000).toList().size());
    graph.tx().rollback();
    // cache is used when second query has lower limit
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(10).profile().next());
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(9).profile().next());
    assertEquals(9, graph.traversal().V().has("prop", "value").limit(9).toList().size());
    graph.tx().rollback();
    // incomplete results are not put in cache if iterator is not exhausted
    GraphTraversal<Vertex, Vertex> iter = graph.traversal().V().has("prop", "value");
    for (int i = 0; i < 10; i++) {
        iter.next();
    }
    iter.close();
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(1).profile().next());
    graph.tx().rollback();
    try (GraphTraversal<Vertex, Vertex> it = graph.traversal().V().has("prop", "value")) {
        for (int i = 0; i < 10; i++) {
            it.next();
        }
    }
    assertBackendHit(graph.traversal().V().has("prop", "value").limit(1).profile().next());
    graph.tx().rollback();
    // complete results are put in cache if iterator is exhausted
    iter = graph.traversal().V().has("prop", "value");
    while (iter.hasNext()) {
        iter.next();
    }
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(1).profile().next());
    graph.tx().rollback();
    iter = graph.traversal().V().has("prop", "value");
    for (int i = 0; i < 100; i++) {
        iter.next();
    }
    assertNoBackendHit(graph.traversal().V().has("prop", "value").limit(1).profile().next());
    graph.tx().rollback();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Example 69 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class EdgeSerializerTest method testValueOrdering.

@Test
public void testValueOrdering() {
    StandardJanusGraph graph = (StandardJanusGraph) StorageSetup.getInMemoryGraph();
    JanusGraphManagement management = graph.openManagement();
    management.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    for (int i = 1; i <= 5; i++) management.makePropertyKey("key" + i).dataType(Integer.class).make();
    management.commit();
    JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    JanusGraphEdge e1 = v1.addEdge("father", v2);
    for (int i = 1; i <= 5; i++) e1.property("key" + i, i);
    graph.tx().commit();
    e1.remove();
    graph.tx().commit();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 70 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class ConfigurationManagementGraphTest method shouldReindexIfPropertyKeyExists.

@Test
public void shouldReindexIfPropertyKeyExists() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    final String propertyKeyName = "Created_Using_Template";
    final Class dataType = Boolean.class;
    JanusGraphManagement management = graph.openManagement();
    management.makePropertyKey(propertyKeyName).dataType(dataType).make();
    management.commit();
    // Instantiate the ConfigurationManagementGraph Singleton
    // This is purposefully done after a property key is created to ensure that a REDINDEX is initiated
    new ConfigurationManagementGraph(graph);
    management = graph.openManagement();
    final JanusGraphIndex index = management.getGraphIndex("Created_Using_Template_Index");
    final PropertyKey propertyKey = management.getPropertyKey("Created_Using_Template");
    assertNotNull(index);
    assertNotNull(propertyKey);
    assertEquals(ENABLED, index.getIndexStatus(propertyKey));
    management.commit();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Aggregations

JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)92 PropertyKey (org.janusgraph.core.PropertyKey)44 Test (org.junit.jupiter.api.Test)26 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)24 JanusGraph (org.janusgraph.core.JanusGraph)23 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)20 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)17 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)12 HashMap (java.util.HashMap)9 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 Test (org.junit.Test)8 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)8 TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)8 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)7 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)6 EdgeLabel (org.janusgraph.core.EdgeLabel)6 Map (java.util.Map)5 JanusGraphException (org.janusgraph.core.JanusGraphException)5