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 crime_statistics_washington_state_nibrs_crimes
table in this repository, by referencing it like:
"everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y:latest"."crime_statistics_washington_state_nibrs_crimes"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"persons_grp_a_dv_total", -- Total Persons Group A offenses involving Domestic Violence
"embezzlement_dv", -- Embezzlement involving Domestic Violence
"extortion_arrests", -- Arrests in Extortion cases
"sex_asslt_w_object_arrests", -- Arrests in Sex Asslt w/ Object cases
"incest_dv", -- Incest involving Domestic Violence
"fraud_dv", -- Fraud involving Domestic Violence
"stolen_property_dv", -- Stolen Property involving Domestic Violence
"animal_cruelty_dv", -- Animal Cruelty involving Domestic Violence
"drug_violations_dv", -- Drug Violations involving Domestic Violence
"drug_equipment_violations_1", -- Drug Equipment Violations involving Domestic Violence
"gambling_dv", -- Gambling involving Domestic Violence
"gambling_arrests", -- Arrests in Gambling cases
"pornography_dv", -- Pornography involving Domestic Violence
"other_grp_a_dv_total", -- Total Other Group A offenses involving Domestic Violence
"population", -- Jurisdiction population at time of report
"juvenile_arrest", -- Total juveniles arrested in year
"murder_rate", -- Crime rate per thousand population
"manslaughter_dv", -- Manslaughter involving Domestic Violence
"manslaughter_arrests", -- Arrests in Manslaughter cases
"rape_rate", -- Crime rate per thousand population
"sodomy", -- Sodomy
"sodomy_dv", -- Sodomy involving Domestic Violence
"fondling", -- Fondling
"aggravated_asslt_dv", -- Aggravated involving Domestic Violence
"intimidation", -- Intimidation
"kidnap", -- Kidnap
"kidnap_dv", -- Kidnap involving Domestic Violence
"incest", -- Incest
"incest_arrests", -- Arrests in Incest cases
"incest_rate", -- Crime rate per thousand population
"statutory_rape_dv", -- Statutory Rape involving Domestic Violence
"statutory_rape_arrests", -- Arrests in Statutory Rape cases
"statutory_rape_rate", -- Crime rate per thousand population
"human_trafficking_dv", -- Human Trafficking involving Domestic Violence
"human_trafficking_rate", -- Crime rate per thousand population
"persons_grp_a_rate", -- Total Persons Group A Crime rate per thousand population
"burglary_dv", -- Burglary involving Domestic Violence
"auto_theft_rate", -- Crime rate per thousand population
"forgery", -- Forgery
"forgery_dv", -- Forgery involving Domestic Violence
"fraud_arrests", -- Arrests in Fraud cases
"embezzlement_arrests", -- Arrests in Embezzlement cases
"bribery", -- Bribery
"bribery_dv", -- Bribery involving Domestic Violence
"bribery_arrests", -- Arrests in Bribery cases
"bribery_rate", -- Crime rate per thousand population
"property_grp_a_total", -- Total Property Group A Offenses
"property_grp_a_dv_total", -- Total Property Group A offenses involving Domestic Violence
"drug_equipment_violations", -- Drug Equipment Violations
"gambling_rate", -- Crime rate per thousand population
"pornography_arrests", -- Arrests in Pornography cases
"prostitution_dv", -- Prostitution involving Domestic Violence
"prostitution_arrests", -- Arrests in Prostitution cases
"prostitution_rate", -- Crime rate per thousand population
"other_grp_a_rate", -- Total Other Group A Crime rate per thousand population
"total_offense", -- Total NIBRS Group A Offenses reported for year
"total_arrest", -- Total arrests, adult and juvenile
"murder_dv", -- Murder involving Domestic Violence
"murder_arrests", -- Arrests in murder cases
"manslaughter_rate", -- Crime rate per thousand population
"sex_asslt_w_object_rate", -- Crime rate per thousand population
"aggravated_assault_rate", -- Crime rate per thousand population
"intimidation_dv", -- Intimidation involving Domestic Violence
"kidnap_rate", -- Crime rate per thousand population
"violation_protection_no_2", -- Arrests in Violation Protection/No Contact Order cases
"violation_protection_no_3", -- Crime rate per thousand population
"robbery_dv", -- Robbery involving Domestic Violence
"burglary_arrests", -- Arrests in Burglary cases
"larceny_arrests", -- Arrests in Larceny cases
"embezzlement", -- Embezzlement
"prostitution", -- Prostitution
"weapons_law_violations_dv", -- Weapons Law Violations involving Domestic Violence
"other_grp_a_total", -- Total Other Group A Offenses
"agency", -- Reporting agency or jurisdiction
"county", -- County reporting agency is in
"agency_type", -- PD- Police Agency, SO- Sheriffs Office, UNIV- University Police, PORT- Port Police, TSKF- Task Force, TRIBAL- Tribal Police, STATE- State agency
"year", -- Year crime statistics were reported
"offenses_cleared", -- Number of offenses cleared with an arrest or exceptional means in the year
"percentage_cleared", -- Percentage of cleared offenses
"adult_arrest", -- Total adults arrested in year
"murder", -- Murder
"manslaughter", -- Manslaughter
"rape", -- Rape
"rape_dv", -- Rape involving Domestic Violence
"rape_arrests", -- Arrests in Rape cases
"sodomy_arrests", -- Arrests in Sodomy cases
"sodomy_rate", -- Crime rate per thousand population
"sex_asslt_w_object", -- Sex Asslt w/ Object
"sex_asslt_w_object_dv", -- Sex Asslt w/ Object involving Domestic Violence
"fondling_dv", -- Fondling involving Domestic Violence
"fondling_arrests", -- Arrests in Fondling cases
"fondling_rate", -- Crime rate per thousand population
"aggravated_asslt", -- Aggravated Asslt
"aggravated_asslt_arrests", -- Arrests in Aggravated Asslt cases
"simple_assault", -- Simple Assault
"simple_assault_dv", -- Simple Assault involving Domestic Violence
"simple_assault_arrests", -- Arrests in Simple Assault cases
"simple_assault_rate", -- Crime rate per thousand population
"intimidation_arrests", -- Arrests in Intimidation cases
"intimidation_rate", -- Crime rate per thousand population
"kidnap_arrests", -- Arrests in Kidnap cases
"statutory_rape", -- Statutory Rape
"human_trafficking", -- Human Trafficking
"human_trafficking_arrests", -- Arrests in Human Trafficking cases
"violation_protection_no", -- Violation Protection/No Contact Order
"violation_protection_no_1", -- Violation Protection/No Contact Order involving Domestic Violence
"persons_grp_a_total", -- Total Persons Group A Offenses
"persons_grp_a_arrests", -- Total Arrests Persons Group A offenses
"robbery", -- Robbery
"robbery_arrests", -- Arrests in Robbery cases
"robbery_rate", -- Crime rate per thousand population
"burglary", -- Burglary
"burglary_rate", -- Crime rate per thousand population
"larceny", -- Larceny
"larceny_dv", -- Larceny involving Domestic Violence
"larceny_rate", -- Crime rate per thousand population
"auto_theft", -- Auto Theft
"auto_theft_dv", -- Auto Theft involving Domestic Violence
"auto_theft_arrests", -- Arrests in Auto Theft cases
"arson", -- Arson
"arson_dv", -- Arson involving Domestic Violence
"arson_arrests", -- Arrests in Arson cases
"arson_rate", -- Crime rate per thousand population
"destruction_of_property", -- Destruction of Property
"destruction_of_property_dv", -- Destruction of Property involving Domestic Violence
"destruction_of_property_1", -- Arrests in Destruction of Property cases
"destruction_of_property_rate", -- Crime rate per thousand population
"forgery_arrests", -- Arrests in Forgery cases
"forgery_rate", -- Crime rate per thousand population
"fraud", -- Fraud
"fraud_rate", -- Crime rate per thousand population
"embezzlement_rate", -- Crime rate per thousand population
"extortion", -- Extortion
"extortion_dv", -- Extortion involving Domestic Violence
"extortion_rate", -- Crime rate per thousand population
"stolen_property", -- Stolen Property
"stolen_property_arrests", -- Arrests in Stolen Property cases
"stolen_property_rate", -- Crime rate per thousand population
"property_grp_a_arrests", -- Total Arrests Property Group A offenses
"property_group_a_rate", -- Total Property Crime Group A rate per thousand population
"animal_cruelty", -- Animal Cruelty
"animal_cruelty_arrests", -- Arrests in Animal Cruelty cases
"animal_cruelty_rate", -- Crime rate per thousand population
"drug_violations", -- Drug Violations
"drug_violations_arrests", -- Arrests in Drug Violations cases
"drug_violations_rate", -- Crime rate per thousand population
"drug_equipment_violations_2", -- Arrests in Drug Equipment Violations cases
"drug_equipment_violations_3", -- Crime rate per thousand population
"gambling", -- Gambling
"pornography", -- Pornography
"pornography_rate", -- Crime rate per thousand population
"weapons_law_violations", -- Weapons Law Violations
"weapons_law_violations_arrests", -- Arrests in Weapons Law Violations cases
"weapons_law_violations_rate", -- Crime rate per thousand population
"other_grp_a_arrests", -- Total Arrests Other Group A offenses
"all_grp_a_total", -- Total all Group A offenses combined
"all_grp_a_dv", -- Total all Group A offenses combined involving Domestic Violence
"all_grp_a_arrests", -- Total all Group arrests combined
"all_grp_a_rate" -- Total all Group A crime rate per thousand population
FROM
"everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y:latest"."crime_statistics_washington_state_nibrs_crimes"
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 everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y
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 everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y: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 everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y
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 everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y:latest
This will download all the objects for the latest
tag of everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y
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 everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y: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 everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y: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, everettwa-gov/crime-statistics-washington-state-nibrs-crimes-qgde-h82y
is just another Postgres schema.