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());
}
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()));
}
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();
}
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();
}
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();
}
Aggregations