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 city_clerk
table in this repository, by referencing it like:
"citydata-mesaaz-gov/city-clerk-tf5h-bcv2:latest"."city_clerk"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"council_minutes_posted", -- Total number of Council meeting minutes posted for the public within two working days after Council approval, which is in compliance with the Open Meeting Law (regular, special, committee, budget).
"hours_spent_transcribing_council_minutes", -- Hours spent transcribing Council minutes
"in_person_early_votes", -- Total number of early voters who visit the City Clerk’s office to cast votes in-person during the early voting period.
"candidate_and_committee_filings", -- Candidate and Committee Filings
"percent_of_registered_voters_voting_in_primary_general", -- Percent of Registered Voters voting in Primary/General
"public_safety_disability", -- Total number of Accidental or Ordinary Disability Retirement applications received and processed by Sworn Police and Fire employees. The applications are also counted within the month they are discussed and considered by the Fire and/or Police Pension Boards.
"special_projects_and_research_projects", -- Unique projects that fall outside of normal daily duties.
"election_web_pages_accessed", -- Total number of unique visits to the City Clerks' Election web pages.
"public_records_requests_for_clerk_office", -- Total number of public record requests submitted to the City of Mesa, excluding those for the Police Department and Development Services.
"requests_for_election_related_information_and_voter_assistance", -- Total number of calls received that were specifically related to election information and/or voter assistance
"notaries_performed", -- Total number of notary services provided by the City Clerk’s Office.
"year", -- Year
"inquiries_tasks_related_to_advisory_boards_and_committees", -- Total number of inquiries made, or tasks performed related to the management of Advisory Boards and Committees.
"hours_in_attendance_at_council_meeting", -- Hours in attendance at Council meeting
"legal_ads_published", -- Legal Ads Published
"public_meeting_notices", -- Total number of meeting notices (boards, committees, etc.) posted in compliance with the Open Meeting Law, which is no less than 24-hours prior to the meeting being held.
"records_retention_inquiries", -- Total number of requests for assistance received from other City staff pertaining to records retention schedules and information.
"election_pamphlets_mailed", -- Total number of publicity pamphlets mailed to registered households, as required by law to ensure voters receive them prior to the start of early voting. The number fluctuates by year based on whether it is an election year.
"projects_tasks_related_to_govqa_software_management", -- Total number of research projects, tasks, and updates made related to managing the GovQA software.
"public_records_requests_city_processed_through_govqa", -- Total number of public record requests received for the City Clerk’s Office to satisfy
"legal_service_documents", -- Total number of summons, claims, subpoenas, and garnishments submitted to the City Clerk's Office and forwarded to City Attorney's Office within 24 hours.
"requests_for_information", -- Total number of requests received (from the public or internally) for information that is non-election related.
"month", -- Month
"special_projects_and_research_projects_hours", -- Special Projects and Research Projects - Hours
"psprs_retirement_and_drop", -- Refers to participants in the Public Safety Personnel Retirement System (PSPRS) and Deferred Retirement Option Plan (DROP). Total number of retirement applications received from Sworn Police and Fire employees and processed within the month they are discussed and considered by the Fire and/or Police Pension Boards.
"community_engagement_activities_attended", -- Community Engagement Activities attended
"ordinances_published_after_council_adoption", -- Ordinances Published after Council Adoption
"advisory_board_committee_applications_submitted", -- Total number of applications submitted for City of Mesa Advisory Boards or Committees.
"date" -- Month Year format
FROM
"citydata-mesaaz-gov/city-clerk-tf5h-bcv2:latest"."city_clerk"
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 citydata-mesaaz-gov/city-clerk-tf5h-bcv2
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at citydata.mesaaz.gov. When you querycitydata-mesaaz-gov/city-clerk-tf5h-bcv2: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
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 (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 clone
and sgr checkout
.
Mounting Data
This repository is an external repository. It's not hosted by Splitgraph. It is hosted by citydata.mesaaz.gov, 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 \
"citydata-mesaaz-gov/city-clerk-tf5h-bcv2" \
--handler-options '{
"domain": "citydata.mesaaz.gov",
"tables": {
"city_clerk": "tf5h-bcv2"
}
}'
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, citydata-mesaaz-gov/city-clerk-tf5h-bcv2
is just another Postgres schema.