From 9d212120575ac3dd06a59248d9efcdcf4081e5e9 Mon Sep 17 00:00:00 2001 From: "philip.cline" Date: Thu, 16 Nov 2023 16:55:46 -0500 Subject: [PATCH] fix(GtfsSnapshotter): avoid duplicate descriptions in calendars --- .../com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java b/src/main/java/com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java index a4e05ecf4..b8b70dee6 100644 --- a/src/main/java/com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java +++ b/src/main/java/com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java @@ -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