private String iterateIndexes(String pattern, Iterable<JanusGraphIndex> indexes) { StringBuilder sb = new StringBuilder(); for (JanusGraphIndex index: indexes) { String type = getIndexType(index); PropertyKey[] keys = index.getFieldKeys(); String[][] keyStatus = getKeyStatus(keys, index); sb.append(String.format(pattern, index.name(), type, index.isUnique(), index.getBackingIndex(), keyStatus[0][0] + ":", keyStatus[0][1])); if (keyStatus.length > 1) { for (int i = 1; i < keyStatus.length; i++) { sb.append(String.format(pattern, "", "", "", "", keyStatus[i][0] + ":", keyStatus[i][1])); } } } return sb.toString(); }
final JanusGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(weight) .addKey(text, getTextMapping()).buildMixedIndex(INDEX); mixed.name(); composite.name(); finishSchema(); 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()); 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());
if (parameters == null) parameters = new Parameter[0]; IndexType indexType = ((JanusGraphIndexWrapper) index).getBaseIndex(); Preconditions.checkArgument(indexType instanceof MixedIndexType, "Can only add keys to an external index, not %s", index.name()); Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof JanusGraphSchemaVertex && ((IndexTypeWrapper) indexType).getSchemaBase() instanceof JanusGraphSchemaVertex); Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name());
assertEquals("prop1", prop1.name()); assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement())); assertTrue(JanusGraphVertexProperty.class.isAssignableFrom(prop1.getIndexedElement())); assertEquals("prop1", prop1.name()); assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement())); assertTrue(JanusGraphVertexProperty.class.isAssignableFrom(prop1.getIndexedElement())); ElementCategory.EDGE, 1, new boolean[]{true, sorted}, edge1.name()); evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(10, 20, 30)).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 3, new boolean[]{true, sorted}, edge1.name()); evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0) .has("text", Cmp.EQUAL, strings[10 % strings.length]), ElementCategory.EDGE, 1, new boolean[]{false, sorted}, edge1.name()); evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 1), ElementCategory.EDGE, 1, new boolean[]{true, sorted}, edge1.name()); evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[]{true, sorted}, edge1.name()); evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 3), ElementCategory.EDGE, 0, new boolean[]{true, sorted}, edge1.name()); evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect"), ElementCategory.EDGE, numV / strings.length, new boolean[]{true, sorted}, edge2.name()); evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[]{true, sorted}, edge2.name()); evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]), ElementCategory.EDGE, numV / strings.length * 2, new boolean[]{false, sorted}); ElementCategory.PROPERTY, 2, new boolean[]{true, sorted}, prop1.name()); evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strings[0]),
assertEquals("index2", index2.name()); assertEquals(INDEX, index3.getBackingIndex()); assertFalse(index2.isUnique()); assertEquals("index2", index2.name()); assertEquals(INDEX, index3.getBackingIndex()); assertFalse(index2.isUnique()); numV / strings.length, new boolean[]{true, true}, index2.name()); evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", decr), ElementCategory.VERTEX, numV / strings.length, new boolean[]{true, true}, weight, Order.DESC, index2.name()); evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[3]).has(LABEL_NAME, Cmp.EQUAL, "org"), ElementCategory.VERTEX, numV / strings.length, new boolean[]{true, true}, index3.name()); evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[1]).has(LABEL_NAME, Cmp.EQUAL, "org").orderBy("weight", decr), ElementCategory.VERTEX, numV / strings.length, new boolean[]{true, true}, weight, Order.DESC, index3.name()); evaluateQuery(tx.query().has("text", Text.CONTAINS, strings[0]).has("weight", Cmp.EQUAL, 2.5).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / (modulo * strings.length), new boolean[]{true, true}, index2.name()); evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[]{false, true}, index1.name()); evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[3]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, 0, new boolean[]{false, true}, index1.name()); evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]), ElementCategory.VERTEX, numV / strings.length, new boolean[]{true, true}, index1.name()); evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[2]).has("text", Text.CONTAINS, strings[2]).has(LABEL_NAME, Cmp.EQUAL, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[]{true, true}, index1.name(), index2.name()); evaluateQuery(tx.query().has("name", Cmp.EQUAL, strings[0]).has("text", Text.CONTAINS, strings[0]).has(LABEL_NAME, Cmp.EQUAL, "person").orderBy("weight", incr), ElementCategory.VERTEX, numV / strings.length, new boolean[]{true, true}, weight, Order.ASC, index1.name(), index2.name()); numV / strings.length, new boolean[]{true, true}, index2.name());
mixed.name(); finishSchema();
JanusGraphIndex graphIndex = mgmt.getGraphIndex("timeIndex"); mgmt.changeName(graphIndex, "byTime"); assertEquals("byTime", graphIndex.name());
private Set<String> getIndexKeys(Class<? extends Element> janusGraphElementClass) { JanusGraphManagement mgmt = getGraph().openManagement(); Iterable<JanusGraphIndex> indices = mgmt.getGraphIndexes(janusGraphElementClass); Set<String> result = new HashSet<String>(); for (JanusGraphIndex index : indices) { result.add(index.name()); } mgmt.commit(); return result; }