delaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r
Icon for Socrata external plugin

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

"delaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r:latest"."state_of_delaware_nibrs_crime_report_totals_by"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "sub_offense_sub_category", -- The Assault main offense has two primary sub-categories (Aggravated Assault and Simple Assault) and each sub-category, unlike the other 23 main offenses, has its own set of sub-categories (e.g., Aggravated Assault with a Firearm). This section contains those categories. 
    "juvenile_arrests", -- Number of juveniles arrested for the given offense. There can be more than one arrest for a single criminal offense.
    "adult_arrests", -- Number of adults arrested for the given offense. There can be more than one arrest for a single criminal offense.
    "clearance_rate", -- The percentage of offenses that were cleared for that specific offense. 
    "offenses_cleared_by_law_enforcement", -- Total number of offenses that were considered to have been solved by law enforcement for one of several reasons .For crime reporting and analysis purposes, an offense is considered ‘cleared’ or solved when a suspect is either arrested and subsequently referred for prosecution or cannot be arrested but is otherwise clearly identifiable. 
    "sub_offense", -- Most of the 24 main offenses have sub-categories of offenses (e.g., Shoplifting is a sub-category of Larceny-Theft). This field identifies those sub-categories. For the main offenses that have no sub-categories, their names are repeated here.
    "main_offense", -- There are 24 main offenses/crimes in the FBI's National Incident Based Reporting System (NIBRS).  These offenses are termed “Group A” by the FBI.
    "offense_type", -- This is a categorization scheme the Delaware Statistical Analysis Center uses to group Delaware's NIBRS data for reporting purposes. There are four categories: Violent, Serious Property, Drug, and Other Property and Social Offenses. The list of offenses in each category can be found further in this document.
    "number_of_offenses_received_by_law_enforcement", -- Total number of offenses reported by that agency for a specific offense.
    "occur_frequency_based_on_main_offense", -- Since some crimes occur frequently and others infrequently, the Delaware SAC has further classified the 24 main NIBRS offenses into four rough categories to make it easier to generate useful charts and figures. These categories are: Low; Low-Moderate; Moderate; High. The list of crimes included in each category may be found further in this document.
    "agency_code", -- Two character code used to identify a given jurisdiction.
    "jurisdiction", -- The law enforcement agency that completed the offense report. A report filed by an agency that entered another agencies jurisdiction would be filed under the reporting agency and not the jurisdiction it fell under. (Ex: Delaware State Police (DSP) entering a town that does not have a police officer present would be reported under the responding DSP Troop.) All towns that DSP provides coverage for and those with no full-time police officers are designated with an asterisk since a significant portion of the reports for that jurisdiction would be completed by the covering agency.
    "county", -- County the agency is located within. Towns/agencies with one geographic jurisdiction that spans two counties are identified by the county that contains the majority of their offenses. Multi-county/Statewide agencies are identified as “State”.
    "year", -- The calendar year in which crimes occurred.
    "ucr_code" -- An alphanumeric code that the FBI uses to identify crimes reported in the National Incident Based Reporting System. The list of crimes can be found further in this document.
FROM
    "delaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r:latest"."state_of_delaware_nibrs_crime_report_totals_by"
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 delaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.delaware.gov. When you querydelaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r: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

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 (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 cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.delaware.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 \
  "delaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r" \
  --handler-options '{
    "domain": "data.delaware.gov",
    "tables": {
        "state_of_delaware_nibrs_crime_report_totals_by": "8njr-fz7r"
    }
}'

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, delaware-gov/state-of-delaware-nibrs-crime-report-totals-by-8njr-fz7r is just another Postgres schema.