Skip to content

Commit

Permalink
fix(GtfsSnapshotter): avoid duplicate descriptions in calendars
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-cline committed Nov 16, 2023
1 parent 9bc752d commit 9d21212
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,17 @@ private void populateDefaultEditorValues(Connection connection, String tablePref
LOG.info(updateOtherSql);
int calendarsUpdated = statement.executeUpdate(updateOtherSql);
LOG.info("Updated description for {} calendars", calendarsUpdated);

// Check if there are duplicate descriptions, in which case set the description to be the service_id which is unique
String avoidDuplicateDescriptionSql = String.format(
"update %1$scalendar set description = service_id " +
"from (select description, count(*) as duplicate_count from %1$scalendar group by description) as duplicate_descriptions " +
"where %1$scalendar.description = duplicate_descriptions.description and duplicate_descriptions.duplicate_count > 1",
tablePrefix
);
LOG.info(avoidDuplicateDescriptionSql);
int duplicatesAvoided = statement.executeUpdate(avoidDuplicateDescriptionSql);
LOG.info("Updated description for {} calendars to avoid duplicates", duplicatesAvoided);
}
if (Table.TRIPS.name.equals(table.name)) {
// Update use_frequency field for patterns. This sets all patterns that have a frequency trip to use
Expand Down

0 comments on commit 9d21212

Please sign in to comment.