cambridgema-gov/police-department-crash-data-updated-gb5w-yva3
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 police_department_crash_data_updated table in this repository, by referencing it like:

"cambridgema-gov/police-department-crash-data-updated-gb5w-yva3:latest"."police_department_crash_data_updated"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "damaged_property_type",
    "v1_moped",
    "v1_third_event",
    "v1_third_damaged_area",
    "v1_towed",
    "v2_tow_use",
    "p1_role",
    "p2_drivers_lic_restrict",
    "date_time", -- Date and Time accident occurred (12:00 AM may represent an unknown time)
    "object_1", -- First involved object in this accident (type of vehicle).
    "street_number",
    "p1_drivers_lic_class_2",
    "p2_veh_owner",
    "near_street",
    "cross_street",
    "location_address",
    "location", -- Crash location: either an intersection, address, or nearby street. Locations have been geocoded when possible.
    "v1_reg_year",
    "manner_of_collision",
    "first_harmful_event_location", --  The injury or damage producing event which characterizes the Crash type and identifies the nature of the first harmful event. (e.g., “Collision with motor vehicle,” “Collision with guardrail”) 
    "p2_seat_position",
    "p2_non_motorist_location",
    "p2_injury",
    "p1_age",
    "weather_condition_1", --  The weather condition (e.g., “Cloudy,” “Rain,” “Snow”) at the time of the Crash. 
    "work_zone",
    "speed_limit",
    "p1_non_motorist_location",
    "v2_is_truck",
    "intersection_name_3",
    "v2_second_event",
    "nearest_intersection_distance",
    "v1_trailer_reg_plate",
    "v1_cargo_body_type",
    "non_public_area",
    "v1_interstate",
    "v1_state_code",
    "v1_configuration",
    "street_direction",
    "roadway_junction_type", --  A code which uniquely identifies a roadway junction type. A junction is either an intersection or the connection between a driveway access and a roadway other than a driveway access. (e.g., “T-intersection,” “Four-way intersection”) 
    "traffic_control_device_type", --  Indicates whether the traffic control was functioning at the time of Crash 
    "object_2", -- Second involved object in this accident (type of vehicle).
    "p2_non_motorist_action",
    "v1_action_prior_to_crash",
    "p1_safety_system",
    "p1_seat_position",
    "p1_non_motorist_action",
    "p1_non_motorist_desc", -- When Role of involved person is NON-MOTORIST (CYCLIST, PEDESTRIAN, etc.)
    "p1_injury",
    "v2_driver_distracted",
    "v2_driver_contribution_2",
    "v2_trailer_reg_year",
    "v2_cargo_body_type",
    "v2_towed",
    "v2_third_damaged_area",
    "v2_most_damaged_area",
    "v2_third_event",
    "v2_underride_override",
    "v1_model_year", --  The year which is assigned to a Vehicle by the manufacturer
    "v2_occupant_count",
    "v2_action_prior_to_crash",
    "v1_occupant_count",
    "v1_is_hazmat",
    "v1_first_event",
    "v1_has_trailer",
    "v1_driver_contribution",
    "v1_trailer_reg_year",
    "v1_driver_distracted",
    "v1_travel_direction",
    "v1_bus_use",
    "v2_state_code",
    "v2_configuration",
    "may_involve_cyclist", -- This calculated field indicates whether each crash might involve cyclist. The field is calculated by searching for the text strings "bicycle," "pedalcycle," or "cycli" within each column for a given row. The keyword "cycle" was not used so as to avoid the risk of false positives from the word "motorcycle." This new column has been included to expedite analysis of the City's crash data for bicycle safety. We are confident that it has caught the vast majority of bicycle related incidents in this dataset, but please be advised that no text search algorithm is perfect, and this one may not account for 100 percent of bicycle-related incidents. 
    "ambient_light",
    "weather_condition_2", --  This data attribute is captured only if there is more than one weather condition type needed to be captured. (e.g., Weather Condition 1 = “Cloudy”; Weather Condition 2 = “Rain”) 
    "landmark_distance",
    "mile_marker_direction",
    "road_contributing",
    "description_of_damaged_property",
    ":@computed_region_guic_hr4a",
    ":@computed_region_rffn_qbt6",
    ":@computed_region_swkg_bavi",
    "may_involve_pedestrian", -- This calculated field indicates whether each crash might involve cyclist. The field is calculated by searching for the text string "pedestrian" within each column for a given row. The keyword "walk" was not used so as to avoid the risk of false positives from the phrase "walk signal." This new column has been included to expedite analysis of the City's crash data for bicycle safety. We are confident that it has caught the vast majority of pedestrian related incidents in this dataset, but please be advised that no text search algorithm is perfect, and this one may not account for 100 percent of pedestrian-related incidents.
    "p2_safety_system",
    "p2_sex",
    "p2_non_motorist_desc", -- When Role of involved person is NON-MOTORIST (CYCLIST, PEDESTRIAN, etc.)
    "p2_drivers_lic_state",
    "p1_sex",
    ":@computed_region_e4yd_rwk4",
    ":@computed_region_rcj3_ccgu",
    "v2_trailer_reg_state",
    "first_harmful_event",
    "v2_first_event",
    "p2_drivers_lic_class_1",
    "day_of_week",
    "v2_haz_placard",
    "location_state",
    "intersection_direction_1",
    "nearest_intersection_direction",
    "v1_gross_weight",
    "v1_haz_placard",
    "v1_is_truck",
    "v2_gross_weight",
    "v2_has_trailer",
    "v2_is_hazmat",
    "v1_is_bus",
    "v2_haz_release",
    "v1_haz_release",
    "v1_driver_contribution_2",
    "v2_is_bus",
    "p1_trapped",
    "p2_age",
    "intersection_name_2",
    "p1_veh_owner",
    "p2_trapped",
    "intersection_name_1",
    "p1_drivers_lic_restrict",
    "p1_drivers_lic_class_1",
    "p1_drivers_lic_state",
    "v2_travel_direction",
    "v2_second_damaged_area",
    "v2_model", -- The manufacturer assigned name denoting a family of Vehicles (within a make) which has a degree of similarity in construction, such as body, chassis, etc. (e.g., “CIVIC,” “TAURUS”) 
    "v1_emergency_response",
    "v2_emergency_response",
    "v1_tow_use",
    "v1_second_damaged_area",
    "v1_most_damaged_area",
    "v1_second_event",
    "v1_most_harmful_event",
    "landmark",
    "trafficway_description", --  Indicates whether or not a trafficway is divided and whether it serves one-way or two-way traffic. (e.g., “One-way, not divided,” “Two-way, divided”) 
    "road_surface_condition", --  The apparent condition of the road. (e.g., “Wet,” “Dry,” “Snow”) 
    "v2_registration_type",
    "location_zip",
    ":@computed_region_v7jj_366k",
    "v2_hit_and_run",
    "v2_most_harmful_event",
    "p2_safety_equipment",
    "street_name",
    "location_city",
    "intersection_direction_3",
    "v1_registration_type",
    "v1_hit_and_run",
    "v1_model", --  The manufacturer assigned name denoting a family of Vehicles (within a make) which has a degree of similarity in construction, such as body, chassis, etc. (e.g., “CIVIC,” “TAURUS”) 
    "v1_trailer_reg_type",
    "v2_reg_year",
    "traffic_control_device_functionality",
    "school_bus_related", --  Indicates whether a school bus is related to the Crash. The school bus must be directly involved as a contact vehicle or indirectly involved as a non-contact vehicle 
    "street_or_intersection",
    "intersection_direction_2",
    "landmark_direction",
    "v1_make", --  The distinctive name applied to the Vehicle by the manufacturer. (e.g., “HONDA,” “FORD”) 
    "v1_underride_override",
    "v1_fourth_event",
    "v1_trailer_reg_state",
    "v1_trailer_len",
    "v2_moped",
    "v2_make", --  The distinctive name applied to the Vehicle by the manufacturer. (e.g., “HONDA,” “FORD”) 
    "v2_interstate",
    "v2_model_year", -- The year which is assigned to a Vehicle by the manufacturer 
    "v2_fourth_event",
    "v2_trailer_reg_type",
    "v2_trailer_reg_plate",
    "v2_trailer_len",
    "v2_driver_contribution",
    "v2_bus_use",
    "p1_safety_equipment",
    "p2_role",
    "p2_drivers_lic_class_2"
FROM
    "cambridgema-gov/police-department-crash-data-updated-gb5w-yva3:latest"."police_department_crash_data_updated"
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 cambridgema-gov/police-department-crash-data-updated-gb5w-yva3 with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.cambridgema.gov. When you querycambridgema-gov/police-department-crash-data-updated-gb5w-yva3: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.cambridgema.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 \
  "cambridgema-gov/police-department-crash-data-updated-gb5w-yva3" \
  --handler-options '{
    "domain": "data.cambridgema.gov",
    "tables": {
        "police_department_crash_data_updated": "gb5w-yva3"
    }
}'

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, cambridgema-gov/police-department-crash-data-updated-gb5w-yva3 is just another Postgres schema.