	
	<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.title=Learning+BigQuery+%2B+Google+Sheets+I&amp;rft.aulast=Yee&amp;rft.aufirst=Raymond&amp;rft.subject=MyBizWriMo&amp;rft.source=Hypotyposis+on+a+Good+Day&amp;rft.date=2017-11-07&amp;rft.type=blogPost&amp;rft.format=text&amp;rft.identifier=https://hypotyposis.net/blog/2017/11/07/bigquery-sheets-1/&amp;rft.language=English"></span>
	
	<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;rft.title=Learning+BigQuery+%2B+Google+Sheets+I&amp;rft.aulast=Yee&amp;rft.aufirst=Raymond&amp;rft.subject=MyBizWriMo&amp;rft.source=Hypotyposis+on+a+Good+Day&amp;rft.date=2017-11-07&amp;rft.type=blogPost&amp;rft.format=text&amp;rft.identifier=https://hypotyposis.net/blog/2017/11/07/bigquery-sheets-1/&amp;rft.language=English"></span>
{"id":1123,"date":"2017-11-07T18:47:19","date_gmt":"2017-11-08T01:47:19","guid":{"rendered":"https:\/\/hypotyposis.net\/blog\/?p=1123"},"modified":"2017-11-07T18:47:19","modified_gmt":"2017-11-08T01:47:19","slug":"bigquery-sheets-1","status":"publish","type":"post","link":"https:\/\/hypotyposis.net\/blog\/2017\/11\/07\/bigquery-sheets-1\/","title":{"rendered":"Learning BigQuery + Google Sheets I"},"content":{"rendered":"<p>I went down the road of studying <a href=\"https:\/\/cloud.google.com\/bigquery\/\">BigQuery<\/a> and <a href=\"https:\/\/www.google.com\/sheets\/about\/\">Google Sheets<\/a>, inspired by a <a href=\"https:\/\/www.facebook.com\/rdhyee\/posts\/10107083126354813?comment_id=10107083451353513&amp;reply_comment_id=10107083801611593&amp;comment_tracking=%7B%22tn%22%3A%22R3%22%7D\">suggestion<\/a> from <a href=\"https:\/\/twitter.com\/doubleocherry?lang=en\">Michael Manoochehri<\/a>:<\/p>\n<blockquote><p>\n  a powerful and lucrative integration is BigQuery\/Google Sheets via Apps Script. Some of our customers use this combo for report generation once we (Switchboard) provide foundational data in BigQuery\n<\/p><\/blockquote>\n<p><a href=\"https:\/\/cloud.google.com\/bigquery\/what-is-bigquery\">What is BigQuery? \u00c2\u00a0|\u00c2\u00a0 BigQuery \u00c2\u00a0|\u00c2\u00a0 Google Cloud Platform<\/a>:<\/p>\n<blockquote><p>\n  What is BigQuery?<\/p>\n<p>  Storing and querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. Google BigQuery is an enterprise data warehouse that solves this problem by enabling super-fast SQL queries using the processing power of Google's infrastructure. Simply move your data into BigQuery and let us handle the hard work. You can control access to both the project and your data based on your business needs, such as giving others the ability to view or query your data.\n<\/p><\/blockquote>\n<h1>What have I done so far and what are the next steps?<\/h1>\n<p>As a learning exercise, I'm using Apps Script to write out data about all the public datasets into a Google Sheet and creating a visualization of the datasets: <a href=\"https:\/\/script.google.com\/d\/15GCKmDH-yF1NJiwStb0VxR1L7rJD4L-jbX1Rzc3TZArjPW4D4Hxq0hJ1\/edit?usp=sharing\">BigQuery Learning (public view with Google account)<\/a>.  Most of the code in the project is borrowed from the sample tutorial code listed <a href=\"https:\/\/developers.google.com\/apps-script\/advanced\/bigquery\">BigQuery Service \u00c2\u00a0|\u00c2\u00a0 Apps Script \u00c2\u00a0|\u00c2\u00a0 Google Developers<\/a>.  When I run the sample code, whose core functionality is in the SQL query:<\/p>\n<pre><code class=\"SQL\">'SELECT TOP(word, 300) AS word, COUNT(*) AS word_count ' +\n      'FROM publicdata:samples.shakespeare WHERE LENGTH(word) &gt; 10;'\n<\/code><\/pre>\n<p>Roughly translated into plain English, this query says: Compute the 300 most common words whose length is greather than 10 (and the number of times the word occurs) in the public Shakespeare corpus.  The rest of the code then stores that list in a Google Sheet.  Here are the top ten words:<\/p>\n<pre><code>word    word_count\ncounterfeit 28\nremembrance 24\ncountenance 24\nacquaintance    23\nsatisfaction    20\nentertainment   20\ndispleasure 20\nsovereignty 19\nimagination 19\ndisposition 19\n<\/code><\/pre>\n<p>Of the many public data sets to play with, I've chosen the Shakespeare data set, not only because it is used in the Google tutorials, but is small (and therefore you're less likely to spend too much money accidentally doing an inefficient query).<\/p>\n<p>I wrote a non-trivial query on the database to calculate the number of words in each of the corpora: <a href=\"https:\/\/bigquery.cloud.google.com\/savedquery\/233267314801:518c73625e9b4d918e068ce452b579fb\">Shakespeare corpora by descending word count<\/a>.<\/p>\n<p>Does the BigQuery API provide access to saved queries? That is, can list my saved queries, read the content of my queries,  write saved queries and even run them?  (The last function is, on second thoughts, such a big deal since there is already functionality I know in the API to run queries.)<\/p>\n<pre><code class=\"SQL\"> \/* list corpora by descending total number of words *\/\nSELECT\n  corpus,\n  corpus_date,\n  SUM(word_count) AS num_words\nFROM\n  publicdata:samples.shakespeare\nGROUP BY\n  corpus, corpus_date\nORDER BY\n  num_words DESC\n<\/code><\/pre>\n<p>From the query interface, you can see a number of options for what to do with the output of the query, including:<\/p>\n<ul>\n<li>download as CSV<\/li>\n<li>download as JSON<\/li>\n<li>Save as <a href=\"https:\/\/research.google.com\/tables\">Table<\/a><\/li>\n<li>Save as Google Sheets<\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.evernote.com\/shard\/s1\/sh\/9bb91c68-0384-41ad-875c-65818303864c\/332b0470d2134529\/res\/9acf94f8-49b5-468b-abdc-af0ba52341a7\/skitch.png?w=584&#038;ssl=1\" alt=\"Big Query: list corpora by descending total number of words\" title=\"Big Query: list corpora by descending total number of words\" \/><\/p>\n<p>After dipping my toes into using BigQuery on public data sets, I wanted to learn more about the data sets themselves that Google has made available.  And not surprising, you can use BigQuery to learn about the data sets.  Stay tuned for a write up on what I learned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I went down the road of studying BigQuery and Google Sheets, inspired by a suggestion from Michael Manoochehri: a powerful and lucrative integration is BigQuery\/Google Sheets via Apps Script. Some of our customers use this combo for report generation once &hellip; <a href=\"https:\/\/hypotyposis.net\/blog\/2017\/11\/07\/bigquery-sheets-1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[145],"tags":[],"class_list":["post-1123","post","type-post","status-publish","format-standard","hentry","category-mybizwrimo"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7I6qs-i7","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/posts\/1123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/comments?post=1123"}],"version-history":[{"count":2,"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/posts\/1123\/revisions"}],"predecessor-version":[{"id":1125,"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/posts\/1123\/revisions\/1125"}],"wp:attachment":[{"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/media?parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/categories?post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hypotyposis.net\/blog\/wp-json\/wp\/v2\/tags?post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}