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
    "contract_revenue", -- FY16 revenue from contracts (may include plaza maintenance contracts, concession contracts, etc.) 
    "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.) 
    "planters_maintained", -- Number of planters maintained by BID in FY16, inclusive of hanging baskets 
    "public_spaces_maintained", -- Number of public spaces maintained by BID, may include plazas, traffic medians, greenstreets, etc. (self-defined by BID) 
    "public_safety_officers_employed", -- Number of public safety officers employed by BID in FY16 
    "sanitation_workers_employed", -- Number of sanitation workers employed by BID 
    "bid_name", -- Name of business improvement district 
    "holiday_lighting_expenses", -- FY16 expenses for holiday lighting program 
    "communication_channels_used", -- same as column name 
    "public_art_installations_sponsored", -- Number of public art installations sponsored by BID in FY16 
    "hours_logged_by_public_safety_officers", -- Number of hours logged by public safety officers in FY16 
    "contributions", -- FY16 revenue from contributions 
    "interest_income", -- FY16 revenue from interest 
    "allocates_staff_salaries", -- Yes/No if specific BID allocates staff time and salaries in budget to specific program areas 
    "bid_has_holiday_lighting_program", -- Yes/No if specific BID installed holiday lighting in FY16 
    "fundraising_and_special_event_revenue", -- FY16 revenue from fundraising and special events 
    "program_service_revenue", -- FY16 revenue from program services (may include revenue from banners, parking lots, trash cans, user rights, etc.) 
    "miscellaneous_income", -- FY16 miscellaneous income
    "other_expenses", -- Other FY16 expenses 
    "total_support_and_revenue", -- same as column name 
    "public_safety_expenses", -- FY16 expenses for public safety program 
    "streetscape_and_repairs_expenses", -- FY16 expenses for streetscape program and repairs 
    "other_program_expenses", -- FY16 expenses for other programs and services (e.g. business services, social services, etc.) 
    "supplies_and_equipment_costs", -- FY16 expenses for supplies and equipment 
    "type_of_public_safety_services", -- same as column name 
    "bid_provides_supplemental_public_safety_services", -- Yes/No if specific BID provides supplemental public safety services 
    "marketing_and_special_event_expenses", -- FY16 expenses for marketing and public events 
    "government_grants", -- FY16 revenue from government grants 
    "banners_maintained", -- Number of banners maintained by BID or a sub-contractor in FY16 
    "type_of_sanitation_services", -- same as column name 
    "bid_provides_supplemental_sanitation_services", -- Yes/No if specific BID provides supplemental sanitation services 
    "full_time_staff", -- Number of full-time staff members employed by BID 
    "interactions_with_public_safety_officers", -- Number of interactions between public safety officers and residents, visitors, etc. 
    "part_time_staff", -- Number of part-time staff members employed by BID 
    "bid_provides_supplemental_streetscape_and_beautification_servic", -- Yes/No if specific BID provides supplemental streetscape/beautification services 
    "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) 
    "public_events_coordinated", -- Number of public events coordinated or co-coordinated by BID in FY16 
    "block_faces", -- Number of block faces included in District 
    "ground_floor_storefront_businesses", -- Number of ground floor storefront businesses in BID 
    "types_of_duties_assigned_to_sanitation_workers", -- same as column name 
    "incidents_of_graffiti_removed", -- Number of incidents of graffiti removed in FY16 (may include graffiti, sticker, poster removal) 
    "trash_bags_collected", -- Number of trash bags collected by BID in FY16 
    "trash_and_recycling_receptacles_serviced", -- Number of trash and recycling receptacles serviced in FY16 (include BID- and City-owned receptacles) 
    "debt_service_expenses", -- FY16 expenses for debt service on loans, bonds 
    "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 
    "salaries", -- FY16 expenses for staff salaries 
    "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 
    "duties_assigned_to_public_safety_personnel", -- same as column name 
    "tree_pits_maintained", -- Number of tree pits maintained by BID in FY16 
    "estimated_attendees_to_public_events_coordinated" -- Number of total attendees at public events coordinated by BID 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.