Query the Data Delivery Network
Query the DDNThe 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 2018_prek_school_directory
table in this repository, by referencing it like:
"cityofnewyork-us/2018-prek-school-directory-xck4-5xd5:latest"."2018_prek_school_directory"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"contact_name", -- The name of the contact person at the school
"bin", -- The BIN (Building Identification Number) is a unique identifier for each building in the City.
"council_district", -- The Council District field indicates the New York City Council District where the building is located.
"community_board", -- The Community Board field indicates the New York City Community District where the building is located.
"longitude", -- Longitude of the building's location.
"enhancedlang_note", -- Designates whether a program is an Enhanced Language program. Identifies the target language.
"subway_stop", -- Subway lines near the school
"bus", -- Bus lines near the school
"halfday_offers", -- A note explaining that the "Who Got Offers" chart does not apply to half-day programs.
"lpga", -- A note explaining who received offers last year for programs with unique priority structures or for those in choice districts. Programs new to the 2018 Pre-K Application are also noted here.
"pkc_indistrict_none", -- For District programs: designates whether no in-district students received offers last year
"nyceec_current_all", -- For NYCEECs: designates whether all current students received offers last year.
"programcode1", -- Code families use on the application to apply to that specific program (affiliated with programname1).
"play", -- Designates the type of playspace a school has available to students and whether the space is indoor, outdoor, onsite or offsite
"final_address", -- School's address
"bbl", -- The BBL (Borough, Block, and Lot) is a unique identifier for each tax lot in the City.
"census_tract", -- The Census Tract field indicates the U.S. Census Tract where the building is located.
"latitude", -- Latitude of the building's location.
"flexschedule", -- Designates whether a program may have a flexible scheduling policy.
"latepickup", -- Time a program ends late pickup.
"diversity", -- Designates whether a program is part of the Diversity in Admissions pilot.
"specialpriority", -- Describes the priority structures for programs with unique admissions priorities. This also flags programs located in choice districts.
"pkc_outdistrict_some", -- For District programs: designates whether some out-of-district students received offers last year
"district_outdistrict", -- For District programs: designates whether all in-district students received offers last year
"district_outdissibs_2", -- For District programs: designates whether no out-of-district siblings received offers last year
"district_outdissibs_1", -- For District programs: designates whether some out-of-district siblings received offers last year
"district_3", -- For District programs: designates whether no in-district siblings received offers last year
"district_2", -- For District programs: designates whether some in-district siblings received offers last year
"district_1", -- For District programs: designates whether all in-district siblings received offers last year
"district_otherzone", -- For District programs: designates whether all in-district siblings received offers last year
"district_zonedsib_2", -- For District programs: designates whether no zoned students received offers last year
"nyceec_others_none", -- For NYCEECs: designates whether no other students received offers last year
"programname2", -- Designates whether the second program at the school (if applicable) is full-day, half-day, 5 hour, or dual language.
"programname1", -- Designates whether the first program offered at the school is full-day, half-day, 5 hour, or dual language.
"meals", -- Designates which meals are provided to students during the school day. Values can be all, none or some of the following: breakfast, lunch, snack(s)
"website", -- School website
"prek_type", -- Pre-K program type
"district", -- Community School District school is located
"borough", -- Borough where school is located
"locationname", -- School's name
"schooldbn", -- DBN (District Borough Number): code used by the NYC Department of Education to uniquely identify schools
"nta", -- The Neighborhood Tabulation Area field indicates the New York City Neighborhood area where the building is located.
"district_otherzone_1", -- For District programs: designates whether some in-district siblings received offers last year
"district_zonedsib_1", -- For District programs: designates whether some zoned siblings received offers last year
"district_otherzone_2", -- For District programs: designates whether some zoned students received offers last year
"nyceec_current_none", -- For NYCEECs: designates whether no current students received offers last year
"pkc_outdistrict_none", -- For District programs: designates whether no out-of-district students received offers last year
"pkc_indistrict_some", -- For District programs: designates whether some in-district students received offers last year
"nyceec_siblings_none", -- For NYCEECs: designates whether no siblings received offers last year
"nyceec_services_all", -- For NYCEECs: designates whether all students receiving social services received offers last year
"nyceec_targetlang_1", -- For NYCEECs and are Enhanced Language programs: designates whether some students that speak the target language received offers last year
"nyceec_targetlang", -- For NYCEECs and are Enhanced Language programs: designates whether all students that speak the target language received offers last year
"income_flg", -- Flag for programs that may have income or other eligibility requirements.
"nyceec_siblings_some", -- For NYCEECs: designates whether some current students received offers last year
"nyceec_others_some", -- For NYCEECs: designates whether some other students received offers last year
"nyceec_others_all", -- For NYCEECs: designates whether all other students received offers last year
"contact_email", -- The email of the contact person at the school
"programcode2", -- Code families use on the application to apply to that specific program (affiliated with programname2).
"uniforms", -- Flag for programs that have a uniform requirement
"nyceec_services_some", -- For NYCEECs: designates whether some students receiving social services received offers last year
"nyceec_current_some", -- For NYCEECs: designates whether some current students received offers last year
"district_zonedsib", -- For District programs: designates whether all zoned siblings received offers last year
"nyceec_services_none", -- For NYCEECs: designates whether no students receiving social services received offers last year
"nyceec_siblings_all", -- For NYCEECs: designates whether all siblings received offers last year
"nyceec_targetlang_2", -- For NYCEECs and are Enhanced Language programs: designates whether no students that speak the target language received offers last year
"phone", -- School's phone number
"programname3", -- Designates whether the third program at the school (if applicable) is full-day, half-day, 5 hour, or dual language.
"postcode", -- Zipcode where the building is located
"pkc_indistrict_all", -- For District programs: designates whether all in-district students received offers last year
"district_outdistrict_2", -- For District programs: designates whether no in-district students received offers last year
"earlydropoff", -- Time a program starts early dropoff.
"programcode3", -- Code families use on the application to apply to that specific program (affiliated with programname3).
"district_indistrict", -- For District programs: designates whether all in-district students received offers last year
"district_outdissibs", -- For District programs: designates whether all out-of-district siblings received offers last year
"hours", -- Program hours
"accessibility", -- Designates the program's level of accessibility.
"pkc_outdistrict_all", -- For District programs: designates whether all out-of-district students received offers last year
"rezoning", -- Designates district schools that could potentially be impacted by a rezoning proposal.
"district_outdistrict_1", -- For District programs: designates whether some in-district students received offers last year
"district_indistrict_2", -- For District programs: designates whether no out-of-district siblings received offers last year
"iepnote", -- A note that prompts families of students with particular IEP recommendations to contact the program.
"magnet", -- Designates whether a program is a magent program. Describes the curricular focus of that magent program.
"district_indistrict_1", -- For District programs: designates whether some in-district students received offers last year
"seats", -- The number of full-day, half-day and 5 hour seats at program(s) last year.
"singlegender" -- Flag for programs that may have some single-gender classrooms or are single-gender programs
FROM
"cityofnewyork-us/2018-prek-school-directory-xck4-5xd5:latest"."2018_prek_school_directory"
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/2018-prek-school-directory-xck4-5xd5
with SQL in under 60 seconds.
Query Your Local Engine
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; sgr
can 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 clone
and sgr checkout
.
Cloning Data
Because cityofnewyork-us/2018-prek-school-directory-xck4-5xd5: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/2018-prek-school-directory-xck4-5xd5
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/2018-prek-school-directory-xck4-5xd5:latest
This will download all the objects for the latest
tag of cityofnewyork-us/2018-prek-school-directory-xck4-5xd5
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/2018-prek-school-directory-xck4-5xd5: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/2018-prek-school-directory-xck4-5xd5: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/2018-prek-school-directory-xck4-5xd5
is just another Postgres schema.