Skip to content
Permalink
Browse files
Fix empty table hasNext return true (#90)
Change-Id: I6449b93a23c01ed804c71c650d9f8712b26a1af7
  • Loading branch information
Linary authored and zhoney committed Aug 19, 2019
1 parent 8698380 commit 9297286010ab74e3ce1b85cc96c9db25f42812c3
Showing 8 changed files with 112 additions and 2 deletions.
@@ -24,7 +24,7 @@
<dependency>
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-client</artifactId>
<version>1.7.4</version>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -74,7 +74,7 @@ public boolean hasNext() {
throw new LoadException("Error while reading the next row", e);
}
}
return this.batch != null;
return this.batch != null && !this.batch.isEmpty();
}

@Override
@@ -943,6 +943,40 @@ public void testDirHasNoFile() {
Assert.assertEquals(0, vertices.size());
}

@Test
public void testEmptyFileWithHeader() {
ioUtil.write("vertex_person.csv");

String[] args = new String[]{
"-f", configPath("empty_file_with_header/struct.json"),
"-s", configPath("empty_file_with_header/schema.groovy"),
"-g", GRAPH,
"-h", SERVER,
"--test-mode", "true"
};
HugeGraphLoader.main(args);

List<Vertex> vertices = CLIENT.graph().listVertices();
Assert.assertEquals(0, vertices.size());
}

@Test
public void testEmptyFileWithoutHeader() {
ioUtil.write("vertex_person.csv");

String[] args = new String[]{
"-f", configPath("empty_file_without_header/struct.json"),
"-s", configPath("empty_file_without_header/schema.groovy"),
"-g", GRAPH,
"-h", SERVER,
"--test-mode", "true"
};

Assert.assertThrows(LoadException.class, () -> {
HugeGraphLoader.main(args);
});
}

@Test
public void testDirHasMultiFiles() {
ioUtil.write("vertex_dir/vertex_person1.csv",
@@ -167,6 +167,25 @@ public void testCustomizedSchema() {
}
}

@Test
public void testEmptyTable() {
String[] args = new String[]{
"-f", configPath("jdbc_customized_schema/struct.json"),
"-s", configPath("jdbc_customized_schema/schema.groovy"),
"-g", GRAPH,
"-h", SERVER,
"--num-threads", "2",
"--test-mode", "true"
};
HugeGraphLoader.main(args);

List<Vertex> vertices = CLIENT.graph().listVertices();
List<Edge> edges = CLIENT.graph().listEdges();

Assert.assertEquals(0, vertices.size());
Assert.assertEquals(0, edges.size());
}

@Test
public void testValueMappingInJDBCSource() {
dbUtil.insert("INSERT INTO `person` VALUES " +
@@ -0,0 +1,10 @@
// Define schema
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("city").asText().ifNotExist().create();
schema.propertyKey("weight").asDouble().ifNotExist().create();
schema.propertyKey("date").asText().ifNotExist().create();

schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name", "city").ifNotExist().create();

schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date", "weight").ifNotExist().create();
@@ -0,0 +1,19 @@
{
"vertices": [
{
"label": "person",
"input": {
"type": "${source_type}",
"path": "${store_path}/vertex_person.csv",
"header": ["name", "age", "city"],
"format": "CSV",
"charset": "UTF-8"
},
"field_mapping": {
"name": "name",
"age": "age",
"city": "city"
}
}
]
}
@@ -0,0 +1,10 @@
// Define schema
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("city").asText().ifNotExist().create();
schema.propertyKey("weight").asDouble().ifNotExist().create();
schema.propertyKey("date").asText().ifNotExist().create();

schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name", "city").ifNotExist().create();

schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date", "weight").ifNotExist().create();
@@ -0,0 +1,18 @@
{
"vertices": [
{
"label": "person",
"input": {
"type": "${source_type}",
"path": "${store_path}/vertex_person.csv",
"format": "CSV",
"charset": "UTF-8"
},
"field_mapping": {
"name": "name",
"age": "age",
"city": "city"
}
}
]
}

0 comments on commit 9297286

Please sign in to comment.