use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class JanusGraphTest method testUpdateSchemaChangeNameForCompositeIndex.
@Test
public void testUpdateSchemaChangeNameForCompositeIndex() {
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();
finishSchema();
// UPDATE SCHEMA NAMES
assertTrue(mgmt.containsGraphIndex("timeIndex"));
JanusGraphIndex graphIndex = mgmt.getGraphIndex("timeIndex");
mgmt.changeName(graphIndex, "byTime");
assertEquals("byTime", graphIndex.name());
finishSchema();
// VERIFY UPDATES IN MANAGEMENT SYSTEM
assertTrue(mgmt.containsGraphIndex("byTime"));
assertFalse(mgmt.containsGraphIndex("timeIndex"));
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testDualMapping.
@Test
public void testDualMapping() {
if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING))
return;
final PropertyKey name = makeKey("name", String.class);
final JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX);
mixed.name();
finishSchema();
tx.addVertex("name", "Long John Don");
tx.addVertex("name", "Long Little Lewis");
tx.addVertex("name", "Middle Sister Mabel");
clopen();
evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS_PREFIX, "Lon"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS_REGEX, "Lit*le"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.REGEX, "Long.*"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.FUZZY, "Long john Don"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS_FUZZY, "Midle"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().orderBy("name", asc), ElementCategory.VERTEX, 3, new boolean[] { false, false }, tx.getPropertyKey("name"), Order.ASC);
evaluateQuery(tx.query().orderBy("name", desc), ElementCategory.VERTEX, 3, new boolean[] { false, false }, tx.getPropertyKey("name"), Order.DESC);
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long").orderBy("name", asc), ElementCategory.VERTEX, 2, new boolean[] { true, true }, tx.getPropertyKey("name"), Order.ASC, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long").orderBy("name", desc), ElementCategory.VERTEX, 2, new boolean[] { true, true }, tx.getPropertyKey("name"), Order.DESC, "mixed");
for (final Vertex u : tx.getVertices()) {
final String n = u.value("name");
if (n.endsWith("Don")) {
u.remove();
} else if (n.endsWith("Lewis")) {
u.property(VertexProperty.Cardinality.single, "name", "Big Brother Bob");
} else if (n.endsWith("Mabel")) {
u.property("name").remove();
}
}
clopen();
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Long"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.CONTAINS, "Big"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.PREFIX, "Big"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mixed");
evaluateQuery(tx.query().has("name", Text.PREFIX, "Middle"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mixed");
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method setupChainGraph.
private void setupChainGraph(int numV, String[] strings, boolean sameNameMapping) {
clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping);
final JanusGraphIndex vindex = getExternalIndex(Vertex.class, INDEX);
final JanusGraphIndex eindex = getExternalIndex(Edge.class, INDEX);
final JanusGraphIndex pindex = getExternalIndex(JanusGraphVertexProperty.class, INDEX);
final PropertyKey name = makeKey("name", String.class);
mgmt.addIndexKey(vindex, name, getStringMapping());
mgmt.addIndexKey(eindex, name, getStringMapping());
mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
final PropertyKey text = makeKey("text", String.class);
mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext"));
mgmt.addIndexKey(eindex, text, getTextMapping());
mgmt.addIndexKey(pindex, text, getTextMapping());
mgmt.makeEdgeLabel("knows").signature(name).make();
mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
finishSchema();
JanusGraphVertex previous = null;
for (int i = 0; i < numV; i++) {
final JanusGraphVertex v = graph.addVertex("name", strings[i % strings.length], "text", strings[i % strings.length]);
v.addEdge("knows", previous == null ? v : previous, "name", strings[i % strings.length], "text", strings[i % strings.length]);
v.property("uid", "v" + i, "name", strings[i % strings.length], "text", strings[i % strings.length]);
previous = v;
}
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testIndexUpdatesWithoutReindex.
@Test
public void testIndexUpdatesWithoutReindex() throws InterruptedException, ExecutionException {
final Object[] settings = new Object[] { option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250) };
clopen(settings);
final String defText = "Mountain rocks are great friends";
final int defTime = 5;
final double defHeight = 101.1;
final String[] defPhones = new String[] { "1234", "5678" };
// Creates types and index only two keys key
mgmt.makePropertyKey("time").dataType(Integer.class).make();
final PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make();
mgmt.makePropertyKey("height").dataType(Double.class).make();
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
mgmt.makePropertyKey("phone").dataType(String.class).cardinality(Cardinality.LIST).make();
}
mgmt.buildIndex("theIndex", Vertex.class).addKey(text, getTextMapping(), getFieldMap(text)).buildMixedIndex(INDEX);
finishSchema();
// Add initial data
addVertex(defTime, defText, defHeight, defPhones);
// Indexes should not yet be in use
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 1, new boolean[] { false, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
}
newTx();
// Add another key to index ------------------------------------------------------
finishSchema();
final PropertyKey time = mgmt.getPropertyKey("time");
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), time, getFieldMap(time));
finishSchema();
newTx();
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
tx.commit();
// Should not yet be able to enable since not yet registered
assertNull(mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX));
// This call is redundant and just here to make sure it doesn't mess anything up
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REGISTER_INDEX).get();
mgmt.commit();
ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").timeout(10L, ChronoUnit.SECONDS).call();
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX).get();
finishSchema();
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
// One more key should be indexed but only sees partial data
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 3, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 3, new boolean[] { false, true });
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { false, true }, "theIndex");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { false, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 3, new boolean[] { false, true });
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 3, new boolean[] { false, true });
}
newTx();
// Add another key to index ------------------------------------------------------
finishSchema();
final PropertyKey height = mgmt.getPropertyKey("height");
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), height);
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
final PropertyKey phone = mgmt.getPropertyKey("phone");
mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), phone, new Parameter("mapping", Mapping.STRING));
}
finishSchema();
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
tx.commit();
mgmt.commit();
ManagementUtil.awaitGraphIndexUpdate(graph, "theIndex", 10, ChronoUnit.SECONDS);
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
finishSchema();
JanusGraphIndex index = mgmt.getGraphIndex("theIndex");
for (final PropertyKey key : index.getFieldKeys()) {
assertEquals(SchemaStatus.ENABLED, index.getIndexStatus(key));
}
// Add more data
addVertex(defTime, defText, defHeight, defPhones);
// One more key should be indexed but only sees partial data
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 4, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
}
newTx();
finishSchema();
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REINDEX).get();
mgmt.commit();
finishSchema();
// All the data should now be in the index
clopen(settings);
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
}
mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.DISABLE_INDEX).get();
tx.commit();
mgmt.commit();
ManagementUtil.awaitGraphIndexUpdate(graph, "theIndex", 10, ChronoUnit.SECONDS);
finishSchema();
index = mgmt.getGraphIndex("theIndex");
for (final PropertyKey key : index.getFieldKeys()) {
assertEquals(SchemaStatus.DISABLED, index.getIndexStatus(key));
}
newTx();
// This now requires a full graph scan
evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { false, true });
}
use of org.janusgraph.core.schema.JanusGraphIndex in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testCompositeAndMixedIndexing.
@Test
public void testCompositeAndMixedIndexing() {
final PropertyKey name = makeKey("name", String.class);
final PropertyKey weight = makeKey("weight", Double.class);
final PropertyKey text = makeKey("text", String.class);
makeKey("flag", Boolean.class);
final JanusGraphIndex composite = mgmt.buildIndex("composite", Vertex.class).addKey(name).addKey(weight).buildCompositeIndex();
final JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(weight).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
mixed.name();
composite.name();
finishSchema();
final int numV = 100;
final String[] strings = { "houseboat", "humanoid", "differential", "extraordinary" };
final String[] stringsTwo = new String[strings.length];
for (int i = 0; i < strings.length; i++) stringsTwo[i] = strings[i] + " " + strings[i];
final int modulo = 5;
final int divisor = modulo * strings.length;
for (int i = 0; i < numV; i++) {
final JanusGraphVertex v = tx.addVertex();
v.property("name", strings[i % strings.length]);
v.property("text", strings[i % strings.length]);
v.property("weight", (i % modulo) + 0.5);
v.property("flag", true);
}
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("flag"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, composite.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name(), composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name(), composite.name());
clopen();
// Same queries as above
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("flag"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, composite.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name(), composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has("name", Cmp.EQUAL, strings[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name(), composite.name());
}
Aggregations