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
"difference_from_national_median_site_eui", -- % difference between building site EUI and national median site EUI for similar building use types.
"year_ending", -- The ending date for the year the data is collected.
":@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.
":@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.
"location_address",
"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.
"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.
"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.
"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.
"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.
"egrid_subregion", -- EPA identified eGrid subregion.
"location", -- Where the building is located. Most rows show street address, city, state, zip code, x-coordinate,y-coordinate.
"square_feet", -- Reported square feet for the building.
"primary_property_type", -- Main property type.
"year_built", -- Year built (some are estimated)
":@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.
"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.
"national_median_site_energy_use_kbtu", -- National median total site energy use. This can be used to compare to the local usage.
":@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.
"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.
"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.
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.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.kcmo.org. When you querykcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd: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.kcmo.org, 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 \
"kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd" \
--handler-options '{
"domain": "data.kcmo.org",
"tables": {
"energy_air_climate_impacts_of_cityowned_buildings": "r4r6-zpzd"
}
}'
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, kcmo/energy-air-climate-impacts-of-cityowned-buildings-r4r6-zpzd
is just another Postgres schema.