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 public_agency_lobbying_totals
table in this repository, by referencing it like:
"wa-gov/public-agency-lobbying-totals-mjwb-szba:latest"."public_agency_lobbying_totals"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"id", -- The PDC internal identifier that corresponds to a Public Agency's name combined with the year the lobbying occurred.
"filer_id", -- The unique id assigned to a Public Agency who is registered to electronically file the L5 report. Mandatory electronic filing is only required by state agencies, therefore other types of agencies may file on paper. If an agency files on paper they may not have a filer id. The filer_id is consistent across years.
"name", -- The Public Agency's name as registered. The name will be consistent across all records for the same filer id and election year but may differ across years due to an agency changing their name.
"address", -- The address of the agency as registered.
"city", -- The city where the agency is located.
"state", -- The state where the agency is located.
"zip_code", -- The zip code of the agency.
"contact", -- The Point of Contact for the agency. This is normally the person who registered the agency and who files the L5 reports.
"email_address", -- The e-mail address of the Point of Contact.
"phone", -- The telephone number of the Point of Contact.
"year", -- The L5 report is a quarterly report. Up to four L5s are reported in a calendar year. An L5 is not required for a quarter if there was no lobbying. Each row represents a row for one agency with four quarterly reports for one calendar year.
"q1_report_num", -- This is the report number for the quarter 1 L5 that was electronically filed. Paper filed L5s do not have report numbers.
"q1", -- This column shows the total expenditures for quarter 1. If the column is blank, either no L5 was submitted, or a report was originally filed but is in a holding state for amending and the data is unavailable.
"q2_report_num", -- This is the report number for the quarter 2 L5 that was electronically filed. Paper filed L5s do not have report numbers.
"q2", -- This column shows the total expenditures for quarter 2. If the column is blank, either no L5 was submitted, or a report was originally filed but is in a holding state for amending and the data is unavailable.
"q3_report_num", -- This is the report number for the quarter 3 L5 that was electronically filed. Paper filed L5s do not have report numbers..
"q3", -- This column shows the total expenditures for quarter . If the column is blank, either no L5 was submitted, or a report was originally filed but is in a holding state for amending and the data is unavailable.
"q4_report_num", -- This is the report number for the quarter 4 L5 that was electronically filed. Paper filed L5s do not have report numbers.
"q4", -- This column shows the total expenditures for quarter 4. If the column is blank, either no L5 was submitted, or a report was originally filed but is in a holding state for amending and the data is unavailable.
"year_total", -- The yearly total is a calculated field adding Q1 + Q2 + Q3 + Q4
"q1_url", -- This field allows you to view an image of the electronically filed L5 for quarter 1. If the field is blank, the L5 was filed on paper and is not available for viewing.
"q2_url", -- This field allows you to view an image of the electronically filed L5 for quarter 2. If the field is blank, the L5 was filed on paper and is not available for viewing.
"q3_url", -- This field allows you to view an image of the electronically filed L5 for quarter 3. If the field is blank, the L5 was filed on paper and is not available for viewing.
"q4_url" -- This field allows you to view an image of the electronically filed L5 for quarter 4. If the field is blank, the L5 was filed on paper and is not available for viewing.
FROM
"wa-gov/public-agency-lobbying-totals-mjwb-szba:latest"."public_agency_lobbying_totals"
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 wa-gov/public-agency-lobbying-totals-mjwb-szba
with SQL in under 60 seconds.
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, 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 clone
and sgr checkout
.
Cloning Data
Because wa-gov/public-agency-lobbying-totals-mjwb-szba: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 wa-gov/public-agency-lobbying-totals-mjwb-szba
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 wa-gov/public-agency-lobbying-totals-mjwb-szba:latest
This will download all the objects for the latest
tag of wa-gov/public-agency-lobbying-totals-mjwb-szba
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 wa-gov/public-agency-lobbying-totals-mjwb-szba: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 wa-gov/public-agency-lobbying-totals-mjwb-szba: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, wa-gov/public-agency-lobbying-totals-mjwb-szba
is just another Postgres schema.