colorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t
Icon for Socrata external plugin

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

"colorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t:latest"."electricity_revenue_by_utility_in_us"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "totalprice", -- Price in cents per kilowatt hour for all consumers (calculated)
    "totalsales", -- Total electricity consumed by all sectors (megawatthours)
    "transcust", -- Transportation consumers.  Beginning with the 2003 data cycle this sector replaces “Other”.  Customer counts for the sales of power to electrified rail and urban transit systems whose primary propulsive energy source is electricity.
    "transsales", -- Transportation sales. Beginning with the 2003 data cycle this sector replaces “Other” (megawatthours). Sales of power to electrified rail and urban transit systems whose primary propulsive energy source is electricity.
    "transrev", -- Transportation revenue.  Beginning with the 2003 data cycle this sector replaces “Other” (thousand dollars). Revenues for the sales of power to electrified rail and urban transit systems whose primary propulsive energy source is electricity.
    "indrev", -- Revenues from industrial customers (in thousands of dollars. Industrial revenue is the billed amount including demand revenue, reactive demand charges (if applicable), high-voltage discounts (if applicable), etc. 
    "comprice", -- Price in cents per kilowatt hour for commercial consumers (calculated)
    "comcust", -- Number of commercial consumers (meters, or customer accounts).  Note: Each location in an aggregated account (as all restaurants in a chain) should be counted as a separate customer, if metered separately.
    "comrev", -- Revenues from commercial customers (in thousands of dollars). Commercial revenue is the billed amount including demand revenue.  
    "rescust", -- Number of residential consumers (meters, or customer accounts).  Note: Each residential customer in an aggregated account (as for a residential buying cooperative) should be counted as a separate customer, if metered separately.
    "resrev", -- Revenues from residential customers (in thousands of dollars). Residential revenue is the billed amount.  
    "bacode", -- Abbreviation for Balancing Authority. For a complete list, navigate to: https://www.eia.gov/conference/2015/pdf/presentations/kaplan.pdf
    "ownership", -- Ownership Type: One of  10 different types of ownership categories: Federal; Political Subdivision; Municipal Marketing Authority; Cooperative; State; Municipal; Investor-Owned; Retail Power Marketer (Energy Service Provider); (Wholesale) Power Marketer; and Unregulated. “State” ownership refers to statewide organizations whose scope is larger than county level.
    "utilityname", -- Name of the utility
    "comsales", -- Electricity sales to commercial customers (in megawatthours).
    "utilitynumber", -- ID number of utility (reporting entity) “99999” is not a utility ID; it represents an adjustment factor.
    "year", -- Year the data is recorded
    "totalcust", -- Total number of consumers in all sectors
    "totalrev", -- Total revenues of all sectors
    "indcust", -- Number of industrial consumers (meters, or customer accounts).  Note: Each facility is counted as one customer even if power is taken and metered at more than one point.
    "resprice", -- Price in cents per kilowatt hour for residential consumers (calculated)
    "transprice", -- Price in cents per kilowatt hour for transportation consumers (calculated)
    "indprice", -- Price in cents per kilowatt hour for industrial consumers (calculated)
    "indsales", -- Electricity sales to industrial customers (in megawatthours)  
    "ressales", -- Electricity sales to residential customers (in megawatthours). Residential sales is the billed amount.
    "part", -- A=Bundled Service, B=Energy Only Service, C=Delivery Only Service, D=TX Energy Service Providers
    "state", -- 2-digit State Code that the utility is primarily in
    "datatype", -- O=observed, I=imputed
    "servicetype" -- Provider Type. Designates electric service types as either Bundled (reported on Schedule 4 Part A or D), Energy (reported on Schedule 4 Part B) or Delivery (reported on Schedule 4 Part C).  Total revenue nationally includes all components.
FROM
    "colorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t:latest"."electricity_revenue_by_utility_in_us"
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 colorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.colorado.gov. When you querycolorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t: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

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 (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 cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.colorado.gov, 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 \
  "colorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t" \
  --handler-options '{
    "domain": "data.colorado.gov",
    "tables": {
        "electricity_revenue_by_utility_in_us": "ue5s-8u8t"
    }
}'

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, colorado-gov/electricity-revenue-by-utility-in-us-ue5s-8u8t is just another Postgres schema.