use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testSetUpdate.
@Test
public void testSetUpdate() {
if (!indexFeatures.supportsCardinality(Cardinality.SET)) {
return;
}
PropertyKey name = makeKey("name", String.class);
PropertyKey alias = mgmt.makePropertyKey("alias").dataType(String.class).cardinality(Cardinality.SET).make();
mgmt.buildIndex("namev", Vertex.class).addKey(name).addKey(alias, indexFeatures.supportsStringMapping(Mapping.TEXTSTRING) ? Mapping.TEXTSTRING.asParameter() : Mapping.DEFAULT.asParameter()).buildMixedIndex(INDEX);
finishSchema();
JanusGraphVertex v = tx.addVertex("name", "Marko Rodriguez");
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
clopen();
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
v.property(VertexProperty.Cardinality.set, "alias", "Marko");
assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
clopen();
assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
v.property(VertexProperty.Cardinality.set, "alias", "mRodriguez");
assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices());
clopen();
assertCount(1, tx.query().has("alias", Text.CONTAINS, "Marko").vertices());
assertCount(1, tx.query().has("alias", Text.CONTAINS, "mRodriguez").vertices());
if (indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) {
assertCount(1, tx.query().has("alias", Cmp.EQUAL, "Marko").vertices());
assertCount(1, tx.query().has("alias", Cmp.EQUAL, "mRodriguez").vertices());
}
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testRawQueriesWithParameters.
/**
* Tests query parameters with raw indexQuery
*/
@Test
public void testRawQueriesWithParameters() {
if (!supportsLuceneStyleQueries())
return;
Parameter asc_sort_p = null;
Parameter desc_sort_p = null;
// ElasticSearch and Solr have different formats for sort parameters
String backend = readConfig.get(INDEX_BACKEND, INDEX);
switch(backend) {
case "elasticsearch":
final Map<String, String> sortAsc = new HashMap<>();
sortAsc.put("_score", "asc");
asc_sort_p = new Parameter("sort", Collections.singletonList(sortAsc));
final Map<String, String> sortDesc = new HashMap<>();
sortDesc.put("_score", "desc");
desc_sort_p = new Parameter("sort", Collections.singletonList(sortDesc));
break;
case "solr":
asc_sort_p = new Parameter("sort", new String[] { "score asc" });
desc_sort_p = new Parameter("sort", new String[] { "score desc" });
break;
case "lucene":
// Ignore for lucene
return;
default:
Assert.fail("Unknown index backend:" + backend);
break;
}
final PropertyKey field1Key = mgmt.makePropertyKey("field1").dataType(String.class).make();
mgmt.buildIndex("store1", Vertex.class).addKey(field1Key).buildMixedIndex(INDEX);
mgmt.commit();
JanusGraphVertex v1 = tx.addVertex();
JanusGraphVertex v2 = tx.addVertex();
JanusGraphVertex v3 = tx.addVertex();
v1.property("field1", "Hello Hello Hello Hello Hello Hello Hello Hello world");
v2.property("field1", "Hello blue and yellow meet green");
v3.property("field1", "Hello Hello world world");
tx.commit();
final List<JanusGraphVertex> vertices = graph.indexQuery("store1", "v.field1:(Hello)").addParameter(asc_sort_p).vertexStream().map(JanusGraphIndexQuery.Result::getElement).collect(Collectors.toList());
assertNotEmpty(vertices);
final AtomicInteger idx = new AtomicInteger(vertices.size() - 1);
// Verify this query returns the items in reverse order.
graph.indexQuery("store1", "v.field1:(Hello)").addParameter(desc_sort_p).vertexStream().map(JanusGraphIndexQuery.Result::getElement).forEachOrdered(e -> assertEquals(vertices.get(idx.getAndDecrement()), e));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testInstantIndexing.
/**
* Tests indexing instants
*/
@Test
public void testInstantIndexing() {
PropertyKey name = makeKey("instant", Instant.class);
mgmt.buildIndex("instantIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
Instant firstTimestamp = Instant.ofEpochMilli(1);
Instant secondTimestamp = Instant.ofEpochMilli(2000);
JanusGraphVertex v1 = graph.addVertex();
v1.property("instant", firstTimestamp);
JanusGraphVertex v2 = graph.addVertex();
v2.property("instant", secondTimestamp);
testInstant(firstTimestamp, secondTimestamp, v1, v2);
firstTimestamp = Instant.ofEpochSecond(0, 1);
v1 = (JanusGraphVertex) graph.vertices(v1.id()).next();
v1.property("instant", firstTimestamp);
if (indexFeatures.supportsNanoseconds()) {
testInstant(firstTimestamp, secondTimestamp, v1, v2);
} else {
// Flush the index
clopen();
try {
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
Assert.fail("Should have failed to update the index");
} catch (Exception ignored) {
}
}
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
PropertyKey name = makeKey("name", String.class);
makeLabel("knows");
mgmt.buildIndex("namev", Vertex.class).addKey(name).buildMixedIndex(INDEX);
mgmt.buildIndex("namee", Edge.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
JanusGraphVertex v = tx.addVertex("name", "Marko Rodriguez");
Edge e = v.addEdge("knows", v, "name", "Hulu Bubab");
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name"));
clopen();
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name"));
v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
v.property(VertexProperty.Cardinality.single, "name", "Marko");
e = getOnlyEdge(v.query().direction(Direction.OUT));
e.property("name", "Tubu Rubu");
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges());
assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name"));
clopen();
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges());
assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name"));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphIterativeBenchmark method loadData.
public void loadData(final int numVertices, final int numThreads) throws Exception {
makeKey("w", Integer.class);
PropertyKey time = makeKey("t", Long.class);
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("l")).sortKey(time).make();
finishSchema();
final int maxQueue = 1000;
final int verticesPerTask = 1000;
final int maxWeight = 10;
final int maxTime = 10000;
final BlockingQueue<Runnable> tasks = new ArrayBlockingQueue<>(maxQueue);
ExecutorService exe = Executors.newFixedThreadPool(numThreads);
for (int i = 0; i < numVertices / verticesPerTask; i++) {
while (tasks.size() >= maxQueue) Thread.sleep(maxQueue);
assert tasks.size() < maxQueue;
exe.submit(() -> {
final JanusGraphTransaction tx = graph.newTransaction();
final JanusGraphVertex[] vs = new JanusGraphVertex[verticesPerTask];
for (int j = 0; j < verticesPerTask; j++) {
vs[j] = tx.addVertex();
vs[j].property(VertexProperty.Cardinality.single, "w", random.nextInt(maxWeight));
}
for (int j = 0; j < verticesPerTask * 10; j++) {
final JanusGraphEdge e = vs[random.nextInt(verticesPerTask)].addEdge("l", vs[random.nextInt(verticesPerTask)]);
e.property("t", random.nextInt(maxTime));
}
System.out.print(".");
tx.commit();
});
}
exe.shutdown();
exe.awaitTermination(numVertices / 1000, TimeUnit.SECONDS);
if (!exe.isTerminated())
System.err.println("Could not load data in time");
System.out.println("Loaded " + numVertices + "vertices");
}
Aggregations