Skip to content

Commit d1cec53

Browse files
committed
fix(load): handle empty column headers on feed load
fixes #124
1 parent cdf8f45 commit d1cec53

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: src/main/java/com/conveyal/gtfs/error/NewGTFSErrorType.java

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public enum NewGTFSErrorType {
1212
LANGUAGE_FORMAT(Priority.LOW, "Language should be specified with a valid BCP47 tag."),
1313
INTEGER_FORMAT(Priority.MEDIUM, "Incorrect integer format."),
1414
FLOATING_FORMAT(Priority.MEDIUM, "Incorrect floating point number format."),
15+
COLUMN_NAME_INVALID(Priority.HIGH, "Column header is not permitted."),
1516
COLUMN_NAME_UNSAFE(Priority.HIGH, "Column header contains characters not safe in SQL, it was renamed."),
1617
NUMBER_PARSING(Priority.MEDIUM, "Unable to parse number from value."),
1718
NUMBER_NEGATIVE(Priority.MEDIUM, "Number was expected to be non-negative."),

Diff for: src/main/java/com/conveyal/gtfs/loader/JdbcGtfsLoader.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,14 @@ private int loadInternal (Table table) throws Exception {
320320
int keyFieldIndex = -1;
321321
for (int h = 0; h < headerCount; h++) {
322322
String header = sanitize(csvReader.getHeader(h));
323-
if (fieldsSeen.contains(header) || "id".equals(header)) {
324-
// FIXME: add separate error for tables containing ID field.
323+
if (fieldsSeen.contains(header)) {
325324
errorStorage.storeError(NewGTFSError.forTable(table, DUPLICATE_HEADER).setBadValue(header));
326325
fields[h] = null;
327-
} else {
326+
} else if ("id".equals(header) || header.isEmpty()) {
327+
// Header field cannot be "id" or missing.
328+
errorStorage.storeError(NewGTFSError.forTable(table, COLUMN_NAME_INVALID).setBadValue(header));
329+
fields[h] = null;
330+
} else {
328331
fields[h] = table.getFieldForName(header);
329332
fieldsSeen.add(header);
330333
if (keyField.equals(header)) {

0 commit comments

Comments
 (0)