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 quarterly_census_of_employment_and_wages_qcew
table in this repository, by referencing it like:
"ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb:latest"."quarterly_census_of_employment_and_wages_qcew"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"county", -- County name
"county_fips", -- Each county in New York State has been assigned a numeric "FIPS" code by the Federal Government. These codes are used as the identifiers for the counties in this data set. Their meanings are listed below. Employees working in New York State, who cannot be classified as working in any one county, or who are working at sites that have not yet been classified, or are unknown, are reported in the classification, "Statewide." Also included in this classification are New York State residents employed overseas or out-of-state but electing to be covered by New York State Unemployment Insurance. Total employment in this classification generally numbers approximately 100,000 (approximately 1.25 percent of the total number of workers covered by New York State's Unemployment Insurance). Data users with access to New York State-specific files will find that these county codes differ from those used "in-house" by the New York State Department of Labor. See Data File Layout PDF in the 'About' tab for a translation of the county FIPS numbers.
"state_fips", -- The New York State "FIPS" identifier (36) is embedded in the file for those who wish to merge multi-state data sets. Federal information processing standards codes (FIPS codes) are a standardized set of numeric or alphabetic codes issued by the National Institute of Standards and Technology (NIST) to ensure uniform identification of geographic entities through all federal government agencies.
"average_weekly_wages", -- The average weekly wage is computed by dividing the total wages for the year by the average monthly employment, and then dividing the result by 52.
"average_employment", -- The average employment is the summed monthly employment, as reported in the ES-202/QCEW, divided by 12.
"year", -- The year is represented by all four digits
"industry_title", -- The title associated with the Industry Code. 00 = All Industries; 01 = Agriculture, Mining & Unclassified; 02 = Agriculture, Mining, Construction & Unclassified; 03 = Construction; 04 = Manufacturing; 05 = Transportation & Public Utilities; 06 = Wholesale Trade; 07 = Retail Trade; 08 = Finance, Insurance & Real Estate; 09 = Services; 10 = Public Administration
"average_annual_wages", -- The average wage is the average yearly wage paid to the employees of all the reporting units for the industry division and county as reported in the ES-202/QCEW. It is computed by dividing the total wages for the year by the average monthly employment.
"total_wages", -- Total wages is the sum of all remunerations reported by all the reporting units in the ES-202/QCEW for the year.
"industry", -- The industry code designates the division level of Standard Industrial Classification (SIC). The source for this classification is the "Standard Industrial Classification Manual, 1987," published by the U.S. Office of Management and Budget. The codes assigned to the industry divisions in the data set should not be confused with the "first digit" of the SIC code. Section 537 of the Labor Law requires that information provided by individual employers be kept confidential. Due to this confidentiality requirement, certain industry divisions have been consolidated in this data set. For the majority of the counties in the state, consolidating "Agriculture, Forestry and Fishing" with "Mining" and "Unclassified" yielded employment totals, which could be disclosed, to the public without jeopardizing the confidentiality of individual employer data. However, in a few counties further consolidation was required to obtain a disclosable total. For these counties, a different grouping included "Construction" with "Agriculture," "Mining" and the "Unclassified" group to obtain a releasable total. Therefore, the data sets for most counties have industry 01 but no industry 02. Industry 02 is the grouping for the special cases that required further consolidation. Users should not be alarmed to find that most of the counties have no industry 02.
"reporting_units" -- The reporting unit is the economic unit for which data are submitted on the employer's unemployment insurance contribution report, or on a multiple worksite report. The reporting unit is often (though not always) synonymous with the terms "worksite" and "establishment."
FROM
"ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb:latest"."quarterly_census_of_employment_and_wages_qcew"
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 ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb
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 ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb: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 ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb
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 ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb:latest
This will download all the objects for the latest
tag of ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb
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 ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb: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 ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb: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, ny-gov/quarterly-census-of-employment-and-wages-qcew-ej35-turb
is just another Postgres schema.