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

"lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe:latest"."lapd_ripa_ab_953_stop_person_detail_from_712018_to"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "stop_number", -- Unique identifier for the incident.  (an incident can include multiple persons)
    "result_of_stop_field_interview", -- Stop resulting in a field interview card being completed?
    "result_of_stop_arrest_without", -- Section and subdivision using the Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "arrest_offense_code", -- Offense Code using the  Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "result_of_stop_custodial_1", -- Stop resulted in Custodial arrest without warrant?
    "result_of_stop_infraction", -- Section and subdivision using the Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "in_field_cite_offense_code", -- Offense Code using the  Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "result_of_stop_citation_for_1", -- Section and subdivision using the Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "waring_offense_code", -- Offense Code using the  Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "stop_time", -- Approximate time of the stop, in 24 hour military time
    "pretext", -- (Field was officially added on 4/01/22) Officers use reasonable suspicion or probable cause of a minor traffic or code violation to investigate another, more serious crime that is unrelated to that violation 
    "type_of_stop", -- (Field was officially added on 6/30/21) Represents the type of involvement of the person being stopped.
    "search_basis_narrative", -- A brief explanation is required regarding the basis for the search and must provide additional detail beyond the general data values selected.  This field is not required if basis for search is "condition of parole/probation/PRCS/mandatory supervision."
    "result_of_stop_warning_offense", -- Section and subdivision using the Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "result_of_stop_referred_to", -- The stop resulted in person being referred to U.S. Department of Homeland Security?  (e.g., ICE, CBP)
    "result_of_stop_referral_to", -- The stop resulted in student being referred to school administrator?
    "result_of_stop_psychiatric", -- The stop resulted in psychiatric hold?  (Welfare & Inst. Code, 5150, 5585.20.)
    "result_of_stop_noncriminal", -- Stop resulted in noncriminal transport or caretaking transport?  (including transport by officer, transport by ambulance, or transport by another agency)
    "result_of_stop_custodial", -- Stop resulted In Custodial arrest pursuant to outstanding warrant?
    "result_of_stop_contacted", -- Stop resulted in contacting parent/legal guardian or other person responsible for the minor?  
    "property_seized_weapon_s", -- Weapon(s) seized?
    "property_seized_drugs", -- Drug/Narcotics seized?
    "property_seized_drug", -- Drug paraphernalia seized?
    "property_seized_cell_phone", -- Cell phone(s) or electronic device(s) seized? 
    "property_seized_alcohol", -- Alcohol seized?
    "perceived_lgbt", -- Person perceived to be a LGBT? (LGBT -  Lesbian, Gay, Bisexual, Transgender man/boy, Transgender woman/girl)
    "perceived_hispanic_latino", -- Person perceived to be  Hispanic/Latino(a)?  (refers to Mexican, Puerto Rican, Cuban, Central or South American, or other Spanish culture or origin)
    "perceived_gender", -- Person perceived to be a  Male, Female, Transgender man/boy, Transgender woman/girl, or Gender nonconforming?  *  Transgender man/boy - female at birth but currently identifies as a man or a boy   *  Transgender woman/girl - male at birth but currently identifies as a woman or a girl    *  Gender nonconforming refers to gender-related appearance differ from traditional conceptions about how males or females typically look or behave
    "perceived_black_african", -- Person perceived to be  Black/African? (refers to Black racial groups of Africa)
    "perceived_asian", -- Person perceived to be Asian? (refers to a person having origins in any of the original peoples of the Far East or South East Asia, including, Cambodia, China, Japan, Korea, Malaysia, the Philippine Islands, Thailand, and Viet)
    "perceived_age", -- Perceived approximate age of the person (in whole numbers)
    "no_disability", -- Person had No perceived or known disability?
    "limited_or_no_english_fluency", -- Person perceived to have limited or no fluency in English? 
    "intellectual_or_developmental", --  Person perceived or known to have an Intellectual or Developmental Disability?
    "hyperactivity_or_impulsive", -- Person perceived or known to have a disability of impulsive behavior?
    "deafness_or_difficulty_hearing", -- Person perceived or known to have a disability of deafness or difficulty hearing?
    "contraband_evidence_discovered_9", -- Cell Phone(s) or electronic device(s) was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_8", -- Suspected stolen property was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_6", -- Money was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_5", -- Alcohol was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_4", -- Drugs/Narcotics were discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_3", -- Weapon(s) other than a Firearm was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_2", -- Ammunition was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered_10", -- Other contraband or evidence was discovered in plain view or as the result of a search?
    "contraband_evidence_discovered_1", -- Firearm(s) was discovered as contraband or evidence in plain view or as the result of a search?
    "citation_offense_code", -- Offense Code using the  Department's standard Criminal Justice Information Services (CJIS) Offense Table
    "blind_or_limited_vision", -- Person perceived or known to have a disability of blindness or Limited Vision?
    "basis_of_reasonable_suspicion_7", -- Person's actions indicative of engaging in a violent crime?
    "basis_of_reasonable_suspicion_6", -- Person's actions were indicative of a drug transaction?
    "basis_of_reasonable_suspicion_5", -- Person suspected of acting as a lookout?
    "basis_of_reasonable_suspicion_4", -- Person appeared to be casing a victim or location?
    "basis_of_reasonable_suspicion_3", -- Person was carrying suspicious object? 
    "basis_of_reasonable_suspicion_2", -- Person stopped based on a witness or victim identification of suspect at the scene?
    "basis_of_reasonable_suspicion_1", -- Person matched suspect description?
    "basis_of_reasonable_suspicion", -- Witnessed person in a commission of a crime?
    "basis_for_stop", -- Basis of reasonable suspicion for Stop.
    "basis_for_search_vehicle", -- Vehicle inventory (for search of property only) was the basis for the search?
    "basis_for_search_suspected_1", -- Suspected violation of vchool policy was the basis for the search?
    "basis_for_search_suspected", -- Suspected weapons was the basis for the search?
    "basis_for_search_search", -- Search for warrant was the basis for the search? 
    "basis_for_search_officer", -- Search performed for  officer safety and safety of others?
    "basis_for_search_odor_of", -- Odor of contraband was the basis for the search? 
    "basis_for_search_incident", -- Incident to arrest was the basis for the search?
    "basis_for_search_exigent", -- Exigent circumstances was the basis for the search?
    "basis_for_search_evidence", -- Evidence of a crime was the basis for the search?
    "basis_for_search_consent", -- Consent Given? 
    "basis_for_search_condition", -- Condition of Parole, Probation, PRCS, and Mandatory Supervision  was the basis for the search? 
    "basis_for_search_canine", -- Canine detention was the basis for the search?
    "basis_for_property_seizure_5", -- Suspected violation of school policy as the basis for property seizure?
    "basis_for_property_seizure_4", -- Abandoned property as the basis for property seizure?
    "basis_for_property_seizure_3", -- Impound of vehicle as the basis for property seizure?
    "basis_for_property_seizure_2", -- Evidence as the basis for property seizure?
    "basis_for_property_seizure_1", -- Contraband as the basis for property seizure?
    "basis_for_property_seizure", -- Safekeeping as allowed by law/statue as the basis for property seizure?
    "action_taken_search_of_person", -- Search of person conducted?
    "action_taken_search_of", -- Search of property conducted?
    "action_taken_property_was", -- Property was seized? 
    "action_taken_person_removed_1", -- Person removed from vehicle by physical contact?
    "action_taken_firearm_pointed", -- Firearm pointed at the person?
    "action_taken_firearm", -- Firearm discharged or used?
    "action_taken_electronic", -- Electronic Control Device used?
    "action_taken_canine_removed", -- Canine removed from vehicle or used to search?
    "action_taken_canine_bit_or", -- Canine bit or held person?
    "action_taken_baton_or_other", -- Baton or other impact weapon used? 
    "action_taken_asked_consent_1", -- Asked for consent to search property?
    "action_taken_admission_or", -- Admission or written statement obtained from student?
    "result_of_stop_referral_to_1", -- The stop resulted in student being referred to school counselor or other support staff?
    "result_of_stop_in_field_cite", -- The stop resulted In-field cite and release?
    "result_of_stop_citation_for", -- Citation for infraction was issued as a result of the stop?
    "result_of_stop_warning", -- Officer issued a warning? 
    "result_of_stop_no_action", -- Stop resulted with no action by officer?
    "property_seized_other", -- Contraband or evidence seized?
    "property_seized_vehicle", -- Vehicle seized? 
    "property_seized_suspected", -- Suspected stolen property seized? 
    "property_seized_money", -- Money seized?
    "property_seized_ammunition", -- Ammunition seized?
    "property_seized_firearm_s", -- Firearm(s) seized?
    "contraband_evidence_discovered_7", -- Drug paraphernalia was discovered as contraband or evidence in plain view or as the result of a search?
    "contraband_evidence_discovered", -- No contraband/evidence was discovered?
    "basis_for_search_visible", -- Visible contraband was the basis for the search?
    "action_taken_none", -- Any action taken?
    "action_taken_vehicle_impound", -- Vehicle Impound?  
    "consent_granted_property", -- Consent granted to search property?
    "consent_granted_person", -- Consent granted to search person?
    "action_taken_asked_consent", -- Asked for consent to search person? 
    "action_taken_person", -- Person photographed?
    "action_taken_other_physical", -- Other physical or vehicle contact?
    "action_taken_chemical_spray", -- Chemical Spray used?
    "action_taken_impact_projectile", -- Impact Projectile Discharged or used?
    "action_taken_patrol_car", -- Person detained in patrol vehicle?
    "action_taken_handcuffed_or", -- Person handcuffed or flex cuffed?
    "action_taken_curbside", -- Person placed on curbside detention?
    "action_taken_field_sobriety", -- Person had a field sobriety test?
    "action_taken_person_removed", -- Person removed from vehicle by order?
    "education_code_subdivision", -- Possible conduct warranting discipline under Education Code Subdeivision 48900(a) through 48900(r); 48900.2; 48900.3; 48900.4; and 48900.7(a).
    "education_code_section", -- Education Code Section for possible conduct warranting discipline under Education Code Sections 48900, 48900.2, 48900.3, 48900.4, and 48900.7. 
    "basis_of_reasonable_suspicion_8", -- Officer had other reasonable suspicion of a crime?
    "traffic_violation_type", -- Person stopped for traffic violation?
    "offense_type_statute", -- Section and subdivision using the standard DOJ Criminal Justice Information Services (CJIS) Offense Table
    "offense_code", -- Offense Code using the standard DOJ Criminal Justice Information Services (CJIS) Offense Table
    "reason_for_stop", -- Reason for Stop refers to the primary reason why the officer stopped the person    
    "other_disability", -- Person perceived or known to have other disabilities?
    "mental_health_condition", -- Person perceived or known to have a disability of Mental Health Condition or not?
    "speech_impairment_or_limited", -- Person perceived or known to have a disability of speech Impairment or limited use of language?
    "perceived_white", -- Person perceived to be  White? (refers to Caucasian descent having origins in any of the original peoples of Europe and Eastern Europe)
    "perceived_pacific_islander", -- Person perceived to be Pacific Islander? (refers to Hawaii, Guam, Samoa, or other Pacific Islands)
    "perceived_native_american", -- Person perceived to be  Native American? (refers to a person having origins in any of the original peoples of North, Central, and South America) 
    "perceived_middle_eastern", -- Person perceived to be  Middle Eastern or South Asian? (refers Arabic, Israeli, Iranian, Indian, Pakistani, Bangladeshi, Sri Lankan, Nepali, Bhutanese, Maldivian, or Afghan origin)
    "perceived_race_before_contact", -- Officer perceived the persons race before the contact (stop).
    "student", -- Was the person a K-12 student? 
    "area_name", -- Name of the Geographic Area within the LAPD where the STOP Incident occurred.  The LAPD has 21 Geographical Areas.
    "area_id", -- Area ID where the Stop Incident Occurred.  The LAPD has 21 Community Police Stations referred to as Geographic Areas within the department. These Geographic Areas are sequentially numbered from 1-21.
    "reporting_district", -- Four-digit code that represents a sub-area within a Geographic Area. All arrest records reference the "RD" that it occurred in for statistical comparisons. Find LAPD Reporting Districts on the LA City GeoHub at http://geohub.lacity.org/datasets/lapd-reporting-districts?geometry=-121.023%2C33.621%2C-115.797%2C34.418
    "stop_date", -- (MM/DD/YYYY) Year, month, and day that stop occurred
    "person_id" -- Unique identifier for each person stopped.
FROM
    "lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe:latest"."lapd_ripa_ab_953_stop_person_detail_from_712018_to"
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 lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe 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 lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe: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 lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe

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 lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe:latest

This will download all the objects for the latest tag of lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe 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 lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe: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 lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe: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, lacity/lapd-ripa-ab-953-stop-person-detail-from-712018-to-bwdf-y5fe is just another Postgres schema.

Related Documentation:

Loading...