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 east_baton_rouge_parish_combined_crime_incidents
table in this repository, by referencing it like:
"brla-gov/east-baton-rouge-parish-combined-crime-incidents-6zc2-imdr:latest"."east_baton_rouge_parish_combined_crime_incidents"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"statute_title", -- Numerical legal code the LA Revised Statute refers to concerning the crime committed
"crime_prevention_district", -- If applicable, the name of the crime prevention district where the crime occurred
"crime_against", -- Description of the party (Person, Property, or Society) which was a victim of the criminal incident
"statute_description", -- Common terminology for the LA Revised Statutes (ex. theft, battery, property damage)
"sub_zone", -- Tertiary level in the patrol area hierarchy where the crime occurred
"district", -- Primary level in the patrol area hierarchy where the crime occurred
"city", -- Postal city where the crime occurred
"street", -- Specific street location where the crime occurred
"report_date", -- Month, day, year, and time of day when the police officer filed the crime incident report
"charge_id", -- Unique identifier of the crime incident report
"neighborhood", -- Neighborhood where the crime occurred
"nibrs_code", -- National Incident-Based Reporting System code for standardized crime reports used by the FBI and other federal agencies
"state", -- State where the crime occurred
"attempted_committed", -- Code to indicate whether the crime was attempted or committed
"approved_date", -- Date the report was reviewed and approved by the supervisor
"supplemental", -- Additional report used for adding information to the original police report
"longitude", -- Geographic longitude coordinate (east-west) where the crime occurred
"postal_code", -- Postal ZIP code where the crime occurred
"street_2", -- If applicable, the number of the suite or apartment number where the crime occurred
"charge_date", -- Month, day, year, and time of day when the charges for the crime incident took place
"incident_number", -- Report number of the incident
"statute_category", -- One of 18 general codes used for filtering the reported crime data
"zone", -- Secondary level in the patrol area hierarchy where the crime occurred
"agency_name", -- Name of the law enforcement agency
"geolocation", -- Geocoded location for displaying in a map view
"council_district", -- Metropolitan Council district where the crime occurred
"enforcement_agency_id", -- Identification code of the law enforcement agency
"census_block_group", -- Code for the Census block group where the crime occurred
"offense_description", -- Description of the category of the National Incident-Based Reporting System code
"latitude", -- Geographic latitude coordinate (north-south) where the crime occurred
":@computed_region_4pgc_bhg2", -- This column was automatically created in order to record in what polygon from the dataset 'Census 2010 Tracts' (4pgc-bhg2) the point in column 'geolocation' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_ntzg_c2w3", -- This column was automatically created in order to record in what polygon from the dataset 'Council Districts_2021_from_d8sa-f3ec' (ntzg-c2w3) the point in column 'geolocation' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_jrqt_zu77", -- This column was automatically created in order to record in what polygon from the dataset 'ZIP Codes_from_tqy7_429i' (jrqt-zu77) the point in column 'geolocation' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_uvg4_nwq8" -- This column was automatically created in order to record in what polygon from the dataset 'Neighborhoods_from_qfmj_2fwi' (uvg4-nwq8) the point in column 'geolocation' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
FROM
"brla-gov/east-baton-rouge-parish-combined-crime-incidents-6zc2-imdr:latest"."east_baton_rouge_parish_combined_crime_incidents"
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 brla-gov/east-baton-rouge-parish-combined-crime-incidents-6zc2-imdr
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.brla.gov. When you querybrla-gov/east-baton-rouge-parish-combined-crime-incidents-6zc2-imdr: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
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 (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 clone
and sgr checkout
.
Mounting Data
This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.brla.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 \
"brla-gov/east-baton-rouge-parish-combined-crime-incidents-6zc2-imdr" \
--handler-options '{
"domain": "data.brla.gov",
"tables": {
"east_baton_rouge_parish_combined_crime_incidents": "6zc2-imdr"
}
}'
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, brla-gov/east-baton-rouge-parish-combined-crime-incidents-6zc2-imdr
is just another Postgres schema.