Skip to content

Commit

Permalink
[d0LvEgnK] Check the correct behaviour with indexes/constraint using …
Browse files Browse the repository at this point in the history
…the apoc.export.cypher.data/graph procedures (#412)

Co-authored-by: Gemma Lamont <[email protected]>
  • Loading branch information
vga91 and gem-neo4j authored Nov 14, 2024
1 parent 7ae9d81 commit 1f7808a
Show file tree
Hide file tree
Showing 4 changed files with 399 additions and 43 deletions.
14 changes: 11 additions & 3 deletions common/src/main/java/apoc/export/util/NodesAndRelsSubGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,31 @@ public Iterable<Relationship> getRelationships() {
public Iterable<IndexDefinition> getIndexes() {
return getDefinitions(
(schema, label) -> StreamSupport.stream(schema.getIndexes(label).spliterator(), false)
.filter(indexDefinition -> indexDefinition.getIndexType() != IndexType.VECTOR)
.toList(),
(schema, type) -> StreamSupport.stream(schema.getIndexes(type).spliterator(), false)
.filter(indexDefinition -> indexDefinition.getIndexType() != IndexType.VECTOR)
.toList());
}

@Override
public Iterable<ConstraintDefinition> getConstraints() {
Comparator<ConstraintDefinition> comp = Comparator.comparing(ConstraintDefinition::getName);
ArrayList<ConstraintDefinition> definitions = getDefinitions(Schema::getConstraints);
ArrayList<ConstraintDefinition> definitions = getDefinitions(Schema::getConstraints, Schema::getConstraints);
definitions.sort(comp);
return definitions;
}

private <T> ArrayList<T> getDefinitions(BiFunction<Schema, Label, Iterable<T>> biFunction) {
private <T> ArrayList<T> getDefinitions(
BiFunction<Schema, Label, Iterable<T>> nodeFunction,
BiFunction<Schema, RelationshipType, Iterable<T>> relFunction) {
Schema schema = tx.schema();
ArrayList<T> definitions = new ArrayList<>(labels.size() * 2);
for (String label : labels) {
Iterables.addAll(definitions, biFunction.apply(schema, Label.label(label)));
Iterables.addAll(definitions, nodeFunction.apply(schema, Label.label(label)));
}
for (String type : types) {
Iterables.addAll(definitions, relFunction.apply(schema, RelationshipType.withName(type)));
}
return definitions;
}
Expand Down
4 changes: 3 additions & 1 deletion common/src/test/resources/init_neo4j_export_csv.cypher
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ CREATE CONSTRAINT SingleExists FOR (x:Label2) REQUIRE (x.prop) IS NOT NULL;
CREATE CONSTRAINT SingleExistsRel FOR ()<-[r:TYPE2]-() REQUIRE (r.prop) IS NOT NULL;
CREATE CONSTRAINT SingleNodeKey FOR (x:Label3) REQUIRE (x.prop) IS NODE KEY;
CREATE CONSTRAINT PersonRequiresNamesConstraint FOR (t:Person) REQUIRE (t.name, t.surname) IS NODE KEY;
CREATE CONSTRAINT KnowsConsNotNull FOR ()-[r:KNOWS]-() REQUIRE (r.foo) IS NOT NULL;
CREATE CONSTRAINT KnowsConsUnique FOR ()-[r:KNOWS]-() REQUIRE (r.two) IS UNIQUE;

CREATE (a:Person {name: 'John', surname: 'Snow'})
CREATE (b:Person {name: 'Matt', surname: 'Jackson'})
CREATE (c:Person {name: 'Jenny', surname: 'White'})
CREATE (d:Person {name: 'Susan', surname: 'Brown'})
CREATE (e:Person {name: 'Tom', surname: 'Taylor'})
CREATE (a)-[:KNOWS]->(b);
CREATE (a)-[:KNOWS {foo: 1}]->(b);
Loading

0 comments on commit 1f7808a

Please sign in to comment.