Querying BigQuery with DataStation
Requires DataStation 0.7.0+.
Data source setup
First create a new data source in the left sidebar.
Give it a nice name so you easily can find it later. And select BigQuery in the Vendor dropdown.
Project and service token
Fill in your Google project ID and paste in your service account token JSON.
Panel setup
Now create a new panel and select the Database type.
Run a query
Let's pull population data from a public BigQuery dataset. Enter the following query and hit play!
SELECT
*
FROM
`bigquery-public-data`.census_bureau_usa.population_by_zip_2010
ORDER BY population DESC
LIMIT 10
Interesting! But random US zipcodes don't mean very much. So let's grab a public CSV of zipcode data that does include the city and state information.
Load zipcode metadata
Create an new HTTP panel, enter the following URL, and hit play.
https://raw.githubusercontent.com/scpike/us-state-county-zip/master/geo-data.csv
Join the two datasets
Now that we have the top 10 zipcodes by population and a list of zipcodes with names, we can join the two datasets to find the city names of the zipcodes with the greatest population.
Create a new panel and select the Program type. Select SQL as the language. Enter the following query and hit run.
SELECT population, city || ', ' || state
FROM DM_getPanel(0)
LEFT JOIN DM_getPanel(1) ON t_0.zipcode = t_1.zipcode
WHERE t_1.zipcode IS NOT NULL
ORDER BY population DESC;
Note: DataStation doesn't allow you to pick table aliases. They
automatically become t_N
where N
is the string passed to
DM_getPanel()
.
Graph the results
Create a new panel. Change the type to Graph. Select the previous Database panel as the panel source. Then select the X and Y columns you'd like to graph.
Finally, click the play button to generate the graph. You can download the graph as a PNG by clicking the download button.
Note: Ctrl-r is a shortcut for hitting the play button when you are focused on one panel.
About this page
See an error or want to add a clarification? This page is
generated from this file on Github.
Last edited Feb 07, 2022.