montgomerycountymd-gov/traffic-violations-4mse-ku6q
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 traffic_violations table in this repository, by referencing it like:

"montgomerycountymd-gov/traffic-violations-4mse-ku6q:latest"."traffic_violations"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "longitude", -- Longitude location of the traffic violation.
    "location", -- Location of the violation, usually an address or intersection.
    "seq_id", -- Unique traffic stop ID
    "driver_city", -- City of the driver’s home address.
    "latitude", -- Latitude location of the traffic violation.
    "violation_type", -- Violation type.  (Examples: Warning, Citation, SERO)
    "search_reason_for_stop", -- The reason for the stop that lead to a search. 
    "time_of_stop", -- Time of the traffic violation.
    "arrest_type", -- Type of Arrest (A = Marked, B = Unmarked, etc.)
    "description", -- Text description of the specific charge.
    "vehicle_type", -- Type of vehicle (Examples: Automobile, Station Wagon, Heavy Duty Truck, etc.)
    "charge", -- Numeric code for the specific charge. 
    "date_of_stop", -- Date of the traffic violation.
    "race", -- Race of the driver.  (Example: Asian, Black, White, Other, etc.)
    "work_zone", -- Yes if the traffic violation was in a work zone.
    "dl_state", -- State issuing the Driver’s License.
    "subagency", -- Court code representing the district of assignment of the officer.  R15 = 1st district, Rockville B15 = 2nd district, Bethesda SS15 = 3rd district, Silver Spring WG15 = 4th district, Wheaton G15 = 5th district, Germantown M15 = 6th district, Gaithersburg / Montgomery Village HQ15 = Headquarters and Special Operations
    "search_arrest_reason", -- The arrest reason from the search. 
    "accident", -- YES if traffic violation involved an accident.
    "search_type", -- Type of search (Person, Property, Both, etc.) 
    "make", -- Manufacturer of the vehicle (Examples: Ford, Chevy, Honda, Toyota, etc.)
    "state", -- State issuing the vehicle registration.
    "commercial_license", -- Yes if driver holds a Commercial Drivers License
    "driver_state", -- State of the driver’s home address.
    "color", -- Color of the vehicle.
    "search_reason", -- The reason for the search. 
    "search_disposition", -- The disposition of the search. 
    "geolocation_zip",
    "year", -- Year vehicle was made.
    "geolocation_state",
    "agency", -- Agency issuing the traffic violation.  (Example: MCP is Montgomery County Police)
    "gender", -- Gender of the driver (F = Female, M = Male)
    "property_damage", -- Yes if traffic violation involved Property Damage.
    "geolocation", -- Geo-coded location information.
    "model", -- Model of the vehicle.
    "geolocation_city",
    "belts", -- YES if seat belts were in use in accident cases.
    "personal_injury", -- Yes if traffic violation involved Personal Injury.
    "search_conducted", -- Yes if a search was conducted. 
    "geolocation_address",
    "contributed_to_accident", -- If the traffic violation was a contributing factor in an accident.
    "hazmat", -- Yes if the traffic violation involved hazardous materials.
    "fatal", -- Yes if traffic violation involved a fatality.
    "commercial_vehicle", -- Yes if the vehicle committing the traffic violation is a commercial vehicle.
    "article", -- Article of State Law.  (TA = Transportation Article, MR = Maryland Rules)
    "alcohol", -- Yes if the traffic violation included an alcohol related suspension.
    "search_outcome", -- Resulting outcome of the search. 
    ":@computed_region_6vgr_duib",
    ":@computed_region_a9cs_3ed7",
    ":@computed_region_rbt8_3x7n",
    ":@computed_region_d7bw_bq6x",
    ":@computed_region_kbsp_ykn9",
    ":@computed_region_tx5f_5em3",
    ":@computed_region_vu5j_pcmz"
FROM
    "montgomerycountymd-gov/traffic-violations-4mse-ku6q:latest"."traffic_violations"
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 montgomerycountymd-gov/traffic-violations-4mse-ku6q with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.montgomerycountymd.gov. When you querymontgomerycountymd-gov/traffic-violations-4mse-ku6q: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 data.montgomerycountymd.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 \
  "montgomerycountymd-gov/traffic-violations-4mse-ku6q" \
  --handler-options '{
    "domain": "data.montgomerycountymd.gov",
    "tables": {
        "traffic_violations": "4mse-ku6q"
    }
}'

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, montgomerycountymd-gov/traffic-violations-4mse-ku6q is just another Postgres schema.