internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w
Loading...

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

"internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w:latest"."us_rail_tariff_rates_for_grain_and_soybeans"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "month", -- Month extracted from Date field. 1 through 12, where 1 refers to January, 2 to February, etc.
    "origin_city", -- Origin city used to determine applicable tariff.
    "date", -- Date to represent month-long period for rate. Railroad websites require a day-level date to determine the applicable tariff. However, data is collected only monthly. Therefore, Date is accurate to the month and year level.
    "train_type", -- Train type, either unit or shuttle. Different railroads have different definitions of shuttle and unit, including the number of cars per train. A typical break is unit trains have fewer than 75 cars and shuttle trains have greater than 75 cars.
    "tariffplusfsc_car", -- Sum of Tariff per Car and FSC per Car.
    "destination_state", -- Destination state used to determine applicable tariff.
    "od_line", -- Line shape from origin and destination point.
    "mileage", -- Distance between Origin and Destination in Miles
    "tariff_car", -- The tariff rate reported by the railroad based on the shipment characteristics
    "fsc_mile", -- Applicable fuel surcharge, based on the railroad and date. This is measured as "per mile per car."
    "fsc_car", -- Calculated based on FSC per car-mile and mileage.
    "tariff_bushel", -- Calculated based on Tariff per MT and a commodity-specific values of bushels per metric ton (e.g., 56 lbs/bu for corn, 60 lbs/bu for soybeans, and 60 lbs/bu for wheat).
    "tariff_mt", -- Calculated based on Tariff per Car and a typical 286,000-lb car size of 100.7 metric tons per car.
    ":@computed_region_7rrn_7wru",
    "destination_city", -- Destination city used to determine applicable tariff.
    "destination_point", -- Geocode of destination state.
    "origin_point", -- Geocode of origin state.
    "tariffplusfsc_bushel", -- Sum of Tariff per BU and FSC per BU.
    "tariffplusfsc_mt", -- Sum of Tariff per MT and FSC per MT.
    "origin_state", -- Origin state used to determine applicable tariff.
    "commodity", -- Name of commodity used to determine applicable tariff (e.g., corn, soybeans, or wheat).
    "railroad", -- Railroad name (one of 7 Class I railroads).
    "year", -- Year extracted from Date field. 2010 to the present.
    ":@computed_region_pg4y_ynkd"
FROM
    "internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w:latest"."us_rail_tariff_rates_for_grain_and_soybeans"
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 internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w with SQL in under 60 seconds.

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

Cloning Data

Because internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w: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 internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w

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 internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w:latest

This will download all the objects for the latest tag of internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w 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 internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w: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 internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w: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, internal-agtransport-usda-gov/us-rail-tariff-rates-for-grain-and-soybeans-idbx-qf4w is just another Postgres schema.

Related Documentation:

Loading...