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 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
"v2_is_bus",
"v2_driver_contribution_2",
"v2_trailer_reg_year",
"v2_cargo_body_type",
"v2_towed",
"v2_third_damaged_area",
"v1_is_truck",
"p2_safety_equipment",
"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.
"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
"nearest_intersection_direction",
"v2_interstate",
"landmark_distance",
"v2_trailer_reg_type",
"ambient_light",
"road_surface_condition", -- The apparent condition of the road. (e.g., “Wet,” “Dry,” “Snow”)
"landmark",
"damaged_property_type",
"v2_most_damaged_area",
"v2_underride_override",
"v2_occupant_count",
"v2_action_prior_to_crash",
"v1_interstate",
"v1_trailer_len",
"v2_second_event",
"v2_gross_weight",
"v2_configuration",
"v2_state_code",
"v1_bus_use",
"v1_driver_distracted",
"v2_driver_contribution",
"v1_occupant_count",
"v1_model_year", -- The year which is assigned to a Vehicle by the manufacturer
"v1_action_prior_to_crash",
"v1_configuration",
"non_public_area",
"nearest_intersection_distance",
"intersection_name_3",
"p1_injury",
"p1_non_motorist_desc", -- When Role of involved person is NON-MOTORIST (CYCLIST, PEDESTRIAN, etc.)
"p1_non_motorist_action",
"p1_seat_position",
"p1_safety_system",
"p2_non_motorist_action",
"location_city",
"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_gross_weight",
"v2_tow_use",
"p1_role",
"p1_drivers_lic_class_1",
"p1_veh_owner",
"day_of_week",
"object_2", -- Second involved object in this accident (type of vehicle).
"street_name",
"near_street",
"location_state",
"speed_limit",
"work_zone",
"weather_condition_1", -- The weather condition (e.g., “Cloudy,” “Rain,” “Snow”) at the time of the Crash.
"manner_of_collision",
"location_address",
"cross_street",
"street_number",
"object_1", -- First involved object in this accident (type of vehicle).
"date_time", -- Date and Time accident occurred (12:00 AM may represent an unknown time)
"p2_role",
"v1_second_event",
"v1_most_harmful_event",
"location_zip",
"p2_safety_system",
"p2_sex",
"p2_drivers_lic_state",
"p1_sex",
"p1_drivers_lic_restrict",
"p1_drivers_lic_state",
"v2_travel_direction",
"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”)
"v2_registration_type",
"v1_is_hazmat",
"v1_has_trailer",
"v1_driver_contribution",
"v1_travel_direction",
"v1_towed",
"v1_third_event",
"v1_moped",
"description_of_damaged_property",
"mile_marker_direction",
"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.
"location", -- Crash location: either an intersection, address, or nearby street. Locations have been geocoded when possible.
"v2_make", -- The distinctive name applied to the Vehicle by the manufacturer. (e.g., “HONDA,” “FORD”)
"v2_moped",
"street_or_intersection",
"traffic_control_device_functionality",
"v1_emergency_response",
"p2_trapped",
"p2_age",
"v1_haz_release",
"v1_is_bus",
"v2_is_hazmat",
"v1_haz_placard",
"v2_haz_placard",
"p2_drivers_lic_class_1",
"v2_first_event",
"first_harmful_event",
":@computed_region_rcj3_ccgu",
":@computed_region_e4yd_rwk4",
"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”)
"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”)
":@computed_region_swkg_bavi",
":@computed_region_rffn_qbt6",
":@computed_region_v7jj_366k",
":@computed_region_guic_hr4a",
"intersection_name_2",
"v2_driver_distracted",
"p2_veh_owner",
"p2_seat_position",
"p2_non_motorist_location",
"p2_non_motorist_desc", -- When Role of involved person is NON-MOTORIST (CYCLIST, PEDESTRIAN, etc.)
"p1_age",
"p1_non_motorist_location",
"p1_drivers_lic_class_2",
"v2_trailer_len",
"v2_second_damaged_area",
"v2_fourth_event",
"v2_third_event",
"v2_model_year", -- The year which is assigned to a Vehicle by the manufacturer
"v1_tow_use",
"v1_reg_year",
"v1_trailer_reg_year",
"v1_cargo_body_type",
"v1_third_damaged_area",
"intersection_direction_3",
"street_direction",
"road_contributing",
"v1_registration_type",
"v1_state_code",
"v1_hit_and_run",
"v1_underride_override",
"v1_fourth_event",
"v1_trailer_reg_type",
"v1_trailer_reg_plate",
"v1_trailer_reg_state",
"v1_driver_contribution_2",
"v2_emergency_response",
"v2_hit_and_run",
"v2_most_harmful_event",
"v2_haz_release",
"v2_trailer_reg_plate",
"v2_trailer_reg_state",
"v2_is_truck",
"v2_has_trailer",
"v2_reg_year",
"v2_bus_use",
"p1_safety_equipment",
"p1_trapped",
"p2_injury",
"p2_drivers_lic_class_2",
"p2_drivers_lic_restrict",
"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”)
"v1_second_damaged_area",
"traffic_control_device_type", -- Indicates whether the traffic control was functioning at the time of Crash
"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”)
"v1_most_damaged_area",
"v1_first_event",
"v1_make", -- The distinctive name applied to the Vehicle by the manufacturer. (e.g., “HONDA,” “FORD”)
"landmark_direction",
"intersection_direction_2",
"intersection_direction_1",
"intersection_name_1"
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.
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 cambridgema-gov/police-department-crash-data-updated-gb5w-yva3: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 cambridgema-gov/police-department-crash-data-updated-gb5w-yva3
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 cambridgema-gov/police-department-crash-data-updated-gb5w-yva3:latest
This will download all the objects for the latest
tag of cambridgema-gov/police-department-crash-data-updated-gb5w-yva3
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 cambridgema-gov/police-department-crash-data-updated-gb5w-yva3: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 cambridgema-gov/police-department-crash-data-updated-gb5w-yva3: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, cambridgema-gov/police-department-crash-data-updated-gb5w-yva3
is just another Postgres schema.