datahub-transportation-gov/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh
Icon for Socrata external plugin

Query the Data Delivery Network

Query the DDN

The 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 nonmajor_safety_and_security_events_fra_commuter table in this repository, by referencing it like:

"datahub-transportation-gov/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh:latest"."nonmajor_safety_and_security_events_fra_commuter"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "location_type", -- General grouping of the location column that can fall into either Facility, Vehicle, or Other.
    "event_count", -- Less severe incidents or events that do not meet the requirements of Reportable Events: Other safety occurrences not otherwise classified (injuries); and Fires. The number is determined by mode, type of service, month, and location.
    "customer_injuries", -- Count of patrons of the transit system or people waiting for transit injured during the given safety event.
    "worker_injuries", -- Count of Transit Workers injured for the given safety event.
    "start_date",
    "other_injuries", -- Count of pedestrians and others not using transit or working for the transit system injured for the given safety event.
    "total_non_major_injuries", -- Count of all people injured for the given safety event. The count should not exceed one (1), as events with multiple injuries meet a major reporting threshold.
    "incidentupdated_date", -- Date which the incident was most recently updated in the NTD system.
    "non_major_physical_assaults", -- Count of non-major physical assaults on transit vehicle operators.
    "non_major_non_physical_1", -- Count of non-major non-physical assaults on transit workers who are not vehicle operators.
    "safety_security_indicator", -- Identifier of a Safety (SFT) or (Security Event). [Safety Event: A collision, derailment, fire, hazardous material spill, act of nature (Act of God), evacuation, or OSONOC occurring on transit right-of-way, in a transit revenue facility, in a transit maintenance facility, or involving a transit revenue vehicle and meeting established NTD thresholds.] OR [Security event: An occurrence of a bomb threat, bombing, arson, hijacking, sabotage, cyber security event, assault, robbery, rape, burglary, suicide, attempted suicide (not involving a transit vehicle), larceny, theft, vandalism, homicide, CBR (chemical/biological/radiological) or nuclear release, or other event.]
    "month_year", -- Concatenation of the month and year in which the Non-major incident occurred.
    "non_major_non_physical", -- Count of non-major non-physical assaults on transit vehicle operators.
    "non_major_physical_assaults_1", -- Count of non-major physical assaults on transit workers who are not vehicle operators.
    "ntd_id", -- A five-digit identifying number for each agency used in the current NTD system.
    "transit_worker_assault", -- General grouping of the location in which a transit worker assault occurred: In Transit Vehicle, In revenue facility, In non-revenue facility, Other, or Not Applicable.
    "event_identifer_abbr",
    "event_type", -- The type of event that occurred.
    "monthid", -- The month in which the Non-major incident occurred.
    "reporting_period", -- Month in which hte Non-major incident was reported.
    "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.
    "year", -- The year in which the Non-major incident occurred.
    "report_year", -- The year in which the Non-major incident was reported to the NTD.
    "mode", -- A system for carrying transit passengers described by specific right-of-way (ROW), technology and operational features.
    "reporter_name", -- The legal name of the entity reporting to the National Transit Database.
    "submission_date", -- Date which the incident was submitted to the NTD.
    "location", -- The area in facility, vehicle, or other where the event took place.
    "additional_assault_information", -- Additional information about an assault event.
    "end_date",
    "incident_created_date" -- Date which the incident was created in the NTD system.
FROM
    "datahub-transportation-gov/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh:latest"."nonmajor_safety_and_security_events_fra_commuter"
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/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at datahub.transportation.gov. When you querydatahub-transportation-gov/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh:latest on the DDN, we "mount" the repository using the socrata mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT is only guaranteed for subsequent queries that land on the same node.

Query Your Local Engine

Install Splitgraph Locally
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; sgrcan manage the image, container and volume for you.

There are a few ways to ingest data into the local engine.

For external repositories (like this repository), 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, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by datahub.transportation.gov, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone to get the data. Instead, you can use the socrata adapter with the sgr mount command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

Mount the table with sgr mount

sgr mount socrata \
  "datahub-transportation-gov/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh" \
  --handler-options '{
    "domain": "datahub.transportation.gov",
    "tables": {
        "nonmajor_safety_and_security_events_fra_commuter": "63rf-6igh"
    }
}'

That's it! Now you can query the data in the mounted table like any other Postgres table.

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/nonmajor-safety-and-security-events-fra-commuter-63rf-6igh is just another Postgres schema.