From bf81b5676782387b213037e1badfcb31eeef747f Mon Sep 17 00:00:00 2001 From: zhangyi51 Date: Tue, 30 Mar 2021 20:30:48 +0800 Subject: [PATCH] fix allowed append vl pk or el sk as nullable props Change-Id: I9514e088718414809f9b2e1477f358648a581df4 --- .../schema/builder/EdgeLabelBuilder.java | 8 ++++-- .../schema/builder/VertexLabelBuilder.java | 8 ++++-- .../hugegraph/core/EdgeLabelCoreTest.java | 25 +++++++++++++++++++ .../hugegraph/core/VertexLabelCoreTest.java | 17 +++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java index c3837bc359..ffca6e66ac 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/EdgeLabelBuilder.java @@ -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 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 newAddedProps = CollectionUtils.subtract( diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java index 71edc6c5e8..fdeafbca11 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/VertexLabelBuilder.java @@ -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 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 newAddedProps = CollectionUtils.subtract( diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java index 4a7080b284..764c3f753f 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java @@ -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(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java index 79525d8cbe..e26c76613c 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java @@ -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();