cityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za
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 dob_now_electrical_permit_details table in this repository, by referencing it like:

"cityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za:latest"."dob_now_electrical_permit_details"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "floor_fixtures", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the number of fixtures involved in the work on that floor.
    "sign_text", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the text on the sign.
    "sign_materials_guage", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the details of the material and gauge used in the sign construction.
    "item_quantity", -- Indicates quantity of each cost item listed under work description
    "sign_manufacturer", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the manufacturer of the sign.
    "sign_total_watts_va", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the total watts or V.A. (Volt Ampere) of the sign.
    "sign_transformers", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate number of transformers for the sign.
    "sign_dimensions", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the dimensions of the sign in feet. This field is free text.
    "floor_kw", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the total kw of heaters involved in the work on that floor.
    "floor_att_receptacles", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the number of ATT Receptacles involved in the work on that floor.
    "floor_detail", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will provide more detail about the floor on which the work will be performed. This field is free text.
    "floor_name", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the name of the floor of the building. (Example: Mezzanine, Lobby, Basement) If the floor doesn't have a name, this field will display "Floor Number(s)".
    "item", -- Indicates name of each cost item listed under work description. Example: 1∅ up to 20-1 or 10-2 pole breakers 
    "sign_id", -- A unique identifier assigned to each electrical sig decscription  under work description
    "floor_id", -- A unique identifier assigned to each floor description under a work description
    "work_id", -- A unique identifier assigned to each item listed under work description
    "sign_va_per_transformer", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate V.A. of each transformer.
    "sign_lamps", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the total number of lamps on the sign.
    "sign_sq_footage", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the total square footage of the sign. 
    "floor_switches", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the number of switches involved in the work on that floor.
    "floor_motors_generators", -- Indicates number of motors or generators in the specified floor 
    "from_floor", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", and the FLOORNAME is "Floor Number(s)", this will indicate the floor on which the work will be performed. (Or in the case of a range of floors, this will be the lowest floor number.)
    "floor_hpkw", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the total hpkw of motors or generators involved in the work on that floor.
    "floor_heaters", -- Indicates number of heaters in the specified floor 
    "fee_amount", -- Indicates total fee amount (quantity * cost)
    "item_cost", -- Indicates cost of each item listed under work description 
    "work_description", -- Indicates a header for each group of items listed under work description.  Example: Panels
    "sign_manufacturer_address", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the sign manufacturer's address.
    "floor_ac_receptacles", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the number of A/C Receptacles involved in the work on that floor.
    "sign_circuits", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the total number of circuits in the sign.
    "unique_id",
    "floor_outlets", -- Indicates number of outlets in the specified floor 
    "item_detail", -- Includes more information to describe each item 
    "job_filing_number", -- A unique identifier assigned to a job filing. It consists of job number (a letter indicating the borough followed by an 8-digit number)  hyphenated with Filing Number (a 2-digit code identifying the filing type). Once the permit is issued, a suffix  "-EL" is added to the job filing number. (Example: M00000001-I1-EL)
    "sign_total_aw_guage", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the number of (American wire) AWG gauge of wire.
    "sign_sockets_per_circuit", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the number of sockets per circuit.
    "sign_lamp_wattage", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Signs", this will indicate the wattage of the lamps on the sign.
    "to_floor", -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", and the FLOORNAME is "Floor Number(s)", this will indicate the floor on which the work will be performed. (Or in the case of a range of floors, this will be the highest floor number.)
    "floor_transformers", -- Indicates number of transformers in the specified floor 
    "floor_kva" -- If the WORK_FLOOR_DESCTRIPTION_TYPE is "Floor Descriptions", this will indicate the total kva of transformers involved in the work on that floor.
FROM
    "cityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za:latest"."dob_now_electrical_permit_details"
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 cityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.cityofnewyork.us. When you querycityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za: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.cityofnewyork.us, 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 \
  "cityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za" \
  --handler-options '{
    "domain": "data.cityofnewyork.us",
    "tables": {
        "dob_now_electrical_permit_details": "xmmq-y7za"
    }
}'

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, cityofnewyork-us/dob-now-electrical-permit-details-xmmq-y7za is just another Postgres schema.