datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9
Loading...

Query the Data Delivery Network

Query the DDN

The 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_victim_demographic table in this repository, by referencing it like:

"datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9:latest"."austin_crash_report_data_crash_victim_demographic"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "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.
    "cris_crash_id", -- The unique identifier of the crash record in the TxDOT CRIS database. This is distinct from our internal ID column, which is used as the primary key for all crash records within our data system.
    "crash_pk", -- The Vision Zero database ID of the crash record associated with this person record
    "crash_timestamp_ct", -- The timestamp of the crash, in US/Central time
    "mode_desc", -- Unit description of person
    "prsn_age", -- The age of the person involved in the crash.
    "unit_id", -- The unique ID identifier of the unit record associated with this person record in the Vision Zero databse
    "crash_timestamp", -- The timestamp of this crash, in UTC time
    "mode_id", -- Vehicle mode of person
    "prsn_ethnicity_label", -- The ethnicity of the crash victim as reported by the responding law enforcement agency
    "id", -- The unique identifier of this person record 
    "prsn_sex_label", -- The biological sex of the crash victim, as reported by the investigating law enforcement agency
    "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.
    "prsn_sex_id", -- The biological sex ID of the crash victim, as reported by the investigating law enforcement agency.  where 0 = UNKNOWN; 1 = MALE; 2 = FEMALE, 95 = AUTONOMOUS VEHICLE
    "is_primary_person", -- This field indicates if this person was was the driver/operator of a vehicle/mode of transportation involved in the crash. The field is not applicable if the person was a pedestrian.
    "prsn_injry_sev_id", -- The severity of the involved person's injury, with 1 indicating an incapacitating or suspected serious injury and 4 indicating a fatal injury.
    "prsn_ethnicity_id" -- Person Ethnicity ID. Coded as: 0: UNKNOWN, 1: WHITE, 2: HISPANIC, 3: BLACK, 4: ASIAN, 5: OTHER, 6: AMER. INDIAN/ALASKAN NATIVE, 94: REPORTED INVALID, 95: NOT REPORTED
FROM
    "datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9:latest"."austin_crash_report_data_crash_victim_demographic"
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-victim-demographic-xecs-rpy9 with SQL in under 60 seconds.

Query Your Local Engine

Install Splitgraph Locally
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; sgrcan 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 cloneand sgr checkout.

Cloning Data

Because datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9: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 datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9

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 datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9:latest

This will download all the objects for the latest tag of datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9 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 datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9: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 datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9: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, datahub-austintexas-gov/austin-crash-report-data-crash-victim-demographic-xecs-rpy9 is just another Postgres schema.

Related Documentation:

Loading...