Skip to content

Commit 86f573f

Browse files
committed
fix(data-migration): make pattern stop sequence zero-based
The stop_times stop_sequence values in editor feeds are zero-based and incrementing. This job used to import feeds from MapDB had been incorrectly setting the first sequence value to 1.
1 parent f384ef4 commit 86f573f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/main/java/com/conveyal/datatools/editor/jobs/ConvertEditorMapDBToSQL.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ private FeedLoadResult convertFeed(String feedId, Integer version, FeedTx feedTx
173173
updateTripsStatement.setString(1, pattern.id);
174174
updateTripsStatement.setString(2, trip.gtfsTripId);
175175
// FIXME: Do something with the return value? E.g., rollback if it hits more than one trip.
176-
// FIXME: Do this in batches?
177176
updateTripsStatement.addBatch();
178177
batchSize += 1;
179178
// If we've accumulated a lot of prepared statement calls, pass them on to the database backend.
@@ -185,10 +184,11 @@ private FeedLoadResult convertFeed(String feedId, Integer version, FeedTx feedTx
185184
}
186185

187186
// Pattern stops table has not yet been created because pattern stops do not exist in
188-
// GTFSFeed. NOte, we want this table to be created regardless of whether patterns exist or not.
187+
// GTFSFeed. Note, we want this table to be created regardless of whether patterns exist or not
188+
// (which is why it is outside of the check for null pattern map).
189189
Table.PATTERN_STOP.createSqlTable(connection, namespace, true);
190190

191-
// Insert all trip patterns and pattern stops into database (tables have already been created FIXME pattern_stops has not yet been created).
191+
// Insert all trip patterns and pattern stops into database (tables have already been created).
192192
if (feedTx.tripPatterns != null) {
193193
batchSize = 0;
194194
// Handle inserting patterns
@@ -214,9 +214,8 @@ private FeedLoadResult convertFeed(String feedId, Integer version, FeedTx feedTx
214214
insertPatternStatement.setString(6, pattern.id);
215215
insertPatternStatement.addBatch();
216216
batchSize += 1;
217-
218-
int stopSequence = 1;
219-
// LOG.info("Inserting {} pattern stops for pattern {}", pattern.patternStops.size(), pattern.id);
217+
// stop_sequence must be zero-based and incrementing to match stop_times values.
218+
int stopSequence = 0;
220219
for (TripPatternStop tripPatternStop : pattern.patternStops) {
221220
// TripPatternStop's stop ID needs to be mapped to GTFS stop ID.
222221
// FIXME Possible NPE?
@@ -228,7 +227,6 @@ private FeedLoadResult convertFeed(String feedId, Integer version, FeedTx feedTx
228227
insertPatternStopStatement.setInt(5, tripPatternStop.defaultDwellTime);
229228
insertPatternStopStatement.setInt(6, 0);
230229
insertPatternStopStatement.setInt(7, 0);
231-
// FIXME: shapeDistTraveled could be null
232230
if (tripPatternStop.shapeDistTraveled == null) {
233231
insertPatternStopStatement.setNull(8, JDBCType.DOUBLE.getVendorTypeNumber());
234232
} else {

0 commit comments

Comments
 (0)