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 2022_ntd_annual_data_capital_expenses_by_capital
table in this repository, by referencing it like:
"datahub-transportation-gov/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj:latest"."2022_ntd_annual_data_capital_expenses_by_capital"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"total_questionable", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"total", -- Total of the categories above.
"reduced_reporter", -- Capital expenses incurred by agencies that do not report capital expenses in specific categories because they have reduced reporting requirements.
"other", -- Any item not described as guideway, passenger stations, administrative buildings, maintenance buildings, revenue vehicles, service vehicles, fare revenue collection equipment, or systems including: • Furniture and equipment that are not an integral part of buildings and structures; and • Shelters, signs, and passenger amenities (e.g., benches) not in passenger stations.
"other_vehicles", -- The vehicles used to support revenue vehicle operations and that are not used to carry transit passengers. These vehicles may be referred to as non-revenue vehicles. Examples include: • Tow trucks • Supervisor vans • Transit police cars • Staff cars • Maintenance vehicles for maintaining passenger facilities and rights-of-way (ROW) (rail stations, bus shelters, track, etc.)
"passenger_vehicles", -- The floating and rolling stock used to provide revenue service for passengers.
"mode_voms", -- The number of revenue vehicles operated by the given mode and type of service to meet the annual maximum service requirement. This is the revenue vehicle count during the peak season of the year; on the week and day that maximum service is provided. Vehicles operated in maximum service (VOMS) exclude atypical days and one-time special events.
"typeofservicecd", -- Describes how public transportation services are provided by the transit agency: directly operated (DO) or purchased transportation (PT) services.
"agency_voms", -- The number of revenue vehicles operated across the whole agency to meet the annual maximum service requirement. This is the revenue vehicle count during the peak season of the year; on the week and day that maximum service is provided. Vehicles operated in maximum service (VOMS) exclude atypical days and one-time special events.
"primary_uza_population", -- The population of the urbanized area primarily served by the agency.
"uza_name", -- The name of the agency's Urbanized Area.
"uace_code", -- UACE Code remains consistent across census years.
"reporter_type", -- The type of NTD report that the agency completed this year.
"organization_type", -- Description of the agency's legal entity.
"ntd_id", -- A five-digit identifying number for each agency used in the current NTD system.
"state", -- The state in which the agency is headquartered.
"city", -- The city in which the agency is headquartered.
"agency", -- The transit agency's name.
"mode_name", -- A system for carrying transit passengers described by specific right-of-way (ROW), technology and operational features.
"stations_questionable", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"stations", -- Passenger stations are significant structures in a separate right-of-way (ROW). Therefore, agencies may not report a street stop or passenger shelter as a passenger station. Passenger stations typically mean a platform area for rail modes. The following rules apply: • All rail passenger facilities are stations (except for light rail (LR), streetcar (SR), and cable car (CC) modes); • All LR, CC, and SR passenger facilities serving track that is in a separate ROW (not in mixed street traffic) that have platforms are stations; • All motorbus (MB), rapid bus (RB), commuter bus (CB), and trolley bus (TB) passenger facilities in a separate ROW that have an enclosed structure (building) for passengers for such items as ticketing, information, restrooms, concessions, and telephones are stations; • When service is operated in mixed traffic, stops on streets or in medians for CC, LR, SR, MB, RB, CB, and TB are not stations if at most they have shelters, canopies, lighting, signage or ramps for accessibility requirements, (i.e. no separate, enclosed buildings); and • All transportation, transit or transfer centers, park-and-ride facilities, and transit malls are stations if they have an enclosed structure (building) for passengers for items such as ticketing, information, restrooms, concessions, and telephones.
"passenger_vehicles_1", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"other_vehicles_questionable", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"other_questionable", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"maintenance_buildings_1", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"guideway_questionable", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"form_type", -- Category in which capital spending was applied.
"fare_collection_equipment_1", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"administrative_buildings_1", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"reduced_reporter_questionable", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"communication_information_1", -- FTA marks a data point as Questionable when there is reason to believe it is incorrect, but the reporting agency has been unable to correct the data or offer an explanation for its anomalous appearance.
"communication_information", -- Systems for exchanging information including two-way radio systems for communications between dispatchers and vehicle operators, cab signaling and train control equipment in rail systems, automatic vehicle locator systems, automated dispatching systems, vehicle guidance systems, telephones, facsimile machines and public address systems. Systems for processing data, including computers, monitors, printers, scanners, data storage devices, and associated software that support transit operations such as general office, accounting, scheduling, planning, vehicle maintenance, non-vehicle maintenance, and customer service functions
"fare_collection_equipment", -- Equipment used in collecting passenger fares including turnstiles, fare boxes (drop), automated fare boxes and related software, money changers and fare dispensing machines (tickets, tokens, passes).
"maintenance_buildings", -- Facilities where maintenance activities are conducted including garages, shops (e.g., body, paint, machine) and operations centers (see Vehicle Maintenance (041) function). Include in maintenance buildings, equipment that enhances the maintenance function, for example: bus (MB) diagnostic equipment. Does not include information systems such as computers that are used to process maintenance data.
"administrative_buildings", -- Facilities and offices which house the executive management and supporting activities for overall transit operations such as accounting, finance, engineering, legal, safety, security, customer services, scheduling and planning (see General Administration (160) function). They include separate buildings for customer information or ticket sales, which are owned by the transit agency and which are not part of passenger stations.
"guideway", -- A public transportation facility using and occupying a separate right-of-way (ROW) or rail for the exclusive use of public transportation including the buildings and structures dedicated for the operation of transit vehicles such as: • At grade • Elevated and subway structures • Tunnels • Bridges • Track and power systems for rail modes • Paved highway lanes dedicated to bus (MB) mode Guideway does not include passenger stations and transfer facilities, MB pull-ins or communication systems (e.g., cab signaling and train control).
"modecd", -- A system for carrying transit passengers described by specific right-of-way (ROW), technology and operational features.
"report_year" -- The year for which the data was reported.
FROM
"datahub-transportation-gov/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj:latest"."2022_ntd_annual_data_capital_expenses_by_capital"
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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj
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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj: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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj
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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj:latest
This will download all the objects for the latest
tag of datahub-transportation-gov/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj
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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj: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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj: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/2022-ntd-annual-data-capital-expenses-by-capital-fphd-jyyj
is just another Postgres schema.