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 business_establishments_per_clue_industry_for
table in this repository, by referencing it like:
"melbourne-vic-gov-au/business-establishments-per-clue-industry-for-c3gt-hrz6:latest"."business_establishments_per_clue_industry_for"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"health_care_and_social_assistance", -- Health Care and Social Assistance includes business providing human health care and social assistance.
"total_establishments_in_block", -- Total number of establishments in the block.
"wholesale_trade", -- Wholesale Trade engages in the purchase and on-selling to businesses.
"rental_and_hiring_services", -- Rental and Hiring Services engage in renting, hiring, or otherwise allowing the use of tangible or intangible assets.
"block_id", -- The Census area is divided into city blocks, each of which is identified by a unique block number. Blocks are primarily defined by major roads. There are around 606 blocks in the City of Melbourne.
"agriculture_and_mining", -- Agriculture, Forestry and Fishing includes business engaged in growing crops, raising animals, growing and harvesting timber, and harvesting fish and other animals from farms or their natural habitats. Mining includes business that extract naturally occurring mineral solids, such as coal and ores; liquid minerals, such as crude petroleum; and gases, such as natural gas.
"information_media_and_telecommunications", -- Health Care and Social Assistance includes business providing human health care and social assistance.
"transport_postal_and_storage", -- Transport, Postal and Warehousing includes business engaging in passenger transportation, freight and postal by road, rail, water or air. Also the provision of goods warehousing and storage.
"census_year", -- The CLUE census year refers to the year in which surveying was completed.
"clue_small_area", -- CLUE small areas are composed of a group of city blocks, each of which is identified by a unique block number.
"accommodation", -- Accommodation business provides short-term accommodation for visitors.
"admin_and_support_services", -- Administrative and Support Services includes business engaged in performing routine support activities for the day-to-day operations of other businesses or organisations.
"arts_and_recreation_services", -- Arts and Recreation Services includes business engaged in preservation/exhibition of object/sites of historical, cultural or educational interest; production of artistic works and/or live performances/events/exhibits for public viewing; and the operation of facilities that enable patrons to participate in sporting or recreational activities.
"business_services", -- Business Services provide professional, scientific and technical services where labour inputs are integral to the production or service delivery. These services include scientific research, architecture, engineering, computer systems design, law, accountancy, advertising, market research, management and other consultancy, veterinary science and professional photography.
"construction", -- Construction includes business engaged in the construction, repair or maintenance of buildings and other structures.
"education_and_training", -- Education and Training includes organisations in the provision and support of education and training.
"electricity_gas_water_and_waste_services", -- Electricity, Gas, Water and Waste Services comprises business engaged in the provision of electricity; gas through mains systems; water; drainage; and sewage services.
"finance_and_insurance", -- Financial and Insurance Services engage in financial transactions of financial assets and in facilitating financial transactions.
"food_and_beverage_services", -- Food service business provide food and beverage services, preparation and serving of meals on and off site.
"manufacturing", -- Manufacturing includes business mainly engaged in the physical or chemical transformation of materials, substances or components into new products (except agriculture and construction).
"other_services", -- Other Services includes a broad range of personal services; religious, civic, professional and other interest group services; selected repair and maintenance activities; and private households employing staff.
"public_administration_and_safety", -- Public Administration and Safety includes units mainly engaged in Central, State or Local Government legislative, executive and judicial activities.
"real_estate_services", -- Real estate services includes business engaged in providing real estate services such as selling, renting and/or buying real estate for others, managing real estate for others and appraising real estate.
"retail_trade" -- Retail Trade engages in the purchase and on-selling to the general public.
FROM
"melbourne-vic-gov-au/business-establishments-per-clue-industry-for-c3gt-hrz6:latest"."business_establishments_per_clue_industry_for"
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 melbourne-vic-gov-au/business-establishments-per-clue-industry-for-c3gt-hrz6
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.melbourne.vic.gov.au. When you querymelbourne-vic-gov-au/business-establishments-per-clue-industry-for-c3gt-hrz6: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.melbourne.vic.gov.au, 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 \
"melbourne-vic-gov-au/business-establishments-per-clue-industry-for-c3gt-hrz6" \
--handler-options '{
"domain": "data.melbourne.vic.gov.au",
"tables": {
"business_establishments_per_clue_industry_for": "c3gt-hrz6"
}
}'
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, melbourne-vic-gov-au/business-establishments-per-clue-industry-for-c3gt-hrz6
is just another Postgres schema.