finances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq
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 afghanistan_reconstruction_trust_fund_artf_donor table in this repository, by referencing it like:

"finances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq:latest"."afghanistan_reconstruction_trust_fund_artf_donor"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "total_receipt_amount_in_usd", -- Paid-in Receipt Amount Preference + No Preference (in USD)
    "project_preference_project_id", -- Project ID for which Donor expressed contribution preference. 
    "receipt_amount_in_donation_currency", -- Contributions received from a Donor in the form of cash by the World Bank entity administering the Trust Fund. 
    "foreign_exchange_receipt_year_sy", -- Solar year within which the Foreign Exchange Date falls. 
    "foreign_exchange_receipt_date", -- Value date of Receipt Amount in Receipt Currency exchanged for USD 
    "installment_due_year_fy", -- Fiscal year within which the Installment Due Date falls. The fiscal year begins on July 1st of the previous year and runs through June 30th of the designated year.
    "installment_due_date", -- Date installment is due for Contribution Amount. Date donor pledges to make contributions.
    "contribution_commitment_amount", -- Contribution Commitment amount - The amount pledged by a donor in the grant agreement. This amount is recorded by the bank, and sometimes paid in separate installments. 
    "installment_posting_date", -- "Date the Trust Funds team posts actual receivables into TF account for a portion of a Contribution (installment)"
    "donor_code", -- Country Code according to the World Bank country list. Might be different from the ISO country code.
    "donor_id", -- Donor identification number.
    "foreign_exchange_receipt_year_fy", -- Fiscal year within which the Foreign Exchange Date falls. The fiscal year begins on July 1st of the previous year and runs through June 30th of the designated year.
    "installment_due_year_cy", -- Calendar year within which the Installment Due Date falls. 
    "project_preference", -- A Description of the project  for which Donor expressed contribution preference. 
    "project_preference_trust_fund_grant_number", -- Trust fund grant ID for which Donor expressed contribution preference. 
    "as_of_date", -- Date when the data snapshot was taken.
    "trustee_fund_number", -- Refers to Trustee Account. The Trustee Account is the account at the highest level in the Trust Fund hierarchy into which Contributions or other funds are received. Every Trust fund hierarchy has one Trustee Account. 
    "donor_or_grant_agreement_currency", -- Currency of the contriubtion, as per the Grant Agreement. 
    "installment_posting_year_cy", -- Calendar year within which the Installment Posting Date falls.
    "preference_amount_in_usd", -- Amount of Contribution with Preference, in USD 
    "trustee_fund_name", -- "Refers to the Trustee Fund name used in the World Bank system to identify a Trustee Account."
    "fund",
    "installment_posting_year_fy", -- World Bank Fiscal year within which the Installment Posting Date. The fiscal year begins on July 1st of the previous year and runs through June 30th of the designated year.
    "installment_posting_year_sy", -- Calendar year within which the Installment Posting Date falls.
    "donor_country", -- Name of donor country/entity.
    "ammendment_unique_id", -- Unique Identifier for the contribution. Contributions are sometimes paid in installments. When payments share the Ammendment ID, these are installments of the same contribution committed. 
    "installment_due_year_sy", -- Solar year within which the Installment Due Date falls. 
    "foreign_exchange_receipt_year_cy", -- Calendar year within which the Foreign Exchange Date falls.
    "no_preference_amount_in_usd" -- Amount of contribution with no Preference, in USD
FROM
    "finances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq:latest"."afghanistan_reconstruction_trust_fund_artf_donor"
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 finances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at finances.worldbank.org. When you queryfinances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq: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 finances.worldbank.org, 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 \
  "finances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq" \
  --handler-options '{
    "domain": "finances.worldbank.org",
    "tables": {
        "afghanistan_reconstruction_trust_fund_artf_donor": "6ajy-n8cq"
    }
}'

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, finances-worldbank/afghanistan-reconstruction-trust-fund-artf-donor-6ajy-n8cq is just another Postgres schema.