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 strategic_subject_list_historical
table in this repository, by referencing it like:
"cityofchicago/strategic-subject-list-historical-4aki-r3np:latest"."strategic_subject_list_historical"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"sex_code_cd", -- Subject's Sex as of their latest arrest record.
"latitude", -- Latitude of Centroid of Census Tract of Arrest for the Subject's latest arrest record.
"idoc_res_zip_code", -- Subject's Zip Code of Residence as entered on a matching Illinois Department of Corrections Record.
"majority_dist", -- Police District in which the largest number of contacts occurred.
"location_state",
"location_city",
"location_address",
":@computed_region_bdys_3d7i",
":@computed_region_rpca_8um6",
":@computed_region_vrxf_vc4k",
":@computed_region_6mkv_f3dw",
":@computed_region_43wa_7qmu",
"predictor_rat_victim_battery_or_assault", -- Attribute RAW Score; The raw score calculated by the model; The number of times an individual has been the victim of an aggravated battery or aggravated assault; .
"weapons_arr_cnt", -- Count of Weapons (UUW) Arrests in last 10 years.
"community_area", -- Community Area of Arrest for the Subject's latest arrest record.
"predictor_rat_gang_affiliation", -- Attribute RAW Score; The raw score calculated by the model; Indicator if an individual has been confirmed to be a member of a criminal street gang. 1=Yes; 0=No
"status_i", -- Is 'Y' if SSL_SCORE is the latest version of the score for this subject.
"latest_weapon_arr_date", -- Date of Latest Weapons (UUW) Arrest .
"idoc_res_state_code", -- Subject's State of Residence as entered on a matching Illinois Department of Corrections Record.
"predictor_rat_uuw_arrests", -- Attribute RAW Score; The raw score calculated by the model; The number of times the individual has been arrested for Unlawful Use of Weapons.
"location", -- Centroid of Census Tract of Arrest for the Subject's latest arrest record.
"narcotics_arr_cnt", -- Count of Drug Arrests in last 10 years.
"dlst", -- State of issue for Latest of entry of Subject's Drivers License Number (if any) found in any arrest record.
"latest_domestic_arr_date", -- Date of Latest Domestic Violence Arrest .
"predictor_rat_trend_in_criminal_activity", -- Attribute RAW Score; The raw score calculated by the model; The trend of an individual's recent criminal activity.
"census_tract", -- Census Tract of Arrest for the Subject's latest arrest record.
"idoc_cpd_dist", -- Police District associated with Subject's Address of Residence as entered on a matching Illinois Department of Corrections Record.
"cpd_arrest_i", -- Is 'Y' if most recent arrest is a Chicago Police arrest and not a surrounding County arrest.
"ssl_flags", -- One or more police units flagged as associated with the subject for purposes of the Strategic Subjects List program.
"longitude", -- Longitude of Centroid of Census Tract of Arrest for the Subject's latest arrest record.
"pre_raw_heat_score", -- An integer-scaled version of the RAW_SSL_SCORE.
"latest_dist", -- Police District in which latest contact occurred.
"ssl_last_ptv_date", -- Most recent date that the subject was matched with a victim or arrest record making the subject a 'Party to Violence'
"idoc_res_city", -- Subject's City of Residence as entered on a matching Illinois Department of Corrections Record.
"parolee_i", -- Is 'Y' if the subject is matched with a recent Illinois Department of Corrections Record indicating the subject is currently on Parole.
"predictor_rat_age_at_latest_arrest", -- Attribute RAW Score; The raw score calculated by the model; The individual's age at the time of their most recent arrest.
"predictor_rat_victim_shooting_incidents", -- Attribute RAW Score; The raw score calculated by the model; The number of times an individual has been the victim of a shooting.
"ssl_score", -- Strategic Subject List Score.
"location_zip",
"domestic_arr_cnt", -- Count of Domestic Violence Arrests in last 10 years.
"raw_heat_score", -- Same as RAW_SSL_SCORE.
"heat_score", -- Same as SSL_SCORE.
"latest_narcotic_arr_date", -- Date of Latest Drug Arrest .
"trap_status", -- Severity category using the old (Pre-2015) Targeted Repeat Offender Program.(TRAP) criteria.
"predictor_rat_arrests_violent_offenses", -- Attribute RAW Score; The raw score calculated by the model; The number of times the individual has been arrested for a violent offense.
"age_group", -- Subject's Age as of their latest arrest record.
"age_to", -- If Age is an estimated range, this is the upper end of that range
"weapon_i", -- Is 'Y' if at least one Weapon (UUW) Arrest in past 10 years.
"latest_dist_res", -- District of Residence as of the subject's latest arrest record.
"drug_i", -- Is 'Y' if at least one Drug Arrest in past 10 years.
"race_code_cd", -- Subject's Race/Ethnicity as of their latest arrest record: BLK - Black; WHI - White; API - Asian/Pacific Islander; WBH - Black Hispanic; WWH - White Hispanic; I - American Indian/Alaskan Native; U - Unknown
"stop_order_no", -- If an outstanding investigative alert exists for this subject, this is the Investigative Alert (previously known as Stop Order) number.
"latest_date", -- Latest date of police contact.
"raw_ssl_score", -- An intermediate version of the SSL score prior to being normalized that was a byproduct of earlier predictive models.
"trap_flags", -- One or more police units flagged as associated with the subject for purposes of the Targeted Repeat Offender program.
"age_curr", -- Subject's Current Age.
"predictor_rat_narcotic_arrests" -- Attribute RAW Score; The raw score calculated by the model; The number of times the individual has been arrested for a narcotics offense.
FROM
"cityofchicago/strategic-subject-list-historical-4aki-r3np:latest"."strategic_subject_list_historical"
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/strategic-subject-list-historical-4aki-r3np
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/strategic-subject-list-historical-4aki-r3np: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/strategic-subject-list-historical-4aki-r3np
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/strategic-subject-list-historical-4aki-r3np:latest
This will download all the objects for the latest
tag of cityofchicago/strategic-subject-list-historical-4aki-r3np
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/strategic-subject-list-historical-4aki-r3np: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/strategic-subject-list-historical-4aki-r3np: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/strategic-subject-list-historical-4aki-r3np
is just another Postgres schema.