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 street_range
table in this repository, by referencing it like:
"brla-gov/street-range-fisq-xxsz:latest"."street_range"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"shoulder", -- Side(s) of the street segment with a shoulder
"parity_right", -- Description of the block range on the right side of the street segment (E = even, O = odd, and Z = no range)
"the_geom", -- Line geometry of the street range segment
"st_name_id", -- Street name ID
"st_type", -- Type of street
"from_elevation_level", -- Street segment runs from elevation level (0-1)
"road_class", -- Class of road
"zip_code_left", -- ZIP code on the left side of the street segment
"speed_mph", -- Speed limit of the street segment (miles per hour)
"parish_name_right", -- Parish on the right side of the street segment
"number_lanes",
"to_add_left", -- Street segment runs to this address at the left
"from_add_right", -- Street segment runs from this address at the right
"restricted_access", -- Access restriction (Yes or No)
"one_way_direction", -- Direction of the one-way street segment (if applicable)
"to_elevation_level", -- Street segment runs from elevation level (0-1)
"subdivision", -- Subdivision where the road segment is (if applicable)
"postal_community_left", -- Postal community on the left side of the street segment
"zip_code_right", -- ZIP code on the right side of the street segment
"community_right", -- Community on the right side of the street segment
"state_route_type", -- State route type (if applicable)
"alt_state_route_type", -- Alternate state route type (if applicable)
"private_street", -- Street segment is on a private street (Yes or No)
"st_directional", -- Street direction
"created_date", -- Date the street segment was created (if applicable)
"cad_ftc", -- Census FCC
"alt_state_route", -- Alternate state route (if applicable)
"parity_left", -- Description of the block range on the left side of the street segment (E = even, O = odd, and Z = no range)
"one_way", -- Pattern of traffic relative to direction of street segment digitization. (B = traffic runs both directions, F = traffic runs same direction as digitization, T = traffic runs opposite direction as digitization). Most centerlines are digitized south to north, or west to east.
"road_type", -- Type of road
"truck_route", -- Street segment is a truck route (Yes or No)
"priority_to_keep_open", -- Priority to keep this street segment open
"notation", -- Additional notes regarding this street segment (if applicable)
"st_segment_id", -- Street segment ID
"street_name_complete", -- Street name
"jurisdiction", -- Jurisdiction where the road segment is (if applicable)
"postal_community_right", -- Postal community on the right side of the street segment
"curb", -- Side(s) of the street segment with a curb and gutter
"street_incept_date", -- Date the street segment was established
"st_elevation_level", -- Street elevation level (0-3)
"st_begin_meas_sf", -- Louisiana DOTD linear referencing system (LRS) begin measurement (in feet)
"st_end_meas_sf", -- Louisiana DOTD linear referencing system (LRS) end measurement (in feet)
"parish_name_left", -- Parish on the left side of the street segment
"modified_date", -- Date the street segment was last edited (if applicable)
"community_left", -- Community on the left side of the street segment
"drainage_maint_responsibility", -- Drainage maintenance responsibility for the street segment
"federal_route", -- Federal route (if applicable)
"federal_route_type", -- Federal route type (if applicable)
"emergency_funding", -- Emergency funding for the street segment (if applicable)
"from_add_left", -- Street segment runs from this address at the left
"to_add_right", -- Street segment runs to this address at the right
"st_owner", -- Owner of the street segment
"alt_federal_route", -- Alternate federal route (if applicable)
"alt_federal_route_type", -- Alternate federal route type (if applicable)
"state_route", -- State route (if applicable)
"data_source", -- Source of the data
"lrs_id", -- Louisiana DOTD linear referencing system (LRS) identication number
"st_segment_num" -- Street segment number
FROM
"brla-gov/street-range-fisq-xxsz:latest"."street_range"
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 brla-gov/street-range-fisq-xxsz
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 brla-gov/street-range-fisq-xxsz: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 brla-gov/street-range-fisq-xxsz
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 brla-gov/street-range-fisq-xxsz:latest
This will download all the objects for the latest
tag of brla-gov/street-range-fisq-xxsz
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 brla-gov/street-range-fisq-xxsz: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 brla-gov/street-range-fisq-xxsz: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, brla-gov/street-range-fisq-xxsz
is just another Postgres schema.