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 austin_crash_report_data_crash_level_records
table in this repository, by referencing it like:
"datahub-austintexas-gov/austin-crash-report-data-crash-level-records-y2wy-tgr5:latest"."austin_crash_report_data_crash_level_records"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"unkn_injry_cnt", -- Total Unknown Injury Count
"case_id", -- Case ID
"crash_timestamp", -- The timestamp at which the crash occurred, in UTC time.
"private_dr_fl", -- Flag indicating whether crash occurred on a private drive or road/private property/parking lot.
"crash_timestamp_ct", -- The timestamp at which the crash occurred, in US/Central time.
"sus_serious_injry_cnt", -- Total Suspected Serious Injury Count
":@computed_region_m2th_e4b7",
":@computed_region_rxpj_nzrk",
":@computed_region_8spj_utxs",
"rpt_street_name", -- Reported Street Name (road on which crash occurred)
"longitude", -- Derived Longitude map coordinate of the crash
"poss_injry_cnt", -- Total Possible Injury Count
"motor_vehicle_death_count", -- The number of victims in this crash who sustained fatal injuries and were occupants of a motor vehicle
":@computed_region_jcrc_4uuy",
"bicycle_death_count", -- The number of victims in this crash who sustained fatal injuries and were occupants of a bicycle
":@computed_region_q9nd_rr82",
"crash_speed_limit", -- Speed Limit
"tot_injry_cnt", -- Total Injury Count
"is_deleted", -- If the record has been "deleted" and is not to included in reporting metrics. The Vision Zero database has a mechanism for soft-deleting records using this boolean flag. Although all records in this dataset are not deleted, a future iteration may included deleted records in order to simplify our data publication process.
":@computed_region_e9j2_6w3z",
"micromobility_serious_injury_count", -- The number of victims in this crash who sustained serious injuries and were occupants of a micromobility device such as an e-scooter
"bicycle_serious_injury_count", -- The number of victims in this crash who sustained serious injuries and were occupants of a bicycle
"address_primary", -- The primary address where the crash is reported to have occurred
"pedestrian_serious_injury_count", -- The number of victims in this crash who sustained serious injuries and were pedestrians
"rpt_street_sfx", -- Reported Street Suffix (road on which crash occurred)
"nonincap_injry_cnt", -- Total Non-incapacitating Injury Count
"id", -- The unique crash identifier within the Vision Zero crash database
"units_involved", -- Mode of units involved in crash
"other_death_count", -- The number of victims in this crash who sustained fatal injuries and were not categorized under any other mode of transportation
"motorcycle_death_count", -- The number of victims in this crash who sustained fatal injuries and were occupants of a motorcycle
"crash_fatal_fl", -- Fatal Crash Identifier - Indicates that the crash involved one or more fatalities
"motorcycle_serious_injury_count", -- The number of victims in this crash who sustained serious injuries and were occupants of a motorcycle
"motor_vehicle_serious_injury_count", -- The number of victims in this crash who sustained serious injuries and were occupants of a motor vehicle
"is_temp_record", -- If the record is a "temporary" record, which means that the record was manually created in the database by Vision Zero staff, as opposed to the record having been created from our integration with the TxDOT CRIS database. Because there can be a lag time of weeks, even months, before law enforcement investigators submit their crash report to TxDOT, the Vision Zero team occasionally creates temporary records so that our reporting metrics are more timely/accurate. The expectation is that a temporary record will be deleted from the database once the official crash report has been received.
"law_enf_fatality_count", -- The the number of fatalities resulting from this crash, as reported by the investigating law enforcement agency. This may vary from the Vision Zero program's statistical reporting in certain circumstances.
"death_cnt", -- Total Death Count
"cris_crash_id", -- TxDOT C.R.I.S. system-generated unique identifying number for a crash
"rpt_street_pfx", -- The street prefix of the primary address at which the crash occurred.
"road_constr_zone_fl", -- Construction Zone - Indicates whether the crash occurred in or was related to a construction, maintenance, or utility work zone, regardless of whether or not workers were actually present at the time of the crash
"non_injry_cnt", -- Total Not Injured Count
"point", -- Point datatype created with crash latitude and longitude to enable request of GeoJSON.
"address_secondary", -- The secondary address where the crash is reported to have occurred. Typically the cross street or nearest cross street.
"onsys_fl", -- Flag indicates whether primary road of crash was on the TxDOT highway system.
"rpt_block_num", -- Reported Block Number (road on which crash occurred)
"latitude", -- Derived Latitude map coordinate of the crash
"other_serious_injury_count", -- The number of victims in this crash who sustained serious injuries and were not categorized under any other mode of transportation
"micromobility_death_count", -- The number of victims in this crash who sustained fatal injuries and were occupants of a micromobility device such as an e-scooter
"crash_sev_id", -- Crash Severity - Most severe injury suffered by any one person involved in the crash ( 0=UNKNOWN, 1=INCAPACITATING INJURY, 2=NON-INCAPACITATING INJURY, 3=POSSIBLE INJURY, 4=KILLED, 5=NOT INJURED)
"pedestrian_death_count" -- The number of victims in this crash who sustained fatal injuries and were pedestrians
FROM
"datahub-austintexas-gov/austin-crash-report-data-crash-level-records-y2wy-tgr5:latest"."austin_crash_report_data_crash_level_records"
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 datahub-austintexas-gov/austin-crash-report-data-crash-level-records-y2wy-tgr5
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at datahub.austintexas.gov. When you querydatahub-austintexas-gov/austin-crash-report-data-crash-level-records-y2wy-tgr5: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 datahub.austintexas.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 \
"datahub-austintexas-gov/austin-crash-report-data-crash-level-records-y2wy-tgr5" \
--handler-options '{
"domain": "datahub.austintexas.gov",
"tables": {
"austin_crash_report_data_crash_level_records": "y2wy-tgr5"
}
}'
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, datahub-austintexas-gov/austin-crash-report-data-crash-level-records-y2wy-tgr5
is just another Postgres schema.