-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolving duplication issues in raw data (#19)
* Load realtime data file-by-file from GCS to avoid duplicates in adjacent files * Add local storage path env to vehicle ingestor for easier local testing * Add transaction to MERGE statement to clear stage table
- Loading branch information
Showing
5 changed files
with
106 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,60 @@ | ||
BEGIN TRANSACTION; | ||
|
||
MERGE `{{ params.project_id }}.{{ params.dataset_id }}.{{ params.vehicle_table_name }}` AS target | ||
USING `{{ params.project_id }}.{{ params.dataset_id }}.{{ params.stage_vehicle_table_name }}` AS source | ||
ON target.vehicle_id = source.vehicle_id | ||
AND target.timestamp = TIMESTAMP_SECONDS(source.timestamp) | ||
AND target.trip_id = source.trip_id | ||
ON target.vehicle_id = source.vehicle_id | ||
AND target.timestamp = TIMESTAMP_SECONDS(source.timestamp) | ||
AND target.trip_id = source.trip_id | ||
WHEN MATCHED THEN | ||
UPDATE SET | ||
target.id = source.id | ||
,target.trip_id = source.trip_id | ||
,target.route_id = source.route_id | ||
,target.direction_id = source.direction_id | ||
,target.start_date = source.start_date | ||
,target.vehicle_id = source.vehicle_id | ||
,target.vehicle_label = source.vehicle_label | ||
,target.latitude = source.latitude | ||
,target.longitude = source.longitude | ||
,target.bearing = source.bearing | ||
,target.speed = source.speed | ||
,target.timestamp = TIMESTAMP_SECONDS(source.timestamp) | ||
,target.occupancy_status = source.occupancy_status | ||
,target.occupancy_percentage = source.occupancy_percentage | ||
, target.trip_id = source.trip_id | ||
, target.route_id = source.route_id | ||
, target.direction_id = source.direction_id | ||
, target.start_date = source.start_date | ||
, target.vehicle_id = source.vehicle_id | ||
, target.vehicle_label = source.vehicle_label | ||
, target.latitude = source.latitude | ||
, target.longitude = source.longitude | ||
, target.bearing = source.bearing | ||
, target.speed = source.speed | ||
, target.timestamp = TIMESTAMP_SECONDS(source.timestamp) | ||
, target.occupancy_status = source.occupancy_status | ||
, target.occupancy_percentage = source.occupancy_percentage | ||
WHEN NOT MATCHED THEN | ||
INSERT ( | ||
id | ||
,trip_id | ||
,route_id | ||
,direction_id | ||
,start_date | ||
,vehicle_id | ||
,vehicle_label | ||
,latitude | ||
,longitude | ||
,bearing | ||
,speed | ||
,timestamp | ||
,occupancy_status | ||
,occupancy_percentage | ||
, trip_id | ||
, route_id | ||
, direction_id | ||
, start_date | ||
, vehicle_id | ||
, vehicle_label | ||
, latitude | ||
, longitude | ||
, bearing | ||
, speed | ||
, timestamp | ||
, occupancy_status | ||
, occupancy_percentage | ||
) VALUES ( | ||
source.id | ||
,source.trip_id | ||
,source.route_id | ||
,source.direction_id | ||
,source.start_date | ||
,source.vehicle_id | ||
,source.vehicle_label | ||
,source.latitude | ||
,source.longitude | ||
,source.bearing | ||
,source.speed | ||
,TIMESTAMP_SECONDS(source.timestamp) | ||
,source.occupancy_status | ||
,source.occupancy_percentage | ||
, source.trip_id | ||
, source.route_id | ||
, source.direction_id | ||
, source.start_date | ||
, source.vehicle_id | ||
, source.vehicle_label | ||
, source.latitude | ||
, source.longitude | ||
, source.bearing | ||
, source.speed | ||
, TIMESTAMP_SECONDS(source.timestamp) | ||
, source.occupancy_status | ||
, source.occupancy_percentage | ||
); | ||
|
||
|
||
TRUNCATE TABLE `{{ params.project_id }}.{{ params.dataset_id }}.{{ params.stage_vehicle_table_name }}`; | ||
|
||
COMMIT TRANSACTION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# A service to ingest vehicle positions continuously | ||
# A service to ingest vehicle positions from GTFS Realtime endpoint | ||
|
||
Useful Docker command for local testing: | ||
Useful Docker command for local testing of vehicle ingestor: | ||
|
||
```bash | ||
docker run -v /Users/vmois/Projects/miwaitway/service_account.json:/root/creds/service_account.json -e VEHICLE_LOCATION_URL="https://www.miapp.ca/GTFS_RT/Vehicle/VehiclePositions.pb" -e BUCKET_NAME=miwaitway -e LOGLEVEL=debug -e GOOGLE_APPLICATION_CREDENTIALS=/root/creds/service_account.json miwaitway_vehicle_positions_ingestor | ||
``` | ||
docker run -v /Users/vmois/Projects/miwaitway/service_account.json:/root/creds/service_account.json -v /Users/vmois/Projects/miwaitway/tmp:/root/tmp -e CHUNKS_TO_LOAD=3 -e LOCAL_STORAGE_PATH="/root/tmp" -e VEHICLE_LOCATION_URL="https://www.miapp.ca/GTFS_RT/Vehicle/VehiclePositions.pb" -e BUCKET_NAME=miwaitway -e LOGLEVEL=debug -e GOOGLE_APPLICATION_CREDENTIALS=/root/creds/service_account.json miwaitway_vehicle_positions_ingestor | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters