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 city_employee_payroll_20132018
table in this repository, by referencing it like:
"controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym:latest"."city_employee_payroll_20132018"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"average_benefit_cost", -- The total average City contribution for the employee's health care, dental care and life insurance
"average_basic_life", -- Average cost to the City to provide basic life insurance to the employee
"average_dental_cost", -- Average cost to the City to provide dental care to the employee
"pay_grade", -- Pay Grade for the Job Class
"mou", -- Memorandum of Understanding
"pay_other_actual", -- Other Pay includes bonuses, adjustments, and lump sum payouts. Examples of bonuses include Permanent, Longevity, and Temporary Bonuses. Lump Sum Pay includes significant one-time payouts due to retirement, lawsuit settlements, or other adjustments
"temporary_bonus_pay", -- Payments attributable to temporary bonuses; typically not pensionable
"permanent_bonus_pay", -- Payments attributable to permanent bonuses; typically pensionable
"base_pay", -- Base compensation for hours worked
"percent_over_base_pay", -- Percentage of payment in excess of Base Pay which may include bonuses and other payouts
"q4_payments", -- Payments for the fourth quarter of the year from October 1 to December 31
"q2_payments", -- Payments for the second quarter of the year from April 1 to June 30
"projected_annual_salary", -- Budgeted pay amount. Used for pension contribution calculations
"hourly_or_event_rate", -- Hourly Earnings Rate or Per Event Rate based on Projected Annual Salary
"job_class_title",
"payroll_department", -- Department Number in City Payroll System
"job_class",
"fms_department", -- Department number in City Financial Management System
"lump_sum_pay", -- Lump sum payouts for special purposes - retirement payouts, back pay, etc.; typically not pensionable
"longevity_bonus_pay", -- Payments attributable to years of service; typically pensionable
"total_payments", -- Total earnings for the year
"q3_payments", -- Payments for the third quarter of the year from July 1 to September 30
"q1_payments", -- Payments for the first quarter of the year from January 1 to March 31
"record_number",
"department_title", -- Title of City Department
"row_id", -- Unique Identifier for each row
"benefits_plan",
"employment_type", -- Employment Type - Full Time, Part Time, or Per Event
"payments_over_base_pay", -- Payments in excess of Base Pay which may include bonuses and other payouts
"overtime_pay", -- Payments attributable to hours worked beyond regular work schedule
"other_pay_adjustments", -- Payments based on other pay codes or adjustments that do not fall into another category
"mou_title", -- Title of Memorandum of Understanding
"average_health_cost", -- Average cost to the City to provide health care to the employee
"year", -- Calendar Year
"job_class_link" -- Click this hyperlink to view the job class description
FROM
"controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym:latest"."city_employee_payroll_20132018"
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 controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym
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 controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym: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 controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym
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 controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym:latest
This will download all the objects for the latest
tag of controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym
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 controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym: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 controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym: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, controllerdata-lacity/city-employee-payroll-20132018-pazn-qyym
is just another Postgres schema.