Skip to content

Commit

Permalink
fix(load): handle empty column headers on feed load
Browse files Browse the repository at this point in the history
fixes #124
  • Loading branch information
landonreed committed Jun 8, 2018
1 parent cdf8f45 commit d1cec53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum NewGTFSErrorType {
LANGUAGE_FORMAT(Priority.LOW, "Language should be specified with a valid BCP47 tag."),
INTEGER_FORMAT(Priority.MEDIUM, "Incorrect integer format."),
FLOATING_FORMAT(Priority.MEDIUM, "Incorrect floating point number format."),
COLUMN_NAME_INVALID(Priority.HIGH, "Column header is not permitted."),
COLUMN_NAME_UNSAFE(Priority.HIGH, "Column header contains characters not safe in SQL, it was renamed."),
NUMBER_PARSING(Priority.MEDIUM, "Unable to parse number from value."),
NUMBER_NEGATIVE(Priority.MEDIUM, "Number was expected to be non-negative."),
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/conveyal/gtfs/loader/JdbcGtfsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,14 @@ private int loadInternal (Table table) throws Exception {
int keyFieldIndex = -1;
for (int h = 0; h < headerCount; h++) {
String header = sanitize(csvReader.getHeader(h));
if (fieldsSeen.contains(header) || "id".equals(header)) {
// FIXME: add separate error for tables containing ID field.
if (fieldsSeen.contains(header)) {
errorStorage.storeError(NewGTFSError.forTable(table, DUPLICATE_HEADER).setBadValue(header));
fields[h] = null;
} else {
} else if ("id".equals(header) || header.isEmpty()) {
// Header field cannot be "id" or missing.
errorStorage.storeError(NewGTFSError.forTable(table, COLUMN_NAME_INVALID).setBadValue(header));
fields[h] = null;
} else {
fields[h] = table.getFieldForName(header);
fieldsSeen.add(header);
if (keyField.equals(header)) {
Expand Down

0 comments on commit d1cec53

Please sign in to comment.