Fix newline bug in mg_import_csv

Summary:
Handle special case when delimiter is the last character in line.
This means that another empty column needs to be added.

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1678
This commit is contained in:
Marko Culinovic 2018-10-18 14:35:51 +02:00
parent 60ec94fb30
commit d8293f1b6b
2 changed files with 12 additions and 6 deletions

View File

@ -188,6 +188,12 @@ std::vector<std::string> ReadRow(std::istream &stream) {
} else if (c == FLAGS_csv_delimiter.front()) {
row.emplace_back(column.begin(), column.end());
column.clear();
// Handle special case when delimiter is the last
// character in line. This means that another
// empty column needs to be added.
if (i == line_size - 1) {
row.emplace_back("");
}
} else {
column.push_back(c);
}

View File

@ -1,6 +1,6 @@
id:ID(FORUM_ID)|title:string|:LABEL
0|General|Forum
1|Support|Forum
2|Music|Forum
3|Film|Forum
4|Programming|Forum
id:ID(FORUM_ID)|title:string|:LABEL|emptyColumn
0|General|Forum|
1|Support|Forum|
2|Music|Forum|
3|Film|Forum|
4|Programming|Forum|

1 id:ID(FORUM_ID) title:string :LABEL emptyColumn
2 0 General Forum
3 1 Support Forum
4 2 Music Forum
5 3 Film Forum
6 4 Programming Forum