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 traffic_crashes_crashes
table in this repository, by referencing it like:
"cityofchicago/traffic-crashes-crashes-85ca-t3if:latest"."traffic_crashes_crashes"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"alignment", -- Street alignment at crash location, as determined by reporting officer
"roadway_surface_cond", -- Road surface condition, as determined by reporting officer
"road_defect", -- Road defects, as determined by reporting officer
"report_type", -- Administrative report type (at scene, at desk, amended)
"posted_speed_limit", -- Posted speed limit, as determined by reporting officer
"hit_and_run_i", -- Crash did/did not involve a driver who caused the crash and fled the scene without exchanging information and/or rendering aid
"damage", -- A field observation of estimated damage.
"traffic_control_device", -- Traffic control device present at crash location, as determined by reporting officer
"date_police_notified", -- Calendar date on which police were notified of the crash
"prim_contributory_cause", -- The factor which was most significant in causing the crash, as determined by officer judgment
"private_property_i", -- Whether the crash begun or first contact was made outside of the public right-of-way.
"sec_contributory_cause", -- The factor which was second most significant in causing the crash, as determined by officer judgment
"street_no", -- Street address number of crash location, as determined by reporting officer
"street_direction", -- Street address direction (N,E,S,W) of crash location, as determined by reporting officer
"street_name", -- Street address name of crash location, as determined by reporting officer
"device_condition", -- Condition of traffic control device, as determined by reporting officer
"beat_of_occurrence", -- Chicago Police Department Beat ID. Boundaries available at https://data.cityofchicago.org/d/aerh-rz74
"photos_taken_i", -- Whether the Chicago Police Department took photos at the location of the crash
"crash_record_id", -- This number can be used to link to the same crash in the Vehicles and People datasets. This number also serves as a unique ID in this dataset.
"statements_taken_i", -- Whether statements were taken from unit(s) involved in crash
"crash_date_est_i", -- Crash date estimated by desk officer or reporting party (only used in cases where crash is reported at police station days after the crash)
"dooring_i", -- Whether crash involved a motor vehicle occupant opening a door into the travel path of a bicyclist, causing a crash
"work_zone_i", -- Whether the crash occurred in an active work zone
"crash_date", -- Date and time of crash as entered by the reporting officer
"work_zone_type", -- The type of work zone, if any
"workers_present_i", -- Whether construction workers were present in an active work zone at crash location
"num_units", -- Number of units involved in the crash. A unit can be a motor vehicle, a pedestrian, a bicyclist, or another non-passenger roadway user. Each unit represents a mode of traffic with an independent trajectory.
"most_severe_injury", -- Most severe injury sustained by any person involved in the crash
"injuries_total", -- Total persons sustaining fatal, incapacitating, non-incapacitating, and possible injuries as determined by the reporting officer
"injuries_fatal", -- Total persons sustaining fatal injuries in the crash
"injuries_incapacitating", -- Total persons sustaining incapacitating/serious injuries in the crash as determined by the reporting officer. Any injury other than fatal injury, which prevents the injured person from walking, driving, or normally continuing the activities they were capable of performing before the injury occurred. Includes severe lacerations, broken limbs, skull or chest injuries, and abdominal injuries.
"injuries_non_incapacitating", -- Total persons sustaining non-incapacitating injuries in the crash as determined by the reporting officer. Any injury, other than fatal or incapacitating injury, which is evident to observers at the scene of the crash. Includes lump on head, abrasions, bruises, and minor lacerations.
"injuries_reported_not_evident", -- Total persons sustaining possible injuries in the crash as determined by the reporting officer. Includes momentary unconsciousness, claims of injuries not evident, limping, complaint of pain, nausea, and hysteria.
"injuries_no_indication", -- Total persons sustaining no injuries in the crash as determined by the reporting officer
"injuries_unknown", -- Total persons for whom injuries sustained, if any, are unknown
"crash_hour", -- The hour of the day component of CRASH_DATE.
"crash_day_of_week", -- The day of the week component of CRASH_DATE. Sunday=1
"crash_month", -- The month component of CRASH_DATE.
"weather_condition", -- Weather condition at time of crash, as determined by reporting officer
"latitude", -- The latitude of the crash location, as determined by reporting officer, as derived from the reported address of crash
"intersection_related_i", -- A field observation by the police officer whether an intersection played a role in the crash. Does not represent whether or not the crash occurred within the intersection.
"longitude", -- The longitude of the crash location, as determined by reporting officer, as derived from the reported address of crash
"location", -- The crash location, as determined by reporting officer, as derived from the reported address of crash, in a column type that allows for mapping and other geographic analysis in the data portal software
":@computed_region_rpca_8um6", -- This column was automatically created in order to record in what polygon from the dataset 'Boundaries - ZIP Codes' (rpca-8um6) the point in column 'location' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"lighting_condition", -- Light condition at time of crash, as determined by reporting officer
"crash_type", -- A general severity classification for the crash. Can be either Injury and/or Tow Due to Crash or No Injury / Drive Away
"first_crash_type", -- Type of first collision in crash
"trafficway_type", -- Trafficway type, as determined by reporting officer
"lane_cnt" -- Total number of through lanes in either direction, excluding turn lanes, as determined by reporting officer (0 = intersection)
FROM
"cityofchicago/traffic-crashes-crashes-85ca-t3if:latest"."traffic_crashes_crashes"
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 cityofchicago/traffic-crashes-crashes-85ca-t3if
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 cityofchicago/traffic-crashes-crashes-85ca-t3if: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 cityofchicago/traffic-crashes-crashes-85ca-t3if
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 cityofchicago/traffic-crashes-crashes-85ca-t3if:latest
This will download all the objects for the latest
tag of cityofchicago/traffic-crashes-crashes-85ca-t3if
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 cityofchicago/traffic-crashes-crashes-85ca-t3if: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 cityofchicago/traffic-crashes-crashes-85ca-t3if: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, cityofchicago/traffic-crashes-crashes-85ca-t3if
is just another Postgres schema.