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 lobbyist_employers_summary
table in this repository, by referencing it like:
"wa-gov/lobbyist-employers-summary-biux-xiwe:latest"."lobbyist_employers_summary"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"other_l3_exp", -- The aggregate of other lobbying-related expenditures, whether through or on behalf of a registered lobbyist. Does not include payments previously accounted for.
"year", -- The calendar year in which an employer hired a lobbyist.
"employer_country", -- The lobbyist employer's country.
"inform_material", -- Aggregate total for composing, designing, producing and distributing informational materials for use primarily to influence legislation.
"employer_city", -- The lobbyist employer's city.
"total_exp", -- This field is a calculated field adding the expenses reported by the employer. It combines the following columns: expenditures + agg_contrib + ballot_prop + entertain + vendor + expert_retain + inform_material + +lobbying_comm + ie_in_support + itemized_exp + other_l3_exp + political. NOTE: THE "CORR_EXPEND" FILED IS NOT USED IN THIS CALCULATION.
"entertain", -- Total of entertainment, tickets, passes, travel expenses (including transportation, meals, lodging, etc.) and enrollment or course fees provided to legislators, state officials, state employees and members of their immediate families.
"expert_retain", -- Aggregate total paid to or on behalf of expert witnesses or others retained to provide lobbying services who offer specialized knowledge or expertise that assists the employer’s lobbying effort.
"ballot_prop", -- Total of independent expenditures supporting or opposing statewide ballot measures.
"lobbying_comm", -- Aggregate total for grass roots lobbying expenses, including those previously reported by employer on Form L-6, and payments for lobbying communications to clients/customers (other than to corporate stockholders and members of an organization or union).
"employer_name", -- The employers registered name. The name will be consistent across all records for the same filer id and election year but may differ across years due to a lobbyist changing their name.
"employer_email", -- The lobbyist employer's email address.
"employer_state", -- The lobbyist employer's state.
"employer_address", -- The lobbyist employer's address.
"compensation", -- This column contains an aggregate of all compensation paid to all of an employer's lobbyists for a year. This is the compensation as reported by the lobbyists. When the employer is filing this report, it has the option to change this total if they don't agree. The new total is reflected in the "corr_compensation" column in this dataset. You must review the actual filing to determine the particulars.
"corr_expend", -- This column allows the employer to correct the expenses reported by the lobbyists. The lobbyist reports expenses incurred on behalf of an employer monthly. The sum of the amounts reported is provided to the employer for verification. If the employer disagrees with the aggregate amount reported by all their lobbyists, the corrected amount is placed in the column.
"employer_phone", -- The lobbyist employer's telephone number.
"agg_contrib", -- This is the aggregate total of all non-itemized contributions given by this employer for a specific year.
"id", -- PDC internal identifier that corresponds to a lobbyist employers unique filer id combined with the year of registration. For example an id of 17239-2017 represents a record for an employer whose filer id is 17239 for calendar year 2017.
"ie_in_support", -- Aggregate total of independent expenditures supporting or opposing a candidate for legislative or statewide executive office or a statewide ballot measure.
"itemized_exp", -- Aggregate total of any expenditures, not otherwise reported, made directly or indirectly to a state elected official, successful candidate for state office or member of their immediate family, if made to honor, influence or benefit the person because of his or her official position.
"expenditures", -- This column contains an aggregate of all expenses paid by all of an employer's lobbyists for a year. This is the total of expenses as reported by the lobbyists. When the employer is filing this report, it has the option to change this total if they don't agree. The new total is reflected in the "corr_expend" column in this dataset. You must review the actual filing to determine the particulars.
"corr_compensation", -- This column allows the employer to correct the compensation reported by the lobbyists. The lobbyist reports compensation from an employer monthly. The sum of the amounts reported is provided to the employer for verification. If the employer disagrees with the aggregate amount reported by all their lobbyists, the corrected amount is placed in the column.
"employer_zip", -- The lobbyist employer's zip code.
"political", -- The aggregate total of all itemized contributions made in a specific year.
"l3_nid", -- This number is the report number of the employers annual expense report.
"vendor", -- Aggregate total paid to vendors on behalf of or in support of registered lobbyists (e.g., entertainment credit card purchases).
"employer_nid" -- The unique identifier assigned to a lobbyist employer. This filer id is consistent across years.
FROM
"wa-gov/lobbyist-employers-summary-biux-xiwe:latest"."lobbyist_employers_summary"
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/lobbyist-employers-summary-biux-xiwe
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/lobbyist-employers-summary-biux-xiwe: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/lobbyist-employers-summary-biux-xiwe
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/lobbyist-employers-summary-biux-xiwe:latest
This will download all the objects for the latest
tag of wa-gov/lobbyist-employers-summary-biux-xiwe
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/lobbyist-employers-summary-biux-xiwe: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/lobbyist-employers-summary-biux-xiwe: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/lobbyist-employers-summary-biux-xiwe
is just another Postgres schema.