Query the Data Delivery Network
Query the DDNThe easiest way to query any data on Splitgraph is via the "Data Delivery Network" (DDN). The DDN is a single endpoint that speaks the PostgreSQL wire protocol. Any Splitgraph user can connect to it at data.splitgraph.com:5432
and query any version of over 40,000 datasets that are hosted or proxied by Splitgraph.
For example, you can query the monthly_modal_time_series
table in this repository, by referencing it like:
"datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv:latest"."monthly_modal_time_series"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"major_non_physical_assaults_on_other_transit_workers", -- Count of major non-physical assaults on transit workers who are not vehicle operators.
"total_other_injuries", -- For 2002-2007, the sum of "Other," "Trespasser," and "Suicide." For 2008-2016, the sum of "Bicyclist," "Ped in Crossing," "Ped not in Crossing," "Ped Crossing Tracks," "Ped Walking Along Tracks," "Other Vehicle Occupant," "Other," and "Suicide."
"trespasser_injuries", -- Number of trespasser injuries.
"pedestrian_crossing_tracks_1", -- Number of pedestrian injuries crossing tracks. This data point is not collected prior to 2008 or after 2015.
"other_worker_injuries", -- Number of non-transit employee injuries.
"total_events_not_otherwise", -- Total number of accidents "not otherwise classified" (NOC) reported to NTD. These events include slips, trips and falls, electric shocks, vehicles leaving roadway, yard derailments, and other events that are not reported as a collision, derailment, or fire.
"total_events", -- Total number reportable major and non-major events for the given agency/mode/type of service/month.
"other_employee_fatalities", -- Number of non-operator transit employee fatalities. This data point is not collected prior to 2008.
"pedestrian_not_in_crosswalk", -- Number of pedestrian fatalities not in crosswalks. This data point is not collected prior to 2008.
"pedestrian_crossing_tracks", -- Number of pedestrian fatalities crossing tracks. This data point is not collected prior to 2008 or after 2015.
"pedestrian_walking_along", -- Number of pedestrian fatalities walking along tracks. This data point is not collected prior to 2008 or after 2015.
"other_vehicle_occupant", -- Number of occupants of other vehicle fatalities. This data point is not collected prior to 2008.
"other_fatalities", -- For 2002-2007, included the sum of "Bicyclist," "Ped in Crossing," "Ped Not In Crossing," "Ped Crossing Tracks," "Ped Walking Along Tracks," and "Other Vehicle Occupant." For 2008 and later, includes other members of the public not specified.
"suicide_fatalities", -- Number of suicides.
"total_other_fatalities", -- For 2002-2007, the sum of "Other," "Trespasser," and "Suicide." For 2008-2016, the sum of "Bicyclist," "Ped in Crossing," "Ped not in Crossing," "Ped Crossing Tracks," "Ped Walking Along Tracks," "Other Vehicle Occupant," "Other," and "Suicide."
"total_fatalities", -- All fatalities - "Passenger," "People Waiting or Leaving," "Total Employee," "Other Worker," and "Total Other."
"passenger_injuries", -- Number of passenger injuries. Passengers include individuals onboard a transit vehicle (including between cars or on top of vehicle).
"people_waiting_or_leaving_1", -- Number of revenue facility occupant injuries. Revenue facility occupants include individuals waiting for or leaving transit.
"operator_injuries", -- Number of transit operator injuries. This data point is not collected prior to 2008.
"other_employee_injuries", -- Number of non-operator transit employee fatalities. This data point is not collected prior to 2008.
"total_employee_injuries", -- Total Employee Injuries (Other Employee and Operator aggregated)
"total_security_events", -- Total number of major security events reported to NTD, including assaults on transit workers and other security events.
"total_derailments", -- Total number of main line derailments reported to NTD. Yard derailments are reported as Not-Otherwise Classified (NOC) events.
"total_collisions", -- The total number of collisions for the given agency/mode/month.
"collisions_with_other", -- The number of collisions with another object for the given agency/mode/month.
"trespasser_fatalities", -- Number of trespasser fatalities.
"pedestrian_in_crosswalk", -- Number of pedestrian fatalities in crosswalks. This data point is not collected prior to 2008.
"bicyclist_fatalities", -- Number of cyclist fatalities. This data point is not collected prior to 2008.
"other_worker_fatalities", -- Number of non-transit employee fatalities.
"total_employee_fatalities", -- Total Employee Fatalities (Other Employee and Operator aggregated)
"uace_code", -- The Census Bereau's Urban Area Census Code (UACE). This five-digit code uniquely identifies an urban area and remains unchanged from census to census.
"rail_y_n", -- Separates Rail (True) from Non-Rail (False) modes.
"collisions_with_rail_vehicle", -- The number of collisions with a rail vehicle for the given agency/mode/month.
"collisions_with_fixed_object", -- The number of collisions with a fixed object for the given agency/mode/month.
"collisions_with_person", -- The number of collisions with a person for the given agency/mode/month.
"collisions_with_motor_vehicle", -- The number of collisions with a motor vehicle for the given agency/mode/month.
"ridership", -- The number of boardings on transit vehicles reported by the system for the same calendar year. The value is year to date for calendar years that are not yet complete.
"vehicle_revenue_hours", -- The number of hours operated by transit vehicles in revenue service, as reported by the system for the same calendar year. The value is year to date for calendar years that are not yet complete.
"vehicles", -- The number of revenue vehicles operated by the given mode and type of service to meet the annual maximum service requirement. This is the revenue vehicle count during the peak season of the reporting period; on the week and day that maximum service is provided. Vehicles operated in maximum service (VOMS) exclude atypical days and one-time special events.
"month", -- The month in which the events occurred.
"year", -- The calendar year in which the events occurred.
"service_area_population",
"service_area_sq_miles",
"primary_uza_population", -- The population of the primary UZA from the most recent decennial Census.
"primary_uza_sq_miles", -- The square miles of the primary UZA from the most recent decennial Census.
"bicyclist_injuries", -- Number of cyclist injuries. This data point is not collected prior to 2008.
"pedestrian_in_corsswalk", -- Number of pedestrian injuries in crosswalks. This data point is not collected prior to 2008.
"pedestrian_not_in_crosswalk_1", -- Number of pedestrian injuries not in crosswalks. This data point is not collected prior to 2008.
"pedestrian_walking_along_1", -- Number of pedestrian injuries walking along tracks. This data point is not collected prior to 2008 or after 2015.
"other_vehicle_occupant_1", -- Number of occupants of other vehicle injuries. This data point is not collected prior to 2008.
"other_injuries", -- For 2002-2007, included the sum of "Bicyclist," "Ped in Crossing," "Ped Not In Crossing," "Ped Crossing Tracks," "Ped Walking Along Tracks," and "Other Vehicle Occupant." For 2008 and later, includes other members of the public not specified.
"total_injuries", -- All injuries - "Passenger," "People Waiting or Leaving," "Total Employee," "Other Worker," and "Total Other."
"non_major_physical_assaults_on_operators", -- Count of non-major physical assaults on transit vehicle operators.
"non_major_non_physical_assaults_on_operators", -- Count of non-major non-physical assaults on transit vehicle operators.
"non_major_physical_assaults_on_other_transit_workers", -- Count of non-major physical assaults on transit workers who are not vehicle operators.
"non_major_non_physical_assaults_on_other_transit_workers", -- Count of non-major non-physical assaults on transit workers who are not vehicle operators.
"major_physical_assaults_on_operators", -- Count of major physical assaults on transit vehicle operators.
"major_non_physical_assaults_on_operators", -- Count of major non-physical assaults on transit vehicle operators.
"major_physical_assaults_on_other_transit_workers", -- Count of major physical assaults on transit workers who are not vehicle operators.
"total_assaults_on_transit_workers", -- Total assaults on transit workers.
"suicide_injuries", -- Number of attempted suicides or other injuries involved in suicide events.
"vehicle_revenue_miles", -- The number of miles traveled by transit vehicles in revenue service, as reported by the system for the same calendar year. The value is year to date for calendar years that are not yet complete. For rail modes, "passenger car revenue miles" is used.
"collisions_with_bus_vehicle", -- The number of collisions with a bus vehicle for the given agency/mode/month.
"passenger_fatalities", -- Number of passenger fatalities. Passengers include individuals onboard a transit vehicle (including between cars or on top of vehicle).
"people_waiting_or_leaving", -- Number of revenue facility occupant fatalities. Revenue facility occupants include individuals waiting for or leaving transit.
"operator_fatalities", -- Number of transit operator fatalities. This data point is not collected prior to 2008.
"mode", -- A system for carrying transit passengers described by specific right-of-way (ROW), technology and operational features.
"type_of_service", -- Describes how public transportation services are provided by the transit agency: directly operated (DO) or purchased transportation which also includes from Taxi Operators and Transportation Network Companies (PT, TX, TN) services.
"primary_uza_name", -- The name of the Census-designated Urbanized Area, from the most recent census, in which the system primarily operates.
"organization_type", -- The organization type, as defined by FTA and reported by transit agencies on the most recent annual report, of the agency.
"agency", -- The legal name of the entity reporting to the NTD.
"_5_digit_ntd_id", -- A five-digit identifying number for each agency used in the current NTD system.
"total_fires" -- Total number of fires reported to NTD.
FROM
"datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv:latest"."monthly_modal_time_series"
LIMIT 100;
Connecting to the DDN is easy. All you need is an existing SQL client that can connect to Postgres. As long as you have a SQL client ready, you'll be able to query datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv
with SQL in under 60 seconds.
Query Your Local Engine
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
Read the installation docs.
Splitgraph Cloud is built around Splitgraph Core (GitHub), which includes a local Splitgraph Engine packaged as a Docker image. Splitgraph Cloud is basically a scaled-up version of that local Engine. When you query the Data Delivery Network or the REST API, we mount the relevant datasets in an Engine on our servers and execute your query on it.
It's possible to run this engine locally. You'll need a Mac, Windows or Linux system to install sgr
, and a Docker installation to run the engine. You don't need to know how to actually use Docker; sgr
can manage the image, container and volume for you.
There are a few ways to ingest data into the local engine.
For external repositories, the Splitgraph Engine can "mount" upstream data sources by using sgr mount
. This feature is built around Postgres Foreign Data Wrappers (FDW). You can write custom "mount handlers" for any upstream data source. For an example, we blogged about making a custom mount handler for HackerNews stories.
For hosted datasets (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr clone
and sgr checkout
.
Cloning Data
Because datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv:latest
is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.
First, install Splitgraph if you haven't already.
Clone the metadata with sgr clone
This will be quick, and does not download the actual data.
sgr clone datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv
Checkout the data
Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest
tag:
sgr checkout datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv:latest
This will download all the objects for the latest
tag of datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv
and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.
Alternatively, use "layered checkout" to avoid downloading all the data
The data in datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv:latest
is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:
sgr checkout --layered datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv:latest
This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.
Read the layered querying documentation to learn about when and why you might want to use layered queries.
Query the data with your existing tools
Once you've loaded the data into your local Splitgraph Engine, you can query it with any of your existing tools. As far as they're concerned, datahub-transportation-gov/monthly-modal-time-series-5ti2-5uiv
is just another Postgres schema.