Skip to content
Permalink
Browse files
Fix parser exception cannot be caught (#74)
  • Loading branch information
imbajin authored and javeme committed Jun 17, 2019
1 parent 6a2e57f commit c368900993eb393b181f0ab8edf4d209bc916f98
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
@@ -188,8 +188,11 @@ private LoadSummary loadVertices() {
private void loadVertex(VertexBuilder builder) {
int batchSize = this.options.batchSize;
List<Vertex> batch = new ArrayList<>(batchSize);
while (builder.hasNext()) {
while (true) {
try {
if (!builder.hasNext()) {
break;
}
Vertex vertex = builder.next();
batch.add(vertex);
} catch (ParseException e) {
@@ -253,8 +256,11 @@ private LoadSummary loadEdges() {
private void loadEdge(EdgeBuilder builder) {
int batchSize = this.options.batchSize;
List<Edge> batch = new ArrayList<>(batchSize);
while (builder.hasNext()) {
while (true) {
try {
if (!builder.hasNext()) {
break;
}
Edge edge = builder.next();
batch.add(edge);
} catch (ParseException e) {
@@ -32,7 +32,7 @@

public final class JsonUtil {

private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper MAPPER = new ObjectMapper();

static {
SimpleModule module = new SimpleModule();
@@ -41,26 +41,26 @@ public final class JsonUtil {
}

public static void registerModule(Module module) {
mapper.registerModule(module);
MAPPER.registerModule(module);
}

public static String toJson(Object object) {
try {
return mapper.writeValueAsString(object);
return MAPPER.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new SerializeException("Failed to serialize objects", e);
}
}

public static <T> T fromJson(String json, Class<T> clazz) {
try {
return mapper.readValue(json, clazz);
return MAPPER.readValue(json, clazz);
} catch (IOException e) {
throw new SerializeException("Failed to deserialize json", e);
}
}

public static <T> T convert(JsonNode node, Class<T> clazz) {
return mapper.convertValue(node, clazz);
return MAPPER.convertValue(node, clazz);
}
}
@@ -1246,4 +1246,24 @@ public void testLZ4FramedCompressFile() {
};
HugeGraphLoader.main(args);
}

@Test
public void testParserNotThrowException() {
// Here are 2 parse errors, and expect no exception thrown
ioUtil.write("vertex_person.csv",
"name,age,city",
"p1,marko,22,Beijing",
"tom,24,Hongkong",
"jerry,18");

String[] args = new String[]{
"-f", configPath("too_few_columns/struct.json"),
"-s", configPath("too_few_columns/schema.groovy"),
"-g", GRAPH,
"-h", SERVER,
"--num-threads", "2",
"--max-parse-errors", "3"
};
HugeGraphLoader.main(args);
}
}

0 comments on commit c368900

Please sign in to comment.