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 financial_affairs_disclosures
table in this repository, by referencing it like:
"wa-gov/financial-affairs-disclosures-ehbc-shxw:latest"."financial_affairs_disclosures"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"certification_name", -- The name of the person that certified the submission of the financial affairs disclosure. This may not be the name of the person required to file in the case where someone else has the authority to file on behalf of them.
"offices", -- A machine consumable representation of the offices that the filer held during the period of this financial affairs disclosure statement.
"period_start", -- The starting date of the reporting period for the financial disclosure.
"submission_id", -- Internal PDC identifier used for tracking a unique revision (submission) of a financial affairs disclosure. When a financial affairs disclosure is amended, the amendment receives a new id.
"json", -- A machine consumable representation of the data submitted to file the financial affairs disclosure. For any records covering reporting period prior to 2019, this field will be empty. This field may also be empty when the statement has been redacted. This may happen when the commission has granted a retroactive reporting modification.
"report_number", -- The legacy report number for financial affairs disclosures due prior to January 1, 2020.
"history", -- This column include a history of all reports related to a financial affairs disclosure submission and subsequent amendments.
"candidacies", -- A machine consumable representation of the candidacies that the filer declared during the period of this financial affairs disclosure statement.
"url", -- A link to view the financial affairs disclosure or a link providing information on how to request the record when it is not available online. Generally, any financial affairs disclosures due prior to January 1, 2020 are not available online.
"id", -- Unique identifier for a financial affairs disclosure for a person, for a single reporting period. When a financial affairs disclosure is amended, the id will stay the same.
"name", -- The name of the person for whom the financial affairs disclosure was filed.
"filer_id", -- Legacy unique id assigned to a candidate. The filer id is consistent across election years with the exception that an individual running for a second office in the same election year will receive a second filer id. There is no correlation between the two. For non-candidate submissions, this value can be used to correlate legacy records with newer records bit the person_id should be preferred because it is consistent even for filers running for multiple offices in the same year.
"person_id", -- The unique ID assigned to a public office holder or candidate. This id is consistent across years and, offices or candidacies and is the preferred id for grouping submissions by person.
"receipt_date", -- The date the financial affairs disclosure was first received. The date received will be the date the disclosure was first received, even if the disclosure is later amended.
"certification_email", -- The email address of the person that certified the submission of the financial affairs disclosure. This may not be the name of the person required to file in the case where someone else has the authority to file on behalf of them.
"certification_phone", -- The phone number provided during certification
"certification", -- The statement that was certified at the time of submittal. Records that were submitted prior to January, 2020 do not have this value
"period_end" -- The ending date of the reporting period for the financial disclosure.
FROM
"wa-gov/financial-affairs-disclosures-ehbc-shxw:latest"."financial_affairs_disclosures"
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/financial-affairs-disclosures-ehbc-shxw
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.wa.gov. When you querywa-gov/financial-affairs-disclosures-ehbc-shxw: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.wa.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 \
"wa-gov/financial-affairs-disclosures-ehbc-shxw" \
--handler-options '{
"domain": "data.wa.gov",
"tables": {
"financial_affairs_disclosures": "ehbc-shxw"
}
}'
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, wa-gov/financial-affairs-disclosures-ehbc-shxw
is just another Postgres schema.