brla-gov/purchase-orders-and-contracts-2ung-w7t4
Icon for Socrata external plugin

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

"brla-gov/purchase-orders-and-contracts-2ung-w7t4:latest"."purchase_orders_and_contracts"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "dept_name", -- Department name which the PO/Contract is for
    "object_desc", -- The description of the type of expense for this good/service. 
    "commodity_desc", -- Description classifying the type of good/service being purchased. 
    "commodity_code", -- Code classifying the type of good/service being purchased.   
    "item_total_cost", -- Total (extended) cost of the PO/Contract line item being ordered.
    "total_items", -- Total number of detail items on PO/Contract.  Each PO/Contract will have at least 1 detail item.
    "vendor_type", -- Indicates the type of business the vendor is in.
    "vendor_name_2", -- Vendor doing business as (DBA) name 
    "vendor_name_1", -- Vendor's primary business name
    "annual_contract", -- For PO only, the annual contract this PO was purchased from 
    "vouched_amount", -- Actual amount invoiced against PO/Contract.  This amount may be less than the original PO/Contract amount.
    "source_doc_type_description", -- Description of the type of PO/Contract.
    "cost_center", -- Cost Center of the Department which the PO/Contract is for.  This will often show which of the Department's Divisions issued the PO/Contract
    "dept_num", -- Number of the department which the PO/Contract is for
    "input_date", -- Date PO/Contract was entered into the system
    "source_doc_desc", -- Description of the good/service being procured. 
    "item_quantity_ordered", -- Quantity being ordered for this PO/Contract line item.
    "smb_dbe", -- Small business disadvantaged business enterprise 
    "vendor_city",
    "extended_through_date", -- For contracts only, date contract has been extended 
    "item_number", -- Sequential number of the detail PO/Contract line item.
    "requisition_no", -- Requisition number used for purchase.
    "object", -- The code indicating the type of expense for this good/service. 
    "item_unit_of_mea", -- Code indicating Unit of Measure for this PO/Contract line item.
    "item_description", -- Description of good or service being ordered on this PO/Contract line item.
    "cost_center_name", -- Description of Cost Center of the Department which the PO/Contract is for.  This will often show which of the Department's Divisions issued the PO/Contract
    "source_doc_type_code", -- Code indicating the type of PO/Contract.  
    "smb_mn_wom", -- Small business minority woman owned 
    "initial_expiration_date", -- For contracts only, expected date for work to end 
    "source_doc_status_description", -- Description of the status of the PO/Contract.
    "vendor_geographic_code", -- Geographic area of vendor (INP=In EBR Parish, INS=In State, USA=In Country, INTL=International 
    "vendor_zip",
    "item_unit_cost", -- Unit Cost for this PO/Contract line item.
    "estimated_start_date", -- For contracts only, estimated date for work to begin 
    "total_amount", -- Total amount of PO/Contract
    "source_document", -- Numeric ID of the PO/Contract 
    "vendor_state",
    "smb_min", -- Small business minority owned 
    "dvse", -- Small business disabled veteran 
    "dbe", -- Disadvantaged business enterprise 
    "vendor_independent_contractor", -- Whether or not the vendor is an independent contractor
    "vendor_status", -- Vendor's status A=Active, B=Bidder, I=Inactive, O=One Time Pay, S=Stop, T=Temporary, S=Self Service 
    "record_type", -- H or D.  H indicates record is a header record.  D indicates a detail record.  A PO/Contract will have 1 header record and at least 1 detail item
    "vet_sm_bus", -- Small business veteran owned 
    "sb_non_mn", -- Small business non-minority owned 
    "vendor_gender",
    "source_doc_type", -- Code representing the type of PO/Contract P = Purchase Order, C = Contract
    "vendor_class", -- The vendor's classification (LLC, Corporation, Sole Proprietor, etc) 
    "source_doc_status_code", -- Code indicating the status of the PO/Contract.
    "smb_woman", -- Small business woman owned 
    "dvbe", -- Disabled veteran business enterprise 
    "isminority", -- Is the vendor a minority business enterprise 
    "vendor_ethnicity"
FROM
    "brla-gov/purchase-orders-and-contracts-2ung-w7t4:latest"."purchase_orders_and_contracts"
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/purchase-orders-and-contracts-2ung-w7t4 with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.brla.gov. When you querybrla-gov/purchase-orders-and-contracts-2ung-w7t4:latest on the DDN, we "mount" the repository using the socrata mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT is only guaranteed for subsequent queries that land on the same node.

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 (like this repository), 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, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.brla.gov, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone to get the data. Instead, you can use the socrata adapter with the sgr mount command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

Mount the table with sgr mount

sgr mount socrata \
  "brla-gov/purchase-orders-and-contracts-2ung-w7t4" \
  --handler-options '{
    "domain": "data.brla.gov",
    "tables": {
        "purchase_orders_and_contracts": "2ung-w7t4"
    }
}'

That's it! Now you can query the data in the mounted table like any other Postgres table.

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/purchase-orders-and-contracts-2ung-w7t4 is just another Postgres schema.