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 lafd_response_metrics_raw_data
table in this repository, by referencing it like:
"lacity/lafd-response-metrics-raw-data-n44u-wxe4:latest"."lafd_response_metrics_raw_data"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"on_scene_time_gmt", -- *CAD captures the time when LAFD resources arrive at the scene of the incident when the corresponding key is pressed at the resource’s MDC. *It must be noted that the recording of En Route Time and On-Scene Time is an event-driven process that requires first-responder interaction. The precision of those time stamps depends on the timeliness of when the user manually activates the respective function key on the MDC (Mobile Data Computer).
"en_route_time_gmt", -- *CAD captures the time when LAFD resources leave quarters by storing the time in which the corresponding key is pressed at the resource’s Mobile Data Computer (MDC). *It must be noted that the recording of En Route Time and On-Scene Time is an event-driven process that requires first-responder interaction. The precision of those time stamps depends on the timeliness of when the user manually activates the respective function key on the MDC (Mobile Data Computer).
"time_of_dispatch_gmt", -- CAD automatically captures the time a fire station is notified and provided dispatch instructions via the LAFD’s Fire Station Alerting System. Notification is simultaneously made via FAX, DATA, and AUDIO to the responding unit(s).
"dispatch_status", -- The status of the responding unit at the time of dispatch. For example, status “QTR” means a unit responded from quarters, “RAD” means a unit responded from a radio call in and was not in quarters at the time, “AVI” means the unit is available, typically when released from an incident, and “ONS” means the unit is on-scene.
"dispatch_sequence", -- The number assigned to each resource in the order in which it is dispatched to the incident. There may be numbers that are skipped in the sequence. This is due to the vehicle being assigned to the incident but then removed before it is dispatched. The dynamic situation of an emergency call allows for additions or removal of resources as more information is gathered. There may also be duplicate numbers in the sequence. This is due to the merging of incidents, once it is discovered that there is more than one call received for the same incident.
"first_in_district", -- The location where the incident occurred in terms of a Fire Station district. The area where a particular fire station responds as well as where the incident occurred.
"randomized_incident_number", -- This is the incident number for the call that has had to be re-identified for the purposes of medical patient protection. LAFD is considered a medical service provider*. This number is generated with the year and quarter indicator with a six digits randomized number attached, i.e. – 201301345785, this number means it is in the year 2013 in the first quarter. *LAFD must therefore comply with the HIPAA law (Health Insurance Portability and Accountability Act of 1996). We can only release data which contains no ‘individually identifiable health information’, (IIHI), and therefore no ‘protected health information’, (PHI).
"incident_creation_time_gmt", -- The time when the call‐taker is presented with the call and takes charge of it, then creates an incident record in CAD. During this process, the call‐taker verifies the address information and interviews the caller to find out what the nature of the call.
"emergency_dispatch_code", -- Indicates whether an incident was categorized as emergency or non-emergency. This dataset contains information related to emergency incidents only.
"ppe_level", -- EMS category includes incident types that require minimum PPE* and a Turnout Time of 60 seconds. The majority of these incidents are medical in nature and do not require fire suppression tools and equipment to mediate. The NON-EMS category includes incidents that require full PPE* and a Turnout Time of 80 seconds. The majority of these incidents require fire suppression tools and equipment to mediate and may result in patients that require medical evaluation and treatment. *Personal Protective Equipment
"unit_type" -- The type of responding unit.
FROM
"lacity/lafd-response-metrics-raw-data-n44u-wxe4:latest"."lafd_response_metrics_raw_data"
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/lafd-response-metrics-raw-data-n44u-wxe4
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.lacity.org. When you querylacity/lafd-response-metrics-raw-data-n44u-wxe4: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 data.lacity.org, 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 \
"lacity/lafd-response-metrics-raw-data-n44u-wxe4" \
--handler-options '{
"domain": "data.lacity.org",
"tables": {
"lafd_response_metrics_raw_data": "n44u-wxe4"
}
}'
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, lacity/lafd-response-metrics-raw-data-n44u-wxe4
is just another Postgres schema.