Skip to content

Commit 140f249

Browse files
nord-erikfbiville
andauthored
feat: allow duplication in schema element names (#338)
This commit relaxes validation DUPL-011, which, until now, strictly forbade schema element name duplications. This PR changes so that element names are allowed to be duplicates if they are equivalent. E.g. they share both the schema type and graph pattern. Co-authored-by: Florent Biville <florent.biville@neo4j.com>
1 parent f6cc439 commit 140f249

File tree

4 files changed

+414
-247
lines changed

4 files changed

+414
-247
lines changed

core/src/main/java/org/neo4j/importer/v1/targets/EntityTarget.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public <T extends EntityTargetExtension> Optional<T> getExtension(Class<T> type)
6969
.findFirst();
7070
}
7171

72+
public abstract Schema getSchema();
73+
7274
@Override
7375
public boolean equals(Object o) {
7476
if (!(o instanceof EntityTarget)) return false;

core/src/main/java/org/neo4j/importer/v1/targets/NodeTarget.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import java.util.Objects;
2525

2626
public class NodeTarget extends EntityTarget {
27-
2827
private final List<String> labels;
29-
3028
private final NodeSchema schema;
3129

3230
@JsonCreator

core/src/main/java/org/neo4j/importer/v1/validation/plugin/NoDuplicatedSchemaNameValidator.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class NoDuplicatedSchemaNameValidator implements SpecificationValidator {
2626
private static final String ERROR_CODE = "DUPL-011";
27-
private final List<SchemaElement> elements = new ArrayList<>();
27+
private final Set<SchemaElement> elements = new LinkedHashSet<>();
2828

2929
@Override
3030
public Set<Class<? extends SpecificationValidator>> requires() {
@@ -53,7 +53,7 @@ public void visitRelationshipTarget(int index, RelationshipTarget target) {
5353
public boolean report(Builder builder) {
5454
var duplicates = elements.stream().collect(Collectors.groupingBy(SchemaElement::getName)).entrySet().stream()
5555
.filter(e -> e.getValue().size() > 1)
56-
.collect(Collectors.toList());
56+
.collect(Collectors.toCollection(LinkedHashSet::new));
5757

5858
duplicates.forEach(dup -> builder.addError(
5959
dup.getValue().get(0).getPath(),
@@ -115,6 +115,19 @@ public String getName() {
115115
public String getPath() {
116116
return path;
117117
}
118+
119+
@Override
120+
public boolean equals(Object o) {
121+
if (this == o) return true;
122+
if (o == null || getClass() != o.getClass()) return false;
123+
ConstraintElement that = (ConstraintElement) o;
124+
return Objects.equals(constraint, that.constraint);
125+
}
126+
127+
@Override
128+
public int hashCode() {
129+
return Objects.hash(constraint);
130+
}
118131
}
119132

120133
private static class IndexElement implements SchemaElement {
@@ -133,5 +146,18 @@ public String getName() {
133146
public String getPath() {
134147
return path;
135148
}
149+
150+
@Override
151+
public boolean equals(Object o) {
152+
if (this == o) return true;
153+
if (o == null || getClass() != o.getClass()) return false;
154+
IndexElement that = (IndexElement) o;
155+
return Objects.equals(index, that.index);
156+
}
157+
158+
@Override
159+
public int hashCode() {
160+
return Objects.hash(index);
161+
}
136162
}
137163
}

0 commit comments

Comments
 (0)