String invalidIndexHint; if (index instanceof RelationTypeIndex || (index instanceof JanusGraphIndex && ((JanusGraphIndex)index).isCompositeIndex()) ) { SchemaStatus actualStatus = schemaVertex.getStatus(); isValidIndex = acceptableStatuses.contains(actualStatus); Preconditions.checkArgument(index instanceof JanusGraphIndex,"Unexpected index: %s",index); JanusGraphIndex graphIndex = (JanusGraphIndex)index; Preconditions.checkArgument(graphIndex.isMixedIndex()); Map<String, SchemaStatus> invalidKeyStatuses = new HashMap<>(); int acceptableFields = 0; for (PropertyKey key : graphIndex.getFieldKeys()) { SchemaStatus status = graphIndex.getIndexStatus(key); if (status!=SchemaStatus.DISABLED && !acceptableStatuses.contains(status)) { isValidIndex=false;
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(); }
private String getIndexType(JanusGraphIndex index) { String type; if (index.isCompositeIndex()) { type = "Composite"; } else if (index.isMixedIndex()) { type = "Mixed"; } else { type = "Unknown"; } return type; }
assertTrue(Vertex.class.isAssignableFrom(index1.getIndexedElement())); assertEquals("index2", index2.name()); assertEquals(INDEX, index3.getBackingIndex()); assertFalse(index2.isUnique()); assertEquals(2, index3.getFieldKeys().length); assertEquals(1, index1.getFieldKeys().length); assertEquals(3, index3.getParametersFor(text).length); assertEquals(2, index3.getParametersFor(weight).length); assertTrue(Vertex.class.isAssignableFrom(index1.getIndexedElement())); assertEquals("index2", index2.name()); assertEquals(INDEX, index3.getBackingIndex()); assertFalse(index2.isUnique()); assertEquals(2, index3.getFieldKeys().length); assertEquals(1, index1.getFieldKeys().length); assertEquals(3, index3.getParametersFor(text).length); assertEquals(2, index3.getParametersFor(weight).length); 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());
assertTrue(vertex1.isUnique()); assertFalse(edge2.isUnique()); assertEquals("prop1", prop1.name()); assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement())); assertTrue(JanusGraphVertexProperty.class.isAssignableFrom(prop1.getIndexedElement())); assertTrue(Edge.class.isAssignableFrom(edge2.getIndexedElement())); assertEquals(2, vertex2.getFieldKeys().length); assertEquals(1, vertex1.getFieldKeys().length); assertTrue(vertex1.isUnique()); assertFalse(edge2.isUnique()); assertEquals("prop1", prop1.name()); assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement())); assertTrue(JanusGraphVertexProperty.class.isAssignableFrom(prop1.getIndexedElement())); assertTrue(Edge.class.isAssignableFrom(edge2.getIndexedElement())); assertEquals(2, vertex2.getFieldKeys().length); assertEquals(1, vertex1.getFieldKeys().length); 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),
management = g.openManagement(); idx = management.getGraphIndex(graphIndexName); for (PropertyKey pk : idx.getFieldKeys()) { SchemaStatus s = idx.getIndexStatus(pk); LOGGER.debug("Key {} has status {}", pk, s); if (!statuses.contains(s))
@Override protected void validateIndexStatus() { if(!(index instanceof RelationTypeIndex || index instanceof JanusGraphIndex)) { throw new UnsupportedOperationException("Unsupported index found: "+index); } if (index instanceof JanusGraphIndex) { JanusGraphIndex graphIndex = (JanusGraphIndex)index; if (graphIndex.isMixedIndex()) throw new UnsupportedOperationException("Cannot remove mixed indexes through JanusGraph. This can " + "only be accomplished in the indexing system directly."); CompositeIndexType indexType = (CompositeIndexType) managementSystem.getSchemaVertex(index).asIndexType(); graphIndexId = indexType.getID(); } //Must be a relation type index or a composite graph index JanusGraphSchemaVertex schemaVertex = managementSystem.getSchemaVertex(index); SchemaStatus actualStatus = schemaVertex.getStatus(); Preconditions.checkArgument(actualStatus==SchemaStatus.DISABLED,"The index [%s] must be disabled before it can be removed",indexName); }
assertEquals(1, graphIndex.getFieldKeys().length); assertEquals(name, graphIndex.getFieldKeys()[0].name()); assertEquals("internalindex", graphIndex.getBackingIndex()); assertEquals(SchemaStatus.ENABLED, graphIndex.getIndexStatus(graphIndex.getFieldKeys()[0])); finishSchema();
if (!updateAction.isApplicableStatus(schemaVertex.getStatus())) return null; for (PropertyKey key : ((JanusGraphIndex) index).getFieldKeys()) { dependentTypes.add((PropertyKeyVertex) key); } else { JanusGraphIndex graphIndex = (JanusGraphIndex) index; if (graphIndex.isMixedIndex()) throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly."); builder = graph.getBackend().buildGraphIndexScanJob();
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());
private String[][] getKeyStatus(PropertyKey[] keys, JanusGraphIndex index) { String[][] keyStatus = new String[keys.length][2]; for (int i = 0; i < keys.length; i++) { keyStatus[i][0] = keys[i].name(); keyStatus[i][1] = index.getIndexStatus(keys[i]).name(); } return keyStatus.length > 0 ? keyStatus: new String[][] {{"",""}}; }
assertEquals(1, sig.length); assertEquals(weight.longId(), sig[0]); assertTrue(mgmt.getGraphIndex(uid.name()).isUnique()); assertFalse(mgmt.getGraphIndex(someId.name()).isUnique()); assertEquals(1, sig.length); assertEquals(weight.longId(), sig[0]); assertTrue(mgmt.getGraphIndex(uid.name()).isUnique()); assertFalse(mgmt.getGraphIndex(someId.name()).isUnique());
@Override public Set<AtlasPropertyKey> getFieldKeys() { PropertyKey[] keys = wrapped.getFieldKeys(); Set<AtlasPropertyKey> result = new HashSet<AtlasPropertyKey>(); for(PropertyKey key : keys) { result.add(GraphDbObjectFactory.createPropertyKey(key)); } return result; }
@Override public boolean isVertexIndex() { return Vertex.class.isAssignableFrom(wrapped.getIndexedElement()); }
@Override public boolean isCompositeIndex() { return wrapped.isCompositeIndex(); }
Preconditions.checkArgument(idx!=null,"Index could not be found: %s",indexName); isStable = true; for (PropertyKey key : idx.getFieldKeys()) { if (!idx.getIndexStatus(key).isStable()) isStable = false;
@Override public boolean isMixedIndex() { return wrapped.isMixedIndex(); }
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());
@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyWithoutLabelConstraint() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); mgmt.buildIndex("newIndex", Vertex.class).addKey(existingPropertyKey).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Override public boolean isUnique() { return wrapped.isUnique(); }