brla-gov/311-citizen-requests-for-service-7ixm-mnvx
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 311_citizen_requests_for_service table in this repository, by referencing it like:

"brla-gov/311-citizen-requests-for-service-7ixm-mnvx:latest"."311_citizen_requests_for_service"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "cityname", -- The city of the reported issue - Baton Rouge, Baker, Zachary, or Central. Issues reported in the unincorporated areas of East Baton Rouge Parish or without city information are reported as East Baton Rouge.
    "streetname", -- The name of the street where services are needed or issues need to be resolved.
    "typename", -- A description of the type of service request represented by the request ID - matches that of the TypeID field.
    "closeddate", -- The date the service request was closed due to the request  as being addressed or the issue  being resolved, confirmed by the responding department/division.
    "statusdesc", -- Matches Status ID - Open, Closed, or In Progress.
    "streetnum", -- The street number of the address where services are needed or issues need to be resolved.
    "createdate", -- The date the service request was created within the City-Parish's 311 service request and complaint tracking system, either by phone, online, or via web app.
    "deptdivid", -- The ID of the City-Parish department and division responsible for responding to the requested service or reported issue. 
    "crossname", -- Any cross street information available as reported by the submitting citizen (for example, at an intersection).
    "parentid", -- The parent category ID of the type of service request (typename) as organized within the City-Parish 311 Citizen Request system. 
    "deptdiv", -- The City-Parish department and division responsible for responding to the requested service or reported issue - matches that of the DeptDivID field.
    "latitude", -- The latitude coordinates of the issue or request for service for geocoding purposes.
    "status", -- Status of service request 0 = Open, 1 = Closed, 3 = In Progress.
    "geolocation",
    "comments", -- Any comments submitted by the reporting citizen associated with the request for service or issue to be resolved.
    "typeid", -- The specific type of service request represented by the request ID. 
    "longitude", -- The longitude coordinates of the issue or request for service for geocoding purposes.
    "streetaddress", -- The full street address where service are needed or issues need to be resolved.
    "id", -- Unique identifier assigned to each citizen request for service for tracking and resolution purposes.
    "division", -- The City-Parish division responsible for responding to the requested service or reported issue, which is a division of the department noted in the Department field.
    "department", -- The City-Parish department with oversight over the requested service or reported issue.
    "lastaction", -- The date of the most recent adjustment or notation to this service request, as noted by the responding department/division. Typically, this field will match that of the closed date if a request has been resolved or closed.
    "parenttype", -- The parent type of service request - matches that of the ParentID field.
    "geolocation_city",
    "geolocation_zip",
    "geolocation_state",
    "geolocation_address",
    ":@computed_region_ntzg_c2w3",
    ":@computed_region_jrqt_zu77",
    ":@computed_region_uvg4_nwq8",
    ":@computed_region_i2e6_956r",
    ":@computed_region_8siy_mghw",
    ":@computed_region_tm4z_r3je",
    ":@computed_region_tqy7_429i",
    ":@computed_region_qfmj_2fwi",
    ":@computed_region_9v63_zwfd",
    ":@computed_region_92rf_uvyc",
    ":@computed_region_hfgy_t898",
    ":@computed_region_8tu6_j4iw"
FROM
    "brla-gov/311-citizen-requests-for-service-7ixm-mnvx:latest"."311_citizen_requests_for_service"
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/311-citizen-requests-for-service-7ixm-mnvx 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/311-citizen-requests-for-service-7ixm-mnvx: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.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/311-citizen-requests-for-service-7ixm-mnvx" \
  --handler-options '{
    "domain": "data.brla.gov",
    "tables": {
        "311_citizen_requests_for_service": "7ixm-mnvx"
    }
}'

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/311-citizen-requests-for-service-7ixm-mnvx is just another Postgres schema.