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 energy_air_climate_impacts_of_cityowned_buildings
table in this repository, by referencing it like:
"kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd:latest"."energy_air_climate_impacts_of_cityowned_buildings"
or in a full query, like:
SELECT
":id", -- Socrata column ID
":@computed_region_my34_vmp8", -- This column was automatically created in order to record in what polygon from the dataset 'County Boundary' (my34-vmp8) the point in column 'location' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"indirect_ghg_emissions_intensity_kgco2e_ft", -- Indirect Emissions are emissions associated with purchases of electricity, district steam, district hot water, or district chilled water. These emissions occur at the utility’s plant, but they are a result of the property’s energy consumption and therefore contribute to the overall GHG footprint. This number is per building square foot.
"location_address",
":@computed_region_kk66_ngf4", -- This column was automatically created in order to record in what polygon from the dataset 'Neighborhood Census' (kk66-ngf4) the point in column 'location' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_w4hf_t6bp", -- This column was automatically created in order to record in what polygon from the dataset 'Zip Codes' (w4hf-t6bp) the point in column 'location' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_9t2m_phkm", -- This column was automatically created in order to record in what polygon from the dataset 'Council Districts' (9t2m-phkm) the point in column 'location' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"year_ending", -- The ending date for the year the data is collected.
"site_eui_kbtu_ft", -- Site energy use per square foot.
"national_median_site_eui_kbtu_ft", -- National median site energy use per square foot. This can be used to compare to the local usage.
"egrid_output_emissions_rate_kgco2e_mbtu", -- The Electric Emissions Rate conveys the amount of carbon dioxide equivalent (CO2e) emissions associated with the electricity consumption, in kilograms per MBtu. Note that the electric emissions rate depends on where your property is located, EPA uses the average electricity production output emission rate of the electricity grid serving the property, as defined by the Emissions & Generation Resource Integrated Database (eGRID).
"location_state",
"location_city",
"location_zip",
"kansas_city_building_reporting_id", -- Benchmarking ID created by the City of Kansas City Missouri to identify covered buildings.
"property_name", -- Sefl-selected name for the property.
"zip_code", -- Zip Code for property.
"parent_property_name", -- Used for buildings that are part of a campus. This is the name of the main property.
"all_property_use_types", -- All use types associated with the property.
"site_energy_use_kbtu", -- Total site energy use for the year. Site Energy is the annual amount of all the energy the property consumes onsite, as reported on your utility bills.
"weather_normalized_site_energy_use_kbtu", -- The site energy use the property would have consumed during 30-year average weather conditions.
"difference_from_national_median_site_eui", -- % difference between building site EUI and national median site EUI for similar building use types.
"national_median_site_energy_use_kbtu", -- National median total site energy use. This can be used to compare to the local usage.
"energy_star_score", -- This score is used to rate buildings on a scale of 1-100. The score indicates the energy efficiency percentile the building is in relation to similar properties. Not all building types are eligible.
"year_built", -- Year built (some are estimated)
"primary_property_type", -- Main property type.
"square_feet", -- Reported square feet for the building.
"weather_normalized_source_eui_kbtu_ft", -- The source energy use per square foot the property would have consumed during 30-year average weather conditions.
"energy_cost_intensity_ft", -- Cost per square foot for the year the data was collected.
"direct_ghg_emissions_metric_tons_co2e", -- Direct Emissions are emissions associated with onsite fuel combustion (e.g. combustion of natural gas or fuel oil).
"direct_ghg_emissions_intensity_kgco2e_ft", -- Direct Emissions are emissions associated with onsite fuel combustion (e.g. combustion of natural gas or fuel oil). This amount is per building square foot.
"egrid_subregion", -- EPA identified eGrid subregion.
"indirect_ghg_emissions_metric_tons_co2e", -- Indirect Emissions are emissions associated with purchases of electricity, district steam, district hot water, or district chilled water. These emissions occur at the utility’s plant, but they are a result of the property’s energy consumption and therefore contribute to the overall GHG footprint.
"water_use_kgal", -- Total Water Use for the year the data was collected.
"energy_cost", -- Total energy cost for the year the data was collected.
"weather_normalized_source_energy_use_kbtu", -- The source energy use the property would have consumed during 30-year average weather conditions.
"weather_normalized_site_eui_kbtu_ft", -- The site energy use per square foot the property would have consumed during 30-year average weather conditions.
"difference_from_national_median_source_eui", -- % difference per square foot between the building and the national median.
"national_median_source_eui_kbtu_ft", -- National median Source EUI per square foot.
"national_median_source_energy_use_kbtu", -- National Median for Source Energy Use.
"source_eui_kbtu_ft", -- Source Energy Use is the total amount of raw fuel that is required to operate the property. In addition to what the property consumes on-site, source energy includes losses that take place during generation, transmission, and distribution of the energy. This number represents per square foot.
"source_energy_use_kbtu", -- Source Energy Use is the total amount of raw fuel that is required to operate the property. In addition to what the property consumes on-site, source energy includes losses that take place during generation, transmission, and distribution of the energy.
"location" -- Where the building is located. Most rows show street address, city, state, zip code, x-coordinate,y-coordinate.
FROM
"kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd:latest"."energy_air_climate_impacts_of_cityowned_buildings"
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 kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd
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 kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd: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 kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd
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 kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd:latest
This will download all the objects for the latest
tag of kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd
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 kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd: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 kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd: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, kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd
is just another Postgres schema.