You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by je...@apache.org on 2022/11/21 12:32:06 UTC
[incubator-hugegraph-toolchain] branch master updated: [fix][loader] Fix deserialize json error (#376)
This is an automated email from the ASF dual-hosted git repository.
jermy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git
The following commit(s) were added to refs/heads/master by this push:
new c979b86e [fix][loader] Fix deserialize json error (#376)
c979b86e is described below
commit c979b86e3e6a6c26229f9942ee2b866b9e02e07d
Author: Cong Zhao <zh...@apache.org>
AuthorDate: Mon Nov 21 20:32:00 2022 +0800
[fix][loader] Fix deserialize json error (#376)
---
.../hugegraph/loader/mapping/LoadMapping.java | 1 -
.../loader/test/functional/FileLoadTest.java | 19 +++++++++++++++++
.../src/test/resources/mapping_v2/schema.groovy | 24 ++++++++++++++++++++++
.../src/test/resources/mapping_v2/struct.json | 22 ++++++++++++++++++++
4 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/mapping/LoadMapping.java b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/mapping/LoadMapping.java
index 7a403d25..c7f74222 100644
--- a/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/mapping/LoadMapping.java
+++ b/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/mapping/LoadMapping.java
@@ -81,7 +81,6 @@ public class LoadMapping implements Checkable {
return mapping;
}
- @JsonCreator
public LoadMapping(@JsonProperty("structs") List<InputStruct> structs) {
this.version = Constants.V2_STRUCT_VERSION;
this.structs = structs;
diff --git a/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java b/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
index e46310be..0e195df6 100644
--- a/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
+++ b/hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java
@@ -1852,6 +1852,25 @@ public class FileLoadTest extends LoadTest {
HugeGraphLoader.main(args);
}
+ @Test
+ public void testParserV2() {
+ ioUtil.write("vertex_person.csv",
+ "name,age,city",
+ "tom,24,Hongkong",
+ "jerry,18");
+
+ String[] args = new String[]{
+ "-f", structPath("mapping_v2/struct.json"),
+ "-s", configPath("mapping_v2/schema.groovy"),
+ "-g", GRAPH,
+ "-h", SERVER,
+ "-p", String.valueOf(PORT),
+ "--batch-insert-threads", "2",
+ "--max-parse-errors", "1"
+ };
+ HugeGraphLoader.main(args);
+ }
+
@Test
public void testBatchUpdateElement() {
ioUtil.write("vertex_person.txt",
diff --git a/hugegraph-loader/src/test/resources/mapping_v2/schema.groovy b/hugegraph-loader/src/test/resources/mapping_v2/schema.groovy
new file mode 100644
index 00000000..80346fd1
--- /dev/null
+++ b/hugegraph-loader/src/test/resources/mapping_v2/schema.groovy
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+// Define schema
+schema.propertyKey("name").asText().ifNotExist().create();
+schema.propertyKey("age").asInt().ifNotExist().create();
+schema.propertyKey("city").asText().ifNotExist().create();
+
+schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create();
diff --git a/hugegraph-loader/src/test/resources/mapping_v2/struct.json b/hugegraph-loader/src/test/resources/mapping_v2/struct.json
new file mode 100644
index 00000000..7b7ebc6a
--- /dev/null
+++ b/hugegraph-loader/src/test/resources/mapping_v2/struct.json
@@ -0,0 +1,22 @@
+{
+ "version": "2.0",
+ "structs": [{
+ "id": 1,
+ "input": {
+ "type": "${source_type}",
+ "path": "${store_path}/vertex_person.csv",
+ "format": "CSV",
+ "charset": "UTF-8"
+ },
+ "vertices": [
+ {
+ "label": "person",
+ "field_mapping": {
+ "name": "name",
+ "age": "age",
+ "city": "city"
+ }
+ }
+ ]
+ }]
+}