Skip to content

Commit

Permalink
fix allowed append vl pk or el sk as nullable props (#1406)
Browse files Browse the repository at this point in the history
Change-Id: I9514e088718414809f9b2e1477f358648a581df4
  • Loading branch information
zhoney committed May 27, 2021
1 parent e42f56a commit 2436890
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,15 @@ private void checkNullableKeys(Action action) {
"must belong to the origin/new properties: %s/%s ",
this.nullableKeys, originProps, appendProps);

E.checkArgument(!CollectionUtil.hasIntersection(this.sortKeys,
List<String> sortKeys = edgeLabel == null ?
this.sortKeys :
this.graph()
.mapPkId2Name(edgeLabel.sortKeys());
E.checkArgument(!CollectionUtil.hasIntersection(sortKeys,
this.nullableKeys),
"The nullableKeys: %s are not allowed to " +
"belong to sortKeys: %s of edge label '%s'",
this.nullableKeys, this.sortKeys, this.name);
this.nullableKeys, sortKeys, this.name);

if (action == Action.APPEND) {
Collection<String> newAddedProps = CollectionUtils.subtract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,15 @@ private void checkNullableKeys(Action action) {
"must belong to the origin/new properties: %s/%s",
this.nullableKeys, originProps, appendProps);

E.checkArgument(!CollectionUtil.hasIntersection(this.primaryKeys,
List<String> primaryKeys = vertexLabel == null ?
this.primaryKeys :
this.graph()
.mapPkId2Name(vertexLabel.primaryKeys());
E.checkArgument(!CollectionUtil.hasIntersection(primaryKeys,
this.nullableKeys),
"The nullableKeys: %s are not allowed to " +
"belong to primaryKeys: %s of vertex label '%s'",
this.nullableKeys, this.primaryKeys, this.name);
this.nullableKeys, primaryKeys, this.name);

if (action == Action.APPEND) {
Collection<String> newAddedProps = CollectionUtils.subtract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,31 @@ public void testAppendEdgeLabelWithNonNullProperties() {

}

@Test
public void testAppendEdgeLabelWithSkAsNullableProperties() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person")
.properties("name", "age", "city")
.primaryKeys("name")
.create();
schema.vertexLabel("book").properties("id", "name")
.primaryKeys("id").create();
schema.edgeLabel("look")
.properties("time")
.link("person", "book")
.multiTimes().sortKeys("time")
.create();

Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("look")
.properties("time", "weight")
.nullableKeys("time", "weight")
.append();
});

}

@Test
public void testRemoveEdgeLabel() {
super.initPropertyKeys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,23 @@ public void testAppendVertexLabelWithNonNullProperties() {
});
}

@Test
public void testAppendVertexLabelWithPkAsNullableProperties() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();

schema.vertexLabel("person")
.properties("name", "age")
.primaryKeys("name")
.create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person")
.properties("name", "city")
.nullableKeys("name", "city")
.append();
});
}

@Test
public void testRemoveVertexLabel() {
super.initPropertyKeys();
Expand Down

0 comments on commit 2436890

Please sign in to comment.