ftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama
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 c2a_and_c2b_tax_liability_computations_c_and_s table in this repository, by referencing it like:

"ftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama:latest"."c2a_and_c2b_tax_liability_computations_c_and_s"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "returns_total_sni", -- Number of returns with (apportioned and nonapportioned) total income for state purposes (SNI).
    "nonapportioning_corps_state_net_income", -- Total nonapportioning SNI amount.
    "apportioning_corps_returns_with_business_income_apportioned_to_", -- Number of returns with business income allocated to California.
    "returns_apportioning_corps_state_net_income", -- Number or returns with apportioned state net income (SNI).
    "apportioning_corps_state_net_income", -- Total apportioning SNI amount.
    "returns_nonapportioning_corps_state_net_income", -- Number or returns with nonapportioned state net income (SNI).
    "returns_taxable_profit", -- Number of returns with net profit for state purposes after apportionment.
    "returns_with_net_income_before_state_adjs", -- Number of returns with net income before state adjustments.
    "returns_net_income_after_state_adjs_profit", -- Number of returns with positive net income after state Adjustments.
    "total_apportioning_business_income", -- Total apportioning business income amount.
    "apportioning_corp_business_income_apportioned_to_ca", -- Total business income amount allocated to California. 
    "returns_taxable_loss", -- Number of returns with net loss for state purposes after apportionment.
    "taxable_loss", -- Total state net loss amount after apportionment. 
    "net_income_before_state_adjs", -- Total net income before state adjustments amount.
    "returns_with_net_income_after_state_adjs", -- Number of returns with net income after state adjustments.
    "net_income_after_state_adjs", -- Total net income after state adjustments amount.
    "total_apportioning_nonbusiness_income", -- Total apportioning nonbusiness income amount.
    "returns_total_deductions", -- Number of returns with total deductions.
    "corp_returns_with_apportioning_business_income", -- Number of returns with apportioning business income.
    "apportioning_corp_returns_with_nonbusiness_income_allocated_to_", -- Number of returns with nonbusiness income allocated to California.
    "returns_nol_or_disaster_loss", -- Number of returns with net operating loss (NOL) and disaster loss.
    "taxable_profit", -- Total state net profit amount after apportionment. 
    "total_sni", -- Total SNI amount (total of apportioning SNI and nonapportioning SNI).
    "returns_total_income", -- Number of returns with total income.
    "taxable_year", -- Taxable year for which tax returns were filed in a number format that can be used to filter and sort, as well as display in charts.
    "sni_after_nol_or_disaster_loss", -- Total SNI amount after NOL for tax purposes.
    "returns_tax_credits", -- Number of returns with tax credit.
    "returns_amt", -- Number of returns with AMT, tax from schedule D, and excess net passive income tax.
    "returns_sni_after_nol_or_disaster_loss", -- Number of returns with SNI after NOL for tax purposes.
    "amt", -- Total alternative minimum tax (AMT), tax from schedule D, and excess net passive income tax amount.
    "gross_receipts", -- Total gross receipts amount.
    "total_state_tax", -- Total state tax amount.
    "returns_tax_before_credits_and_amt", -- Number of returns with tax before credits and alternative minimum tax (AMT).
    "apportioning_corp_nonbusiness_income_allocated_to_ca", -- Total nonbusiness income amount allocated to California. 
    "corp_returns_with_apportioning_nonbusiness_income", -- Number of returns with apportioning nonbusiness income.
    "returns_gross_profit", -- Number of returns with gross profit.
    "net_income_after_state_adjs_profit", -- Total profit after state adjustments amount.
    "corporation_type", -- Denotes C or S Corporation.
    "total_deductions", -- Total deductions amount.
    "returns_net_income_after_state_adjs_loss", -- Number of returns with negative net income after state Adjustments.
    "net_income_after_state_adjs_loss", -- Total loss after state adjustments amount.
    "nol_or_disaster_loss", -- Total NOL and disaster loss amount.
    "tax_before_credits_and_amt", -- Total tax before credits and AMT amount.
    "tax_credits", -- Total tax credit amount.
    "returns_with_total_state_tax", -- Number of returns with total state tax.
    "returns_with_gross_receipts", -- Number of returns with gross receipts.
    "returns_less_cost_of_goods_sold", -- Number of returns with cost of goods sold.
    "less_cost_of_goods_sold", -- Total cost of goods sold amount.
    "gross_profit", -- Total of gross profit amount.
    "total_income" -- Total income amount.
FROM
    "ftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama:latest"."c2a_and_c2b_tax_liability_computations_c_and_s"
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 ftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.ftb.ca.gov. When you queryftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama: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.ftb.ca.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 \
  "ftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama" \
  --handler-options '{
    "domain": "data.ftb.ca.gov",
    "tables": {
        "c2a_and_c2b_tax_liability_computations_c_and_s": "v2rv-mama"
    }
}'

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, ftb-ca-gov/c2a-and-c2b-tax-liability-computations-c-and-s-v2rv-mama is just another Postgres schema.