From a8e61dffeb00f1522e439312c8baf422f940b965 Mon Sep 17 00:00:00 2001 From: liningrui Date: Thu, 14 Jan 2021 10:55:45 +0800 Subject: [PATCH 1/3] Fix some small bugs and improve experience 1. Allowed modify set/list property in friendly way 2. Check fieldMapping valid --- .../load/FileMappingController.java | 19 +++++++++++++++++++ .../hugegraph/service/graph/GraphService.java | 2 +- .../main/resources/i18n/messages.properties | 4 ++++ .../resources/i18n/messages_zh_CN.properties | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/controller/load/FileMappingController.java b/hubble-be/src/main/java/com/baidu/hugegraph/controller/load/FileMappingController.java index bb68827d..622f07c9 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/controller/load/FileMappingController.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/controller/load/FileMappingController.java @@ -52,6 +52,7 @@ import com.baidu.hugegraph.service.load.JobManagerService; import com.baidu.hugegraph.service.schema.EdgeLabelService; import com.baidu.hugegraph.service.schema.VertexLabelService; +import com.baidu.hugegraph.util.CollectionUtil; import com.baidu.hugegraph.util.Ex; import com.baidu.hugegraph.util.HubbleUtil; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -299,6 +300,21 @@ private void checkVertexMappingValid(int connId, VertexMapping vertexMapping, Ex.check(columnNames.containsAll(vertexMapping.getIdFields()), "load.file-mapping.vertex.id-fields-should-in-column-names", vertexMapping.getIdFields(), columnNames); + if (vl.getIdStrategy().isPrimaryKey()) { + Ex.check(vertexMapping.getIdFields().size() == + vl.getPrimaryKeys().size(), + "load.file-mapping.vertex.id-fields-should-same-size-pks"); + Ex.check(!CollectionUtils.containsAny( + vertexMapping.fieldMappingToMap().values(), + vl.getPrimaryKeys()), + "load.file-mapping.vertex.mapping-fields-cannot-contains-pk"); + } else { + Ex.check(vertexMapping.getIdFields().size() == 1, + "load.file-mapping.vertex.id-fields-should-only-one"); + } + Ex.check(CollectionUtil.allUnique( + vertexMapping.fieldMappingToMap().values()), + "load.file-mapping.mapping-fields-should-no-duplicate"); this.checkMappingValid(vertexMapping, fileMapping); } @@ -324,6 +340,9 @@ private void checkEdgeMappingValid(int connId, EdgeMapping edgeMapping, Ex.check(columnNames.containsAll(edgeMapping.getTargetFields()), "load.file-mapping.edge.target-fields-should-in-column-names", edgeMapping.getTargetFields(), columnNames); + Ex.check(CollectionUtil.allUnique( + edgeMapping.fieldMappingToMap().values()), + "load.file-mapping.mapping-fields-should-no-duplicate"); this.checkMappingValid(edgeMapping, fileMapping); } diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/service/graph/GraphService.java b/hubble-be/src/main/java/com/baidu/hugegraph/service/graph/GraphService.java index 21bf7a95..8ef486ef 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/service/graph/GraphService.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/service/graph/GraphService.java @@ -182,7 +182,7 @@ private void fillProperties(int connId, SchemaLabelEntity schema, try { // DataTypeUtil.convert in loader need param InputSource FileSource source = new FileSource(); - ListFormat listFormat = new ListFormat("[", "]", ","); + ListFormat listFormat = new ListFormat("", "", ","); source.listFormat(listFormat); value = DataTypeUtil.convert(rawValue, propertyKey, source); } catch (IllegalArgumentException e) { diff --git a/hubble-be/src/main/resources/i18n/messages.properties b/hubble-be/src/main/resources/i18n/messages.properties index ad5387a4..a52c3a18 100644 --- a/hubble-be/src/main/resources/i18n/messages.properties +++ b/hubble-be/src/main/resources/i18n/messages.properties @@ -131,9 +131,13 @@ load.file-mapping.vertex.not-exist.label=The vertex mapping doesn't exist with l load.file-mapping.vertex.automatic-id-unsupported=The id strategy of the current vertex label is AUTOMATIC. Such data load operations are not supported. Please implement it by calling the API. load.file-mapping.vertex.id-fields-cannot-be-empty=The id fields can't be empty load.file-mapping.vertex.id-fields-should-in-column-names=The all id fields {0} should be existed in columns names {1} +load.file-mapping.vertex.id-fields-should-same-size-pks=The id strategy of the current vertex label is PRIMARYKEY, the id fields should be consistent with the number of primary keys +load.file-mapping.vertex.mapping-fields-cannot-contains-pk=The id strategy of the current vertex label is PRIMARYKEY, the mapping properties can no longer contain primary keys +load.file-mapping.vertex.id-fields-should-only-one=The id strategy of the current vertex label is PRIMARYKEY, an id field should be specified load.file-mapping.edge.not-exist.label=The edge mapping doesn't exist with label {0} load.file-mapping.edge.source-fields-cannot-be-empty=The source fields can't be empty load.file-mapping.edge.target-fields-cannot-be-empty=The target fields can't be empty +load.file-mapping.mapping-fields-should-no-duplicate= load.file-mapping.load-parameter.max-parse-error.illegal=The load parameter 'max-parse-errors' is illegal load.file-mapping.load-parameter.max-insert-error.illegal=The load parameter 'max-insert-errors' is illegal load.file-mapping.load-parameter.insert-timeout.illegal=The load parameter 'insert-timeout' is illegal diff --git a/hubble-be/src/main/resources/i18n/messages_zh_CN.properties b/hubble-be/src/main/resources/i18n/messages_zh_CN.properties index 0d461b57..2b8f925a 100644 --- a/hubble-be/src/main/resources/i18n/messages_zh_CN.properties +++ b/hubble-be/src/main/resources/i18n/messages_zh_CN.properties @@ -131,9 +131,13 @@ load.file-mapping.vertex.not-exist.label=不存在 label 为 {0} 的顶点映射 load.file-mapping.vertex.automatic-id-unsupported=当前顶点类型的 ID 策略为自动生成,不支持此类数据导入操作,请通过调用 API 实现 load.file-mapping.vertex.id-fields-cannot-be-empty=ID 列不能为空 load.file-mapping.vertex.id-fields-should-in-column-names=ID 列 {0} 必须都属于文件列 {1} +load.file-mapping.vertex.id-fields-should-same-size-pks=当前顶点类型的 ID 策略为主键属性,ID 列应该与主键属性个数一致 +load.file-mapping.vertex.mapping-fields-cannot-contains-pk=当前顶点类型的 ID 策略为主键属性,映射的属性中不能再包含主键属性 +load.file-mapping.vertex.id-fields-should-only-one=当前顶点类型的 ID 策略为自定义,应指定一个 ID 列 load.file-mapping.edge.not-exist.label=不存在 label 为 {0} 的边映射 load.file-mapping.edge.source-fields-cannot-be-empty=起点 ID 列不能为空 load.file-mapping.edge.target-fields-cannot-be-empty=终点 ID 列不能为空 +load.file-mapping.mapping-fields-should-no-duplicate=不允许多列映射到同一属性 load.file-mapping.load-parameter.max-parse-error.illegal=导入参数 允许最大解析错误行数 不合法 load.file-mapping.load-parameter.max-insert-error.illegal=导入参数 允许最大插入错误行数 不合法 load.file-mapping.load-parameter.insert-timeout.illegal=导入参数 插入超时时间/s 不合法 From 1e432d4848b61a23583341e5de2da1285c64deb6 Mon Sep 17 00:00:00 2001 From: liningrui Date: Thu, 14 Jan 2021 14:19:31 +0800 Subject: [PATCH 2/3] tiny improve --- hubble-be/src/main/resources/i18n/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hubble-be/src/main/resources/i18n/messages.properties b/hubble-be/src/main/resources/i18n/messages.properties index a52c3a18..03153f2d 100644 --- a/hubble-be/src/main/resources/i18n/messages.properties +++ b/hubble-be/src/main/resources/i18n/messages.properties @@ -137,7 +137,7 @@ load.file-mapping.vertex.id-fields-should-only-one=The id strategy of the curren load.file-mapping.edge.not-exist.label=The edge mapping doesn't exist with label {0} load.file-mapping.edge.source-fields-cannot-be-empty=The source fields can't be empty load.file-mapping.edge.target-fields-cannot-be-empty=The target fields can't be empty -load.file-mapping.mapping-fields-should-no-duplicate= +load.file-mapping.mapping-fields-should-no-duplicate=Multiple fields are not allowed to map to same property load.file-mapping.load-parameter.max-parse-error.illegal=The load parameter 'max-parse-errors' is illegal load.file-mapping.load-parameter.max-insert-error.illegal=The load parameter 'max-insert-errors' is illegal load.file-mapping.load-parameter.insert-timeout.illegal=The load parameter 'insert-timeout' is illegal From 8063a796157894767976843f461faf13c8f26e5e Mon Sep 17 00:00:00 2001 From: liningrui Date: Thu, 14 Jan 2021 15:16:53 +0800 Subject: [PATCH 3/3] tiny improve --- .../controller/schema/VertexLabelController.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/controller/schema/VertexLabelController.java b/hubble-be/src/main/java/com/baidu/hugegraph/controller/schema/VertexLabelController.java index 40763497..537b05ee 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/controller/schema/VertexLabelController.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/controller/schema/VertexLabelController.java @@ -45,6 +45,7 @@ import com.baidu.hugegraph.entity.schema.VertexLabelEntity; import com.baidu.hugegraph.entity.schema.VertexLabelStyle; import com.baidu.hugegraph.entity.schema.VertexLabelUpdateEntity; +import com.baidu.hugegraph.exception.ExternalException; import com.baidu.hugegraph.service.schema.PropertyIndexService; import com.baidu.hugegraph.service.schema.PropertyKeyService; import com.baidu.hugegraph.service.schema.VertexLabelService; @@ -195,11 +196,20 @@ public Map checkUsing( @DeleteMapping public void delete(@PathVariable("connId") int connId, - @RequestParam("names") List names) { + @RequestParam("names") List names, + @RequestParam(name = "skip_using", + defaultValue = "false") + boolean skipUsing) { for (String name : names) { this.vlService.checkExist(name, connId); - Ex.check(!this.vlService.checkUsing(name, connId), - "schema.vertexlabel.in-using", name); + if (this.vlService.checkUsing(name, connId)) { + if (skipUsing) { + continue; + } else { + throw new ExternalException("schema.vertexlabel.in-using", + name); + } + } this.vlService.remove(name, connId); } }