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 massachusetts_department_of_transportation_massdot
table in this repository, by referencing it like:
"datahub-transportation-gov/massachusetts-department-of-transportation-massdot-6m7q-g56h:latest"."massachusetts_department_of_transportation_massdot"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"relationship_parents", -- Array of IDs indicating entities that the road event with this relationship is a part of, such as a work zone project or phase.
"relationship_first", -- Array of IDs indicating the first (can be multiple) road event in a sequence of road events by road_event_id.
"creation_date", -- The UTC time and date when the activity or event was created.
"total_num_lanes", -- The total number of lanes associated with the road event. This field has been deprecated as of WZDx v3.1.
"event_status", -- The status of the event.
"end_date_accuracy", -- A measure of how accurate the end Date Time is.
"start_date_accuracy", -- A measure of how accurate the start Date Time is.
"end_date", -- The UTC time and date when the event ends.
"start_date", -- The UTC time and date when the event begins.
"ending_milepost", -- The linear distance measured against a milepost marker along a roadway where the event ends.
"beginning_milepost", -- The linear distance measured against a milepost marker along a roadway where the event begins.
"ending_cross_street", -- Name or number of the nearest cross street along the roadway where the event ends.
"beginning_cross_street", -- Name or number of the nearest cross street along the roadway where the event begins.
"direction", -- The digitization direction of the road that is impacted by the event. This value is based on the standard naming for US roadways and indicates the direction the traffic flow regardless of the real heading angle.
"feed_update_date", -- The UTC date and time when the data feed was last updated.
"feed_bbox", -- GeoJSON Bounding Box on the coordinate range for the WZDxFeed FeatureCollection.
"data_source_lrs_url", -- A URL where additional information on the LRS information and transformation information is stored.
"data_source_update_frequency", -- The frequency in seconds at which the data source is updated.
"road_event_feed_info_update_1", -- The frequency in seconds at which the data feed is updated.
"geometry_multipoint", -- A coordinate pair or an array of coordinates. In either case, the first coordinate is the beginning point and the last coordinate is the ending point of the road event. Multi-Point
"geometry_linestring", -- A coordinate pair or an array of coordinates. In either case, the first coordinate is the beginning point and the last coordinate is the ending point of the road event.
"description", -- Short free text description of road event.
"restrictions", -- One or more road restrictions applying to the work zone road segment associated with the work zone delimited by semicolons.
"reduced_speed_limit", -- The reduced speed limit posted within the event space.
"workers_present", -- A flag indicating that there are workers present in the event space.
"road_event_bbox", -- GeoJSON Bounding Box on the coordinate range for the RoadEventFeature Feature.
"data_source_location_method", -- The typical method used to locate the beginning and end of a work zone impact area.
"road_event_feed_info_contact", -- The name of the individual or group responsible for the data feed.
"lanes", -- Stringified array of JSON objects identifying and describing individual lanes within a road event. Each lane JSON object can contain the following fields: “order” - The position of a lane in sequence on the roadway. This value is used as an index to indicate the order of all WZDx lanes provided for a road event; “type” - an indication of the type of lane or shoulder.); “status” - status of the lane for the traveling public; “lane_number” - the number assigned to the lane to help identify its position. Flexible, but usually used for regular, driveable lanes; “restrictions” - an array of lane_restriction JSON objects. Each lane_restriction JSON object contain the following fields: “restriction_type” - the type of restriction being enforced; “restriction_value” - the measure of the restriction type; “restriction_units” - units of measure for the restriction value. The “restriction_type” field of the lane_restriction JSON object is required. The “order”, “type”, and “status” fields of the lane JSON object are required.
"types_of_work", -- Stringified array of JSON objects indicating the type of work being done in a road event, if applicable (e.g. typical work zones), as well as noting if the type of work will result in an architectural change to the roadway. Each JSON object can contain the following fields: “type_of_work_id” - ID identifying the types_of_work record; “type_name” - a high-level text description of the type of work being done; “is_architectural_change” - an optional boolean flag indicating whether the type of work will result in an architectural change to the roadway.
"event_type", -- The type/classification of road event.
"data_source_id", -- Unique identifier for the organization providing work zone data.
"road_event_feed_info_contact_1", -- The email address of the individual or group responsible for the data feed.
"road_event_feed_info_publisher", -- The organization responsible for publishing the feed.
"relationship_next", -- Array of IDs indicating the next (can be multiple) road event in a sequence by road_event_id.
"update_date", -- The UTC time and date when the activity or event was updated.
"ending_accuracy", -- Indicates how the ending coordinate was defined.
"road_event_id", -- A unique identifier issued by the data feed provider to identify the work zone project or activity.
"road_event_feed_info_version", -- The WZDx specification version used to create the data feed in major.minor format.
"data_source_lrs_type", -- Describes the type of linear referencing system (LRS) used for the milepost measurements.
"data_source_location_verify", -- The method used to verify the accuracy of the location information.
"data_source_update_date", -- The UTC date and time when the data source was last updated.
"data_source_contact_email", -- The email address of the individual or group responsible for the data source.
"data_source_contact_name", -- The name of the individual or group responsible for the work zone data source.
"data_source_organization", -- The name of the organization for the authoritative source of the work zone data.
"relationship_children", -- Arrays of IDs indicating entities that are part of the road event with this relationship, such as a detour or piece of equipment.
"road_names", -- A list of publicly known names of the road on which the event occurs. This may include the road number designated by a jurisdiction such as a county, state or interstate (e.g. I-5, VT 133)
"beginning_accuracy", -- Indicates how the beginning coordinate was defined.
"vehicle_impact" -- The impact to vehicular lanes along a single road in a single direction.
FROM
"datahub-transportation-gov/massachusetts-department-of-transportation-massdot-6m7q-g56h:latest"."massachusetts_department_of_transportation_massdot"
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/massachusetts-department-of-transportation-massdot-6m7q-g56h
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/massachusetts-department-of-transportation-massdot-6m7q-g56h: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/massachusetts-department-of-transportation-massdot-6m7q-g56h
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/massachusetts-department-of-transportation-massdot-6m7q-g56h:latest
This will download all the objects for the latest
tag of datahub-transportation-gov/massachusetts-department-of-transportation-massdot-6m7q-g56h
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/massachusetts-department-of-transportation-massdot-6m7q-g56h: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/massachusetts-department-of-transportation-massdot-6m7q-g56h: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/massachusetts-department-of-transportation-massdot-6m7q-g56h
is just another Postgres schema.