diff --git a/common/src/main/java/apoc/result/IndexConstraintNodeInfo.java b/common/src/main/java/apoc/result/IndexConstraintNodeInfo.java index 75a25c1d4..f3a251a28 100644 --- a/common/src/main/java/apoc/result/IndexConstraintNodeInfo.java +++ b/common/src/main/java/apoc/result/IndexConstraintNodeInfo.java @@ -34,18 +34,18 @@ public class IndexConstraintNodeInfo { * @param label * @param properties * @param status status of the index, if it's a constraint it will be empty - * @param type if it is an index type will be "INDEX" otherwise it will be the type of constraint + * @param schemaType if it is an index type will be "INDEX" otherwise it will be the type of constraint * @param failure * @param populationProgress * @param size * @param userDescription */ - public IndexConstraintNodeInfo(String name, Object label, List properties, String status, String type, String failure, float populationProgress, long size, double valuesSelectivity, String userDescription) { + public IndexConstraintNodeInfo(String name, Object label, List properties, String status, String schemaType, String failure, float populationProgress, long size, double valuesSelectivity, String userDescription) { this.name = name; this.label = label; this.properties = properties; this.status = status; - this.type = type; + this.type = schemaType; this.failure = failure; this.populationProgress = populationProgress; this.size = size; diff --git a/common/src/main/java/apoc/result/IndexConstraintRelationshipInfo.java b/common/src/main/java/apoc/result/IndexConstraintRelationshipInfo.java index 96e52b1b6..68559d586 100644 --- a/common/src/main/java/apoc/result/IndexConstraintRelationshipInfo.java +++ b/common/src/main/java/apoc/result/IndexConstraintRelationshipInfo.java @@ -9,16 +9,19 @@ public class IndexConstraintRelationshipInfo { public final String name; - public final Object type; + public final String type; public final List properties; public final String status; + + public final Object relationshipType; - public IndexConstraintRelationshipInfo(String name, Object type, List properties, String status) { + public IndexConstraintRelationshipInfo(String name, String schemaType, List properties, String status, Object relationshipType) { this.name = name; - this.type = type; + this.type = schemaType; this.properties = properties; this.status = status; + this.relationshipType = relationshipType; } } \ No newline at end of file diff --git a/core/src/main/java/apoc/schema/Schemas.java b/core/src/main/java/apoc/schema/Schemas.java index c6fbe16eb..e5089325f 100644 --- a/core/src/main/java/apoc/schema/Schemas.java +++ b/core/src/main/java/apoc/schema/Schemas.java @@ -534,7 +534,7 @@ private IndexConstraintNodeInfo nodeInfoFromIndexDefinition(IndexDescriptor inde labelName, properties, schemaRead.indexGetState(indexDescriptor).toString(), - !indexDescriptor.isUnique() ? "INDEX" : "UNIQUENESS", + getIndexType(indexDescriptor), schemaRead.indexGetState(indexDescriptor).equals(InternalIndexState.FAILED) ? schemaRead.indexGetFailure(indexDescriptor) : "NO FAILURE", schemaRead.indexGetPopulationProgress(indexDescriptor).getCompleted() / schemaRead.indexGetPopulationProgress(indexDescriptor).getTotal() * 100, schemaRead.indexSize(indexDescriptor), @@ -548,7 +548,7 @@ private IndexConstraintNodeInfo nodeInfoFromIndexDefinition(IndexDescriptor inde labelName, properties, "NOT_FOUND", - !indexDescriptor.isUnique() ? "INDEX" : "UNIQUENESS", + getIndexType(indexDescriptor), "NOT_FOUND", 0,0,0, indexDescriptor.userDescription(tokens) @@ -574,14 +574,15 @@ private IndexConstraintRelationshipInfo relationshipInfoFromIndexDescription(Ind .mapToObj(tokens::propertyKeyGetName) .collect(Collectors.toList()); try { - return new IndexConstraintRelationshipInfo(getSchemaInfoName(relName, properties), relName, properties, schemaRead.indexGetState(indexDescriptor).toString()); + return new IndexConstraintRelationshipInfo(getSchemaInfoName(relName, properties), "INDEX", properties, schemaRead.indexGetState(indexDescriptor).toString(), relName); } catch (IndexNotFoundKernelException e) { return new IndexConstraintRelationshipInfo( // Pretty print for index name getSchemaInfoName(relName, properties), - relName, + getIndexType(indexDescriptor), properties, - "NOT_FOUND" + "NOT_FOUND", + relName ); } } @@ -597,10 +598,15 @@ private IndexConstraintRelationshipInfo relationshipInfoFromConstraintDefinition String.format("CONSTRAINT %s", constraintDefinition.toString()), constraintDefinition.getConstraintType().name(), Iterables.asList(constraintDefinition.getPropertyKeys()), - "" + "", + constraintDefinition.getRelationshipType().name() ); } + private static String getIndexType(IndexDescriptor indexDescriptor) { + return indexDescriptor.isUnique() ? "UNIQUENESS" : "INDEX"; + } + private String getSchemaInfoName(Object labelOrType, List properties) { final String labelOrTypeAsString = labelOrType instanceof String ? (String) labelOrType : StringUtils.join(labelOrType, ","); return String.format(":%s(%s)", labelOrTypeAsString, StringUtils.join(properties, ",")); diff --git a/core/src/test/java/apoc/schema/SchemasEnterpriseFeaturesTest.java b/core/src/test/java/apoc/schema/SchemasEnterpriseFeaturesTest.java index 57828e30c..0bd502043 100644 --- a/core/src/test/java/apoc/schema/SchemasEnterpriseFeaturesTest.java +++ b/core/src/test/java/apoc/schema/SchemasEnterpriseFeaturesTest.java @@ -382,6 +382,7 @@ public void testSchemaRelationships() { Map r = result.next(); assertEquals("CONSTRAINT FOR ()-[liked:LIKED]-() REQUIRE liked.day IS NOT NULL", r.get("name")); assertEquals("RELATIONSHIP_PROPERTY_EXISTENCE", r.get("type")); + assertEquals("LIKED", r.get("relationshipType")); assertEquals(asList("day"), r.get("properties")); assertEquals(StringUtils.EMPTY, r.get("status")); assertFalse(result.hasNext()); @@ -401,12 +402,13 @@ public void testSchemaNodeWithRelationshipsConstraintsAndViceVersa() { tx.commit(); return null; }); - testResult(session, "CALL apoc.schema.relationships() YIELD name, type, properties, status " + + testResult(session, "CALL apoc.schema.relationships() YIELD name, type, properties, status, relationshipType " + "WHERE type <> '' " + "RETURN *", (result) -> { Map r = result.next(); assertEquals("CONSTRAINT FOR ()-[liked:LIKED]-() REQUIRE liked.day IS NOT NULL", r.get("name")); assertEquals("RELATIONSHIP_PROPERTY_EXISTENCE", r.get("type")); + assertEquals("LIKED", r.get("relationshipType")); assertEquals(asList("day"), r.get("properties")); assertEquals(StringUtils.EMPTY, r.get("status")); assertFalse(result.hasNext()); diff --git a/core/src/test/java/apoc/schema/SchemasTest.java b/core/src/test/java/apoc/schema/SchemasTest.java index 488d861bb..5645bb3d4 100644 --- a/core/src/test/java/apoc/schema/SchemasTest.java +++ b/core/src/test/java/apoc/schema/SchemasTest.java @@ -349,7 +349,8 @@ public void testRelIndex() { testCall(db, "CALL apoc.schema.relationships()", row -> { assertEquals(":KNOWS(id,since)", row.get("name")); assertEquals("ONLINE", row.get("status")); - assertEquals("KNOWS", row.get("type")); + assertEquals("KNOWS", row.get("relationshipType")); + assertEquals("INDEX", row.get("type")); assertEquals(List.of("id", "since"), row.get("properties")); }); } @@ -712,7 +713,8 @@ public void testLookupIndexes() { testCall(db, "CALL apoc.schema.relationships()", (row) -> { assertEquals(":" + TOKEN_REL_TYPE + "()", row.get("name")); assertEquals("ONLINE", row.get("status")); - assertEquals(TOKEN_REL_TYPE, row.get("type")); + assertEquals("INDEX", row.get("type")); + assertEquals(TOKEN_REL_TYPE, row.get("relationshipType")); assertTrue(((List)row.get("properties")).isEmpty()); }); } @@ -753,8 +755,9 @@ public void testIndexesWithMultipleLabelsAndRelTypes() { testCall(db, "CALL apoc.schema.relationships()", (r) -> { assertEquals(":[TYPE_1, TYPE_2],(alpha,beta)", r.get("name")); assertEquals("ONLINE", r.get("status")); - assertEquals(List.of("TYPE_1", "TYPE_2"), r.get("type")); + assertEquals(List.of("TYPE_1", "TYPE_2"), r.get("relationshipType")); assertEquals(List.of("alpha", "beta"), r.get("properties")); + assertEquals("INDEX", r.get("type")); }); } }