cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i
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 fy16_bid_trends_report_data table in this repository, by referencing it like:

"cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i:latest"."fy16_bid_trends_report_data"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "salaries", -- FY16 expenses for staff salaries 
    "debt_service_expenses", -- FY16 expenses for debt service on loans, bonds 
    "other_expenses", -- Other FY16 expenses 
    "supplies_and_equipment_costs", -- FY16 expenses for supplies and equipment 
    "other_program_expenses", -- FY16 expenses for other programs and services (e.g. business services, social services, etc.) 
    "streetscape_and_repairs_expenses", -- FY16 expenses for streetscape program and repairs 
    "public_safety_expenses", -- FY16 expenses for public safety program 
    "total_support_and_revenue", -- same as column name 
    "miscellaneous_income", -- FY16 miscellaneous income
    "program_service_revenue", -- FY16 revenue from program services (may include revenue from banners, parking lots, trash cans, user rights, etc.) 
    "fundraising_and_special_event_revenue", -- FY16 revenue from fundraising and special events 
    "contributions", -- FY16 revenue from contributions 
    "contract_revenue", -- FY16 revenue from contracts (may include plaza maintenance contracts, concession contracts, etc.) 
    "estimated_attendees_to_public_events_coordinated", -- Number of total attendees at public events coordinated by BID in FY16 
    "tree_pits_maintained", -- Number of tree pits maintained by BID in FY16 
    "duties_assigned_to_public_safety_personnel", -- same as column name 
    "trash_and_recycling_receptacles_serviced", -- Number of trash and recycling receptacles serviced in FY16 (include BID- and City-owned receptacles) 
    "trash_bags_collected", -- Number of trash bags collected by BID in FY16 
    "incidents_of_graffiti_removed", -- Number of incidents of graffiti removed in FY16 (may include graffiti, sticker, poster removal) 
    "types_of_duties_assigned_to_sanitation_workers", -- same as column name 
    "ground_floor_storefront_businesses", -- Number of ground floor storefront businesses in BID 
    "block_faces", -- Number of block faces included in District 
    "public_events_coordinated", -- Number of public events coordinated or co-coordinated by BID in FY16 
    "pieces_of_street_furniture_maintained", -- Number of pieces of street furniture maintained by BID in FY16, may include benches, tables, chairs, infrastructure elements, signage, kiosks, etc. (self-defined by BID) 
    "bid_provides_supplemental_streetscape_and_beautification_servic", -- Yes/No if specific BID provides supplemental streetscape/beautification services 
    "part_time_staff", -- Number of part-time staff members employed by BID 
    "interactions_with_public_safety_officers", -- Number of interactions between public safety officers and residents, visitors, etc. 
    "full_time_staff", -- Number of full-time staff members employed by BID 
    "bid_provides_supplemental_sanitation_services", -- Yes/No if specific BID provides supplemental sanitation services 
    "type_of_sanitation_services", -- same as column name 
    "banners_maintained", -- Number of banners maintained by BID or a sub-contractor in FY16 
    "government_grants", -- FY16 revenue from government grants 
    "marketing_and_special_event_expenses", -- FY16 expenses for marketing and public events 
    "bid_provides_supplemental_public_safety_services", -- Yes/No if specific BID provides supplemental public safety services 
    "type_of_public_safety_services", -- same as column name 
    "bid_has_holiday_lighting_program", -- Yes/No if specific BID installed holiday lighting in FY16 
    "allocates_staff_salaries", -- Yes/No if specific BID allocates staff time and salaries in budget to specific program areas 
    "interest_income", -- FY16 revenue from interest 
    "hours_logged_by_public_safety_officers", -- Number of hours logged by public safety officers in FY16 
    "public_art_installations_sponsored", -- Number of public art installations sponsored by BID in FY16 
    "communication_channels_used", -- same as column name 
    "holiday_lighting_expenses", -- FY16 expenses for holiday lighting program 
    "bid_name", -- Name of business improvement district 
    "sanitation_workers_employed", -- Number of sanitation workers employed by BID 
    "public_safety_officers_employed", -- Number of public safety officers employed by BID in FY16 
    "public_spaces_maintained", -- Number of public spaces maintained by BID, may include plazas, traffic medians, greenstreets, etc. (self-defined by BID) 
    "planters_maintained", -- Number of planters maintained by BID in FY16, inclusive of hanging baskets 
    "marketing_materials_distributed", -- Sum of all marketing materials distributed, including: District guides/maps, Event-Specific Advertisements, Coupon books, Apparel (e.g. t-shirts), Accessories (e.g. totes, sunglasses), Office supplies (e.g. pens, pads, etc.) 
    "assessment_revenue", -- FY16 revenue from special assessment 
    "sanitation_expenses", -- FY16 expenses for sanitation program 
    "beautification_and_horticulture_expenses", -- FY16 expenses for beautification and horticulture program 
    "insurance_costs", -- FY16 expenses for insurance (liability, workers comp, auto required) 
    "outside_contractor_expenses", -- FY16 expenses for outside contractors (e.g. marketing, research, design, etc.) 
    "rent_and_utilities", -- FY16 expenses for rent and utilities 
    "capital_improvement_expenses", -- FY16 expenses for capital improvements (e.g. park, plaza development) 
    "total_expenses", -- same as column name 
    "hours_logged_by_sanitation_workers" -- Number of hours logged by sanitation workers in FY16 
FROM
    "cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i:latest"."fy16_bid_trends_report_data"
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/fy16-bid-trends-report-data-43ab-v68i 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/fy16-bid-trends-report-data-43ab-v68i: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/fy16-bid-trends-report-data-43ab-v68i" \
  --handler-options '{
    "domain": "data.cityofnewyork.us",
    "tables": {
        "fy16_bid_trends_report_data": "43ab-v68i"
    }
}'

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/fy16-bid-trends-report-data-43ab-v68i is just another Postgres schema.