cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i
Loading...

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
    "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 
    "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 
    "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 
    "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 
    "public_safety_expenses", -- FY16 expenses for public safety program 
    "total_support_and_revenue", -- same as column name 
    "miscellaneous_income", -- FY16 miscellaneous income
    "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.) 
    "contributions", -- FY16 revenue from contributions 
    "contract_revenue", -- FY16 revenue from contracts (may include plaza maintenance contracts, concession contracts, etc.) 
    "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 
    "streetscape_and_repairs_expenses", -- FY16 expenses for streetscape program and repairs 
    "ground_floor_storefront_businesses", -- Number of ground floor storefront businesses in BID 
    "block_faces", -- Number of block faces included in District 
    "other_program_expenses", -- FY16 expenses for other programs and services (e.g. business services, social services, etc.) 
    "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) 
    "supplies_and_equipment_costs", -- FY16 expenses for supplies and equipment 
    "bid_provides_supplemental_streetscape_and_beautification_servic", -- Yes/No if specific BID provides supplemental streetscape/beautification services 
    "other_expenses", -- Other FY16 expenses 
    "debt_service_expenses", -- FY16 expenses for debt service on loans, bonds 
    "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 
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.

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, 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 (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Cloning Data

Because cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i:latest is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.

First, install Splitgraph if you haven't already.

Clone the metadata with sgr clone

This will be quick, and does not download the actual data.

sgr clone cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i

Checkout the data

Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest tag:

sgr checkout cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i:latest

This will download all the objects for the latest tag of cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.

Alternatively, use "layered checkout" to avoid downloading all the data

The data in cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i:latest is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:

sgr checkout --layered cityofnewyork-us/fy16-bid-trends-report-data-43ab-v68i:latest

This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.

Read the layered querying documentation to learn about when and why you might want to use layered queries.

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.

Related Documentation:

Loading...