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 ams_pasadena_main_data
table in this repository, by referencing it like:
"datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn:latest"."ams_pasadena_main_data"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"delay_over_the_station_length_55_mph", -- This field contains the average delay over the station length with respect to a threshold speed of 55 mph.
"_5_minute_occupancies_for_lane_8", -- This field contains the average of 5-minute occupancies for lane 8 over the hour. The values are reported in percent.
"_5_minute_flows_for_lane_8", -- This field contains the sum of 5-minute flows for lane 8 over the hour. The values are reported in vehicles per hour.
"_5_minute_speeds_for_lane_7", -- This field contains the flow-weighted average of 5-minute lane 7 speeds. The values are reported in miles per hour.
"_5_minute_flows_for_lane_7", -- This field contains the sum of 5-minute flows for lane 7 over the hour. The values are reported in vehicles per hour.
"_5_minute_speeds_for_lane_6", -- This field contains the flow-weighted average of 5-minute lane 6 speeds. The values are reported in miles per hour.
"_5_minute_flows_for_lane_6", -- This field contains the sum of 5-minute flows for lane 6 over the hour. The values are reported in vehicles per hour.
"_5_minute_speeds_for_lane_5", -- This field contains the flow-weighted average of 5-minute lane N speeds. The values are reported in miles per hour.
"_5_minute_flows_for_lane_5", -- This field contains the sum of 5-minute flows for lane 5 over the hour. The values are reported in vehicles per hour.
"_5_minute_speeds_for_lane_4", -- This field contains the flow-weighted average of 5-minute lane 4 speeds. The values are reported in miles per hour.
"_5_minute_flows_for_lane_4", -- This field contains the sum of 5-minute flows for lane N over the hour. The values are reported in vehicles per hour.
"_5_minute_flows_for_lane_2", -- This field contains the sum of 5-minute flows for lane 2 over the hour. The values are reported in vehicles per hour.
"_5_minute_speeds_lane_1", -- This field contains the flow-weighted average of 5-minute lane 1 speeds. The values are reported in miles per hour.
"_5_minute_occupancy_for_lane_1", -- This field contains the average of 5-minute occupancies for lane 1 over the hour. The values are reported in percent.
"delay_over_the_station_length_50_mph", -- This field contains the average delay over the station length with respect to a threshold speed of 50 mph.
"delay_over_the_station_length_40mph", -- This field contains the average delay over the station length with respect to a threshold speed of 40 mph.
"this_field_contains_the_segment_length_covered_by_the_station_r", -- This field contains the segment length covered by the station reported in miles.
"route_number", -- This field contains the state or interstate route number where the dataset was reported.
"date", -- This field contains the date and time stamp when the associated dataset was reported.
"_5_minute_occupancies_for_lane_5", -- This field contains the average of 5-minute occupancies for lane 5 over the hour. The values are reported in percent.
"_5_minute_occupancies_for_lane_4", -- This field contains the average of 5-minute occupancies for lane 4 over the hour. The values are reported in percent.
"_5_minute_speeds_lane_3", -- This field contains the flow-weighted average of 5-minute lane 3 speeds. The values are reported in miles per hour.
"_5_minute_occupancy_for_lane_3", -- This field contains the average of 5-minute occupancies for lane 3 over the hour. The values are reported in percent.
"_5_minute_speeds_lane_2", -- This field contains the flow-weighted average of 5-minute lane 2 speeds. The values are reported in miles per hour.
"_5_minute_flows_for_lane_1", -- This field contains the sum of 5-minute flows for lane 1 over the hour. The values are reported in vehicles per hour.
"delay_over_the_station_length_60_mph", -- This field contains the average delay over the station length with respect to a threshold speed of 60 mph.
"_5_minute_station_speed", -- This field contains the flow-weighted average of 5-minute station speeds. Values are reported in miles per hour.
"_5_minute_station_occupancy", -- This field contains the average of 5-minute station occupancies over the hour expressed as a decimal number between 0 and 1.
"_5_minute_vehicle_flow", -- This field contains the sum of 5-minute vehicle flow over the hour.
"_5_minute_lanes_point", -- This field contains the 5-minute lane points that were observed.
"station_report_id", -- This field contains the unique numerical identification for the station reporting the dataset.
"_5_minute_speeds_for_lane_8", -- This field contains the flow-weighted average of 5-minute lane 8 speeds. The values are reported in miles per hour.
"engineering_district_number", -- This field contains the engineering district number within California where the dataset was reported.
"direction_of_travel", -- This field contains the direction of travel on the facility where the dataset was reported.
"type_of_facility", -- This field contains the lane type of the facility where the dataset was reported.
"_5_minute_occupancies_for_lane_7", -- This field contains the average of 5-minute occupancies for lane 7 over the hour. The values are reported in percent.
"delay_over_the_station_length_45mph", -- This field contains the average delay over the station length with respect to a threshold speed of 45 mph.
"_5_minute_occupancy_for_lane_2", -- This field contains the average of 5-minute occupancies for lane 2 over the hour. The values are reported in percent.
"number_of_samples", -- This field contains the total number of samples received for all lanes.
"delay_over_the_station_length_35mph", -- This field contains the average delay over the station length with respect to a threshold speed of 35 mph.
"_5_minute_flows_for_lane_3", -- This field contains the sum of 5-minute flows for lane 3 over the hour. The values are reported in vehicles per hour.
"_5_minute_occupancies_for_lane_6" -- This field contains the average of 5-minute occupancies for lane 6 over the hour. The values are reported in percent.
FROM
"datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn:latest"."ams_pasadena_main_data"
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 datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn
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 datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn: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 datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn
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 datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn:latest
This will download all the objects for the latest
tag of datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn
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 datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn: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 datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn: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, datahub-transportation-gov/ams-pasadena-main-data-a79b-e3wn
is just another Postgres schema.