calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue
Loading...

Query the Data Delivery Network

Query the DDN

The 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 citizen_satisfaction_survey_20162017 table in this repository, by referencing it like:

"calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue:latest"."citizen_satisfaction_survey_20162017"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "q12", -- Increase taxes vs cut services (1-4)
    "q24bx_6", -- Calgary is a great place to make a living (1-10)
    "q19_8", -- The City used input from Calgarians in decision-making about City projects and services (0-3)
    "q39", -- Household income category
    "q37", -- Years in Calgary
    "q19_4", -- City staff are easy to get a hold of when I need them (0-3)
    "q38", -- Highest level of education
    "q24bx_2", -- The City of Calgary, municipal government, fosters a city that is inclusive and accepting of all (1-10)
    "q24bx_5", -- I am regularly involved in neighbourhood and local community events (1-10)
    "q11a", -- Please rate the value you feel you receive from your municipal property tax dollars (1-10)
    "uid",
    "q19_1", -- The quality of customer service from the city is consistently high (0-3)
    "q34", -- Household tenancy
    "q10", -- How safe do you feel or would you feel walking alone in your neighborhood after dark? (1-4)
    "qwave", -- Year of survey
    "q2a", -- Overall quality of life (1-10)
    "q30", -- Age
    "q32x", -- Children in household
    "q3", -- Change in quality of life (Improved/Stayed the same/Worsened)
    "q24bx_3", -- I am proud to be a Calgarian (1-10)
    "mweight0", -- Survey weight
    "s4qt", -- Quadrant of Calgary (1 = Southwest; 2 = Southeast; 3 = Northwest; 4 = Northeast; 5 = Don't Know)
    "market2", -- City of Calgary Ward
    "q24bx_4", -- I am proud to live in my neighbourhood (1-10)
    "q19_3", -- City staff are courteous, helpful, and knowledgeable (0-3)
    "q24bx_7", -- Calgary is a great place to make a life (1-10)
    "q19_5", -- The City of Calgary practices open and accessible government (0-3)
    "q19_6", -- The City of Calgary makes customer service a priority (0-3)
    "q19_7", -- The City allows citizen to have meaningful input into decision-making (0-3)
    "q24cx", -- Calgary is on the right track to be a better city 10 years from now (1-4)
    "q19_2", -- The city responds quickly to requests and concerns (0-3)
    "q40", -- Member of a visible minority
    "sexfix", -- Gender
    "q24bx_1" -- Calgary is moving in the right direction to ensure a high quality of life for future generations (1-10)
FROM
    "calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue:latest"."citizen_satisfaction_survey_20162017"
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 calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue with SQL in under 60 seconds.

Query Your Local Engine

Install Splitgraph Locally
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; sgrcan 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 cloneand sgr checkout.

Cloning Data

Because calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue: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 calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue

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 calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue:latest

This will download all the objects for the latest tag of calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue 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 calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue: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 calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue: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, calgary-ca/citizen-satisfaction-survey-20162017-kgh7-mhue is just another Postgres schema.

Related Documentation:

Loading...