ftb-ca-gov/c2-tax-liability-computations-all-corporations-p6m4-tupe
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 c2_tax_liability_computations_all_corporations table in this repository, by referencing it like:

"ftb-ca-gov/c2-tax-liability-computations-all-corporations-p6m4-tupe:latest"."c2_tax_liability_computations_all_corporations"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "apportioning_corps_returns_with_business_income_apportioned_to_", -- Number of returns with business income allocated to California.
    "apportioning_corp_nonbusiness_income_allocated_to_ca", -- Total nonbusiness income amount allocated to California. 
    "apportioning_corp_returns_with_nonbusiness_income_allocated_to_", -- Number of returns with nonbusiness income allocated to California.
    "total_apportioning_business_income", -- Total apportioning business income amount.
    "corp_returns_with_apportioning_business_income", -- Number of returns with apportioning business income.
    "total_apportioning_nonbusiness_income", -- Total apportioning nonbusiness income amount.
    "corp_returns_with_apportioning_nonbusiness_income", -- Number of returns with apportioning nonbusiness income.
    "net_income_after_state_adjs_profit", -- Total profit after state adjustments amount.
    "returns_net_income_after_state_adjs_profit", -- Number of returns with positive net income after state Adjustments.
    "net_income_after_state_adjs_loss", -- Total loss after state adjustments amount.
    "returns_net_income_after_state_adjs_loss", -- Number of returns with negative net income after state Adjustments.
    "net_income_after_state_adjs", -- Total net income after state adjustments amount.
    "returns_with_net_income_after_state_adjs", -- Number of returns with net income after state adjustments.
    "net_income_before_state_adjs", -- Total net income before state adjustments amount.
    "returns_with_net_income_before_state_adjs", -- Number of returns with net income before state adjustments.
    "total_deductions", -- Total deductions amount.
    "returns_total_deductions", -- Number of returns with total deductions.
    "total_income", -- Total income amount.
    "returns_tax_credits", -- Number of returns with tax credit.
    "returns_less_cost_of_goods_sold", -- Number of returns with cost of goods sold.
    "gross_receipts", -- Total gross receipts amount.
    "returns_with_gross_receipts", -- Number of returns with gross receipts.
    "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.
    "excess_net_passive_income", -- Total net passive income amount
    "returns_pte_elective", -- Number of returns with Pass Thru Entity (PTE) election
    "tax_before_credits_and_amt", -- Total tax before credits and AMT amount.
    "returns_tax_before_credits_and_amt", -- Number of returns with tax before credits and alternative minimum tax (AMT).
    "sni_after_nol_or_disaster_loss", -- Total SNI amount after NOL for tax purposes.
    "returns_sni_after_nol_or_disaster_loss", -- Number of returns with SNI after NOL for tax purposes.
    "nol_or_disaster_loss", -- Total NOL and disaster loss amount.
    "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. 
    "returns_taxable_profit", -- Number of returns with net profit for state purposes after apportionment.
    "taxable_loss", -- Total state net loss amount after apportionment. 
    "returns_taxable_loss", -- Number of returns with net loss for state purposes after apportionment.
    "total_sni", -- Total SNI amount (total of apportioning SNI and nonapportioning SNI).
    "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.
    "returns_nonapportioning_corps_state_net_income", -- Number or returns with nonapportioned state net income (SNI).
    "apportioning_corps_state_net_income", -- Total apportioning SNI amount.
    "returns_apportioning_corps_state_net_income", -- Number or returns with apportioned state net income (SNI).
    "apportioning_corp_business_income_apportioned_to_ca", -- Total business income amount allocated to California. 
    "returns_total_income", -- Number of returns with total income.
    "gross_profit", -- Total of gross profit amount.
    "returns_gross_profit", -- Number of returns with gross profit.
    "less_cost_of_goods_sold", -- Total cost of goods sold amount.
    "tax_credits", -- Total tax credit amount.
    "returns_amt", -- Number of returns with AMT, tax from schedule D, and excess net passive income tax.
    "amt", -- Total alternative minimum tax (AMT), tax from schedule D, and excess net passive income tax amount.
    "returns_excess_net_passive_income", -- Number of returns with excess net passive income amount
    "pte_elective", -- Total Pass Thru Entity (PTE) election amount
    "returns_with_total_state_tax", -- Number of returns with total state tax.
    "total_state_tax" -- Total state tax amount.
FROM
    "ftb-ca-gov/c2-tax-liability-computations-all-corporations-p6m4-tupe:latest"."c2_tax_liability_computations_all_corporations"
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/c2-tax-liability-computations-all-corporations-p6m4-tupe 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/c2-tax-liability-computations-all-corporations-p6m4-tupe: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/c2-tax-liability-computations-all-corporations-p6m4-tupe" \
  --handler-options '{
    "domain": "data.ftb.ca.gov",
    "tables": {
        "c2_tax_liability_computations_all_corporations": "p6m4-tupe"
    }
}'

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/c2-tax-liability-computations-all-corporations-p6m4-tupe is just another Postgres schema.