Query a public dataset with the BigQuery client libraries
Learn how to query a public dataset with the BigQuery clientlibraries.
To follow step-by-step guidance for this task directly in theGoogle Cloud console, select your preferred programming language:
C#
Go
Java
Node.js
PHP
Python
Ruby
Before you begin
Create or select a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Create a Google Cloud project:
gcloud projects createPROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating.Select the Google Cloud project that you created:
gcloud config set projectPROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name.
Choose whether touse the BigQuery sandbox at no charge,or toenable billing for your Google Cloud project.
If you do not enable billing for a project, you automatically work in theBigQuery sandbox. The BigQuery sandbox lets you learnBigQuery with a limited set of BigQueryfeatures at no charge. If you do not plan to use your project beyond thisdocument, we recommend that you use the BigQuery sandbox.
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/serviceusage.serviceUsageAdmin, roles/bigquery.jobUsergcloudprojectsadd-iam-policy-bindingPROJECT_ID--member="user:USER_IDENTIFIER"--role=ROLE
Replace the following:
PROJECT_ID: Your project ID.USER_IDENTIFIER: The identifier for your user account. For example,myemail@example.com.ROLE: The IAM role that you grant to your user account.
Enable the BigQuery API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.gcloudservicesenablebigqueryFor new projects, the BigQuery API is automatically enabled.
In the Google Cloud console, activate Cloud Shell.
Activate your Google Cloud project in Cloud Shell:
gcloudconfigsetprojectPROJECT_IDReplacePROJECT_ID with the project that you selected forthis walkthrough.
The output is similar to the following:
Updated property [core/project].
Query a public dataset
Select one of the following languages:
C#
In Cloud Shell, create a new C# project and file:
dotnetnewconsole-nBigQueryCsharpDemo
The output is similar to the following. Several lines are omitted tosimplify the output.
Welcome to .NET 6.0!---------------------SDK Version: 6.0.407...The template "Console App" was created successfully....
This command creates a C# project that's named
BigQueryCsharpDemoand a file that's namedProgram.cs.Open the Cloud Shell Editor:
cloudshellworkspaceBigQueryCsharpDemo
To open a terminal in the Cloud Shell Editor, clickOpen Terminal.
Open your project directory:
cdBigQueryCsharpDemoInstall the BigQuery client library for C#:
dotnetaddpackageGoogle.Cloud.BigQuery.V2
The output is similar to the following. Several lines are omitted tosimplify the output.
Determining projects to restore...Writing /tmp/tmpF7EKSd.tmp...info : Writing assets file to disk....
Set the variable
GOOGLE_PROJECT_IDto the valueGOOGLE_CLOUD_PROJECTand export the variable:exportGOOGLE_PROJECT_ID=$GOOGLE_CLOUD_PROJECT
ClickOpen Editor.
In theExplorer pane, locate your
BIGQUERYCSHARPDEMOproject.Click the
Program.csfile to open it.To create a query against the
bigquery-public-data.stackoverflowdataset that returns thetop 10 most viewed Stack Overflow pages and their view counts, replacethe contents of the file with the following code:usingSystem;usingGoogle.Cloud.BigQuery.V2;namespaceGoogleCloudSamples{publicclassProgram{publicstaticvoidMain(string[]args){stringprojectId=Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID");varclient=BigQueryClient.Create(projectId);stringquery=@"SELECT CONCAT( 'https://stackoverflow.com/questions/', CAST(id as STRING)) as url, view_count FROM `bigquery-public-data.stackoverflow.posts_questions` WHERE tags like '%google-bigquery%' ORDER BY view_count DESC LIMIT 10";varresult=client.ExecuteQuery(query,parameters:null);Console.Write("\nQuery Results:\n------------\n");foreach(varrowinresult){Console.WriteLine($"{row["url"]}: {row["view_count"]} views");}}}}ClickOpen Terminal.
In the terminal, run the
Program.csscript. If you are prompted toauthorize Cloud Shell and agree to the terms, clickAuthorize.dotnetrun
The result is similar to the following:
Query Results:------------https://stackoverflow.com/questions/35159967: 170023 viewshttps://stackoverflow.com/questions/22879669: 142581 viewshttps://stackoverflow.com/questions/10604135: 132406 viewshttps://stackoverflow.com/questions/44564887: 128781 viewshttps://stackoverflow.com/questions/27060396: 127008 viewshttps://stackoverflow.com/questions/12482637: 120766 viewshttps://stackoverflow.com/questions/20673986: 115720 viewshttps://stackoverflow.com/questions/39109817: 108368 viewshttps://stackoverflow.com/questions/11057219: 105175 viewshttps://stackoverflow.com/questions/43195143: 101878 views
You have successfully queried a public dataset with theBigQuery C# client library.
Go
In Cloud Shell, create a new Go project and file:
mkdirbigquery-go-quickstart\&&touch\bigquery-go-quickstart/app.go
This command creates a Go project that's named
bigquery-go-quickstartand a file that's namedapp.go.Open the Cloud Shell Editor:
cloudshellworkspacebigquery-go-quickstart
To open a terminal in the Cloud Shell Editor, clickOpen Terminal.
Open your project directory:
cdbigquery-go-quickstartCreate a
go.modfile:gomodinitquickstart
The output is similar to the following:
go: creating new go.mod: module quickstartgo: to add module requirements and sums: go mod tidy
Install the BigQuery client library for Go:
gogetcloud.google.com/go/bigquery
The output is similar to the following. Several lines are omitted tosimplify the output.
go: downloading cloud.google.com/go/bigquery v1.49.0go: downloading cloud.google.com/go v0.110.0...go: added cloud.google.com/go/bigquery v1.49.0go: added cloud.google.com/go v0.110.0
ClickOpen Editor.
In theExplorer pane, locate your
BIGQUERY-GO-QUICKSTARTproject.Click the
app.gofile to open it.To create a query against the
bigquery-public-data.stackoverflowdataset that returns thetop 10 most viewed Stack Overflow pages and their view counts, copy thefollowing code into theapp.gofile:// Command simpleapp queries the Stack Overflow public dataset in Google BigQuery.packagemainimport("context""fmt""io""log""os""cloud.google.com/go/bigquery""google.golang.org/api/iterator")funcmain(){projectID:=os.Getenv("GOOGLE_CLOUD_PROJECT")ifprojectID==""{fmt.Println("GOOGLE_CLOUD_PROJECT environment variable must be set.")os.Exit(1)}ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{log.Fatalf("bigquery.NewClient: %v",err)}deferclient.Close()rows,err:=query(ctx,client)iferr!=nil{log.Fatal(err)}iferr:=printResults(os.Stdout,rows);err!=nil{log.Fatal(err)}}// query returns a row iterator suitable for reading query results.funcquery(ctxcontext.Context,client*bigquery.Client)(*bigquery.RowIterator,error){query:=client.Query(`SELECTCONCAT('https://stackoverflow.com/questions/',CAST(id as STRING)) as url,view_countFROM `+"`bigquery-public-data.stackoverflow.posts_questions`"+`WHERE tags like '%google-bigquery%'ORDER BY view_count DESCLIMIT 10;`)returnquery.Read(ctx)}typeStackOverflowRowstruct{URLstring`bigquery:"url"`ViewCountint64`bigquery:"view_count"`}// printResults prints results from a query to the Stack Overflow public dataset.funcprintResults(wio.Writer,iter*bigquery.RowIterator)error{for{varrowStackOverflowRowerr:=iter.Next(&row)iferr==iterator.Done{returnnil}iferr!=nil{returnfmt.Errorf("error iterating through results: %w",err)}fmt.Fprintf(w,"url: %s views: %d\n",row.URL,row.ViewCount)}}ClickOpen Terminal.
In the terminal, run the
app.goscript. If you are prompted toauthorize Cloud Shell and agree to the terms, clickAuthorize.gorunapp.go
The result is similar to the following:
https://stackoverflow.com/questions/35159967 : 170023 viewshttps://stackoverflow.com/questions/22879669 : 142581 viewshttps://stackoverflow.com/questions/10604135 : 132406 viewshttps://stackoverflow.com/questions/44564887 : 128781 viewshttps://stackoverflow.com/questions/27060396 : 127008 viewshttps://stackoverflow.com/questions/12482637 : 120766 viewshttps://stackoverflow.com/questions/20673986 : 115720 viewshttps://stackoverflow.com/questions/39109817 : 108368 viewshttps://stackoverflow.com/questions/11057219 : 105175 viewshttps://stackoverflow.com/questions/43195143 : 101878 views
You have successfully queried a public dataset with theBigQuery Go client library.
Java
In Cloud Shell, create a new Java project using Apache Maven:
mvnarchetype:generate\-DgroupId=com.google.app\-DartifactId=bigquery-java-quickstart\-DinteractiveMode=false
This command creates a Maven project that's named
bigquery-java-quickstart.The output is similar to the following. Several lines are omitted tosimplify the output.
[INFO] Scanning for projects......[INFO] Building Maven Stub Project (No POM) 1...[INFO] BUILD SUCCESS...
There are many dependency management systems that you can use other thanMaven. For more information, learn how toset up a Java development environment to use withclient libraries.
Rename the
App.javafile that Maven creates by default:mv\bigquery-java-quickstart/src/main/java/com/google/app/App.java\bigquery-java-quickstart/src/main/java/com/google/app/SimpleApp.java
Open the Cloud Shell Editor:
cloudshellworkspacebigquery-java-quickstart
If you are prompted whether to synchronize the Javaclasspath or configuration, clickAlways.
If you are not prompted and encounter an error that isrelated to the classpath during this walkthrough, do the following:
- ClickFile> Preferences> Open Settings (UI).
- ClickExtensions> Java.
- Scroll toConfiguration: Update Build Configuration and selectautomatic.
In theExplorer pane, locate your
BIGQUERY-JAVA-QUICKSTARTproject.Click the
pom.xmlfile to open it.Inside the
<dependencies>tag, add the following dependencyafter any existing ones. Do not replace any existing dependencies.<dependency><groupId>com.google.cloud</groupId><artifactId>google-cloud-bigquery</artifactId></dependency>On the line following the closing tag (
</dependencies>), add thefollowing:<dependencyManagement><dependencies><dependency><groupId>com.google.cloud</groupId><artifactId>libraries-bom</artifactId><version>26.1.5</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>In theExplorer pane, in your
BIGQUERY-JAVA-QUICKSTARTproject,clicksrc> main/java/com/google/app> SimpleApp.java.The file opens.To create a query against the
bigquery-public-data.stackoverflowdataset, leave thefirst line of the file (package com.google.app;), and replace theremaining contents of the file with the following code:importcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.FieldValueList;importcom.google.cloud.bigquery.Job;importcom.google.cloud.bigquery.JobId;importcom.google.cloud.bigquery.JobInfo;importcom.google.cloud.bigquery.QueryJobConfiguration;importcom.google.cloud.bigquery.TableResult;publicclassSimpleApp{publicstaticvoidmain(String...args)throwsException{// TODO(developer): Replace these variables before running the app.StringprojectId="MY_PROJECT_ID";simpleApp(projectId);}publicstaticvoidsimpleApp(StringprojectId){try{BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();QueryJobConfigurationqueryConfig=QueryJobConfiguration.newBuilder("SELECT CONCAT('https://stackoverflow.com/questions/', "+"CAST(id as STRING)) as url, view_count "+"FROM `bigquery-public-data.stackoverflow.posts_questions` "+"WHERE tags like '%google-bigquery%' "+"ORDER BY view_count DESC "+"LIMIT 10")// Use standard SQL syntax for queries.// See: https://cloud.google.com/bigquery/sql-reference/.setUseLegacySql(false).build();JobIdjobId=JobId.newBuilder().setProject(projectId).build();JobqueryJob=bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());// Wait for the query to complete.queryJob=queryJob.waitFor();// Check for errorsif(queryJob==null){thrownewRuntimeException("Job no longer exists");}elseif(queryJob.getStatus().getExecutionErrors()!=null &&queryJob.getStatus().getExecutionErrors().size() >0){// TODO(developer): Handle errors here. An error here do not necessarily mean that the job// has completed or was unsuccessful.// For more details: https://cloud.google.com/bigquery/troubleshooting-errorsthrownewRuntimeException("An unhandled error has occurred");}// Get the results.TableResultresult=queryJob.getQueryResults();// Print all pages of the results.for(FieldValueListrow:result.iterateAll()){// String typeStringurl=row.get("url").getStringValue();StringviewCount=row.get("view_count").getStringValue();System.out.printf("%s : %s views\n",url,viewCount);}}catch(BigQueryException|InterruptedExceptione){System.out.println("Simple App failed due to error: \n"+e.toString());}}}The query returns the top 10 most viewed Stack Overflow pages andtheir view counts.
Right-clickSimpleApp.java and clickRun Java. If you areprompted to authorize Cloud Shell and agree to the terms, clickAuthorize.
The result is similar to the following:
https://stackoverflow.com/questions/35159967 : 170023 viewshttps://stackoverflow.com/questions/22879669 : 142581 viewshttps://stackoverflow.com/questions/10604135 : 132406 viewshttps://stackoverflow.com/questions/44564887 : 128781 viewshttps://stackoverflow.com/questions/27060396 : 127008 viewshttps://stackoverflow.com/questions/12482637 : 120766 viewshttps://stackoverflow.com/questions/20673986 : 115720 viewshttps://stackoverflow.com/questions/39109817 : 108368 viewshttps://stackoverflow.com/questions/11057219 : 105175 viewshttps://stackoverflow.com/questions/43195143 : 101878 views
You have successfully queried a public dataset with theBigQuery Java client library.
Node.js
In Cloud Shell, create a new Node.js project and file:
mkdirbigquery-node-quickstart\&&touch\bigquery-node-quickstart/app.js
This command creates a Node.js project that's named
bigquery-node-quickstartand a file that's namedapp.js.Open the Cloud Shell Editor:
cloudshellworkspacebigquery-node-quickstart
To open a terminal in the Cloud Shell Editor, clickOpen Terminal.
Open your project directory:
cdbigquery-node-quickstartInstall the BigQuery client library for Node.js:
npminstall@google-cloud/bigquery
The output is similar to the following:
added 63 packages in 2s
ClickOpen Editor.
In theExplorer pane, locate your
BIGQUERY-NODE-QUICKSTARTproject.Click the
app.jsfile to open it.To create a query against the
bigquery-public-data.stackoverflowdataset that returns thetop 10 most viewed Stack Overflow pages and their view counts, copy thefollowing code into theapp.jsfile:// Import the Google Cloud client libraryconst{BigQuery}=require('@google-cloud/bigquery');asyncfunctionqueryStackOverflow(){// Queries a public Stack Overflow dataset.// Create a clientconstbigqueryClient=newBigQuery();// The SQL query to runconstsqlQuery=`SELECT CONCAT( 'https://stackoverflow.com/questions/', CAST(id as STRING)) as url, view_count FROM \`bigquery-public-data.stackoverflow.posts_questions\` WHERE tags like '%google-bigquery%' ORDER BY view_count DESC LIMIT 10`;constoptions={query:sqlQuery,// Location must match that of the dataset(s) referenced in the query.location:'US',};// Run the queryconst[rows]=awaitbigqueryClient.query(options);console.log('Query Results:');rows.forEach(row=>{consturl=row['url'];constviewCount=row['view_count'];console.log(`url:${url},${viewCount} views`);});}queryStackOverflow();ClickOpen Terminal.
In the terminal, run the
app.jsscript. If you are prompted toauthorize Cloud Shell and agree to the terms, clickAuthorize.nodeapp.js
The result is similar to the following:
Query Results:url: https://stackoverflow.com/questions/35159967, 170023 viewsurl: https://stackoverflow.com/questions/22879669, 142581 viewsurl: https://stackoverflow.com/questions/10604135, 132406 viewsurl: https://stackoverflow.com/questions/44564887, 128781 viewsurl: https://stackoverflow.com/questions/27060396, 127008 viewsurl: https://stackoverflow.com/questions/12482637, 120766 viewsurl: https://stackoverflow.com/questions/20673986, 115720 viewsurl: https://stackoverflow.com/questions/39109817, 108368 viewsurl: https://stackoverflow.com/questions/11057219, 105175 viewsurl: https://stackoverflow.com/questions/43195143, 101878 views
You have successfully queried a public dataset with theBigQuery Node.js client library.
PHP
In Cloud Shell, create a new PHP project and file:
mkdirbigquery-php-quickstart\&&touch\bigquery-php-quickstart/app.php
This command creates a PHP project that's named
bigquery-php-quickstartand a file that's namedapp.php.Open the Cloud Shell Editor:
cloudshellworkspacebigquery-php-quickstart
To open a terminal in the Cloud Shell Editor, clickOpen Terminal.
Open your project directory:
cdbigquery-php-quickstartInstall the BigQuery client library for PHP:
composerrequiregoogle/cloud-bigquery
The output is similar to the following. Several lines are omitted tosimplify the output.
Running composer update google/cloud-bigqueryLoading composer repositories with package informationUpdating dependencies...No security vulnerability advisories foundUsing version ^1.24 for google/cloud-bigquery
ClickOpen Editor.
In theExplorer pane, locate your
BIGQUERY-PHP-QUICKSTARTproject.Click the
app.phpfile to open it.To create a query against the
bigquery-public-data.stackoverflowdataset that returns thetop 10 most viewed Stack Overflow pages and their view counts, copy thefollowing code into theapp.phpfile:<?php# ...require __DIR__ . '/vendor/autoload.php';use Google\Cloud\BigQuery\BigQueryClient;$bigQuery = new BigQueryClient();$query = <<<ENDSQLSELECT CONCAT( 'https://stackoverflow.com/questions/', CAST(id as STRING)) as url, view_countFROM `bigquery-public-data.stackoverflow.posts_questions`WHERE tags like '%google-bigquery%'ORDER BY view_count DESCLIMIT 10;ENDSQL;$queryJobConfig = $bigQuery->query($query);$queryResults = $bigQuery->runQuery($queryJobConfig);if ($queryResults->isComplete()) { $i = 0; $rows = $queryResults->rows(); foreach ($rows as $row) { printf('--- Row %s ---' . PHP_EOL, ++$i); printf('url: %s, %s views' . PHP_EOL, $row['url'], $row['view_count']); } printf('Found %s row(s)' . PHP_EOL, $i);} else { throw new Exception('The query failed to complete');}ClickOpen Terminal.
In the terminal, run the
app.phpscript. If you are prompted toauthorize Cloud Shell and agree to the terms, clickAuthorize.phpapp.php
The result is similar to the following:
--- Row 1 ---url: https://stackoverflow.com/questions/35159967, 170023 views--- Row 2 ---url: https://stackoverflow.com/questions/22879669, 142581 views--- Row 3 ---url: https://stackoverflow.com/questions/10604135, 132406 views--- Row 4 ---url: https://stackoverflow.com/questions/44564887, 128781 views--- Row 5 ---url: https://stackoverflow.com/questions/27060396, 127008 views--- Row 6 ---url: https://stackoverflow.com/questions/12482637, 120766 views--- Row 7 ---url: https://stackoverflow.com/questions/20673986, 115720 views--- Row 8 ---url: https://stackoverflow.com/questions/39109817, 108368 views--- Row 9 ---url: https://stackoverflow.com/questions/11057219, 105175 views--- Row 10 ---url: https://stackoverflow.com/questions/43195143, 101878 viewsFound 10 row(s)
You have successfully queried a public dataset with theBigQuery PHP client library.
Python
In Cloud Shell, create a new Python project and file:
mkdirbigquery-python-quickstart\&&touch\bigquery-python-quickstart/app.py
This command creates a Python project that's named
bigquery-python-quickstartand a file that's namedapp.py.Open the Cloud Shell Editor:
cloudshellworkspacebigquery-python-quickstart
To open a terminal in the Cloud Shell Editor, clickOpen Terminal.
Open your project directory:
cdbigquery-python-quickstartInstall the BigQuery client library for Python:
pipinstall--upgradegoogle-cloud-bigquery
The output is similar to the following. Several lines are omitted tosimplify the output.
Installing collected packages: google-cloud-bigquery...Successfully installed google-cloud-bigquery-3.9.0...
ClickOpen Editor.
In theExplorer pane, locate your
BIGQUERY-PYTHON-QUICKSTARTproject.Click the
app.pyfile to open it.To create a query against the
bigquery-public-data.stackoverflowdataset that returns thetop 10 most viewed Stack Overflow pages and their view counts, copy thefollowing code into theapp.pyfile:fromgoogle.cloudimportbigquerydefquery_stackoverflow()->None:client=bigquery.Client()results=client.query_and_wait(""" SELECT CONCAT( 'https://stackoverflow.com/questions/', CAST(id as STRING)) as url, view_count FROM `bigquery-public-data.stackoverflow.posts_questions` WHERE tags like '%google-bigquery%' ORDER BY view_count DESC LIMIT 10""")# Waits for job to complete.forrowinresults:print("{} :{} views".format(row.url,row.view_count))if__name__=="__main__":query_stackoverflow()ClickOpen Terminal.
In the terminal, run the
app.pyscript. If you are prompted toauthorize Cloud Shell and agree to the terms, clickAuthorize.pythonapp.py
The result is similar to the following:
https://stackoverflow.com/questions/35159967 : 170023 viewshttps://stackoverflow.com/questions/22879669 : 142581 viewshttps://stackoverflow.com/questions/10604135 : 132406 viewshttps://stackoverflow.com/questions/44564887 : 128781 viewshttps://stackoverflow.com/questions/27060396 : 127008 viewshttps://stackoverflow.com/questions/12482637 : 120766 viewshttps://stackoverflow.com/questions/20673986 : 115720 viewshttps://stackoverflow.com/questions/39109817 : 108368 viewshttps://stackoverflow.com/questions/11057219 : 105175 viewshttps://stackoverflow.com/questions/43195143 : 101878 views
You have successfully queried a public dataset with theBigQuery Python client library.
Ruby
In Cloud Shell, create a new Ruby project and file:
mkdirbigquery-ruby-quickstart\&&touch\bigquery-ruby-quickstart/app.rb
This command creates a Ruby project that's named
bigquery-ruby-quickstartand a file that's namedapp.rb.Open the Cloud Shell Editor:
cloudshellworkspacebigquery-ruby-quickstart
To open a terminal in the Cloud Shell Editor, clickOpen Terminal.
Open your project directory:
cdbigquery-ruby-quickstartInstall the BigQuery client library for Ruby:
geminstallgoogle-cloud-bigquery
The output is similar to the following. Several lines are omitted tosimplify the output.
23 gems installed
ClickOpen Editor.
In theExplorer pane, locate your
BIGQUERY-RUBY-QUICKSTARTproject.Click the
app.rbfile to open it.To create a query against the
bigquery-public-data.stackoverflowdataset that returns thetop 10 most viewed Stack Overflow pages and their view counts, copy thefollowing code into theapp.rbfile:require"google/cloud/bigquery"# This uses Application Default Credentials to authenticate.# @see https://cloud.google.com/bigquery/docs/authentication/getting-startedbigquery=Google::Cloud::Bigquery.newsql="SELECT "\"CONCAT('https://stackoverflow.com/questions/', CAST(id as STRING)) as url, view_count "\"FROM `bigquery-public-data.stackoverflow.posts_questions` "\"WHERE tags like '%google-bigquery%' "\"ORDER BY view_count DESC LIMIT 10"results=bigquery.querysqlresults.eachdo|row|puts"#{row[:url]}:#{row[:view_count]} views"endClickOpen Terminal.
In the terminal, run the
app.rbscript. If you are prompted toauthorize Cloud Shell and agree to the terms, clickAuthorize.rubyapp.rb
The result is similar to the following:
https://stackoverflow.com/questions/35159967: 170023 viewshttps://stackoverflow.com/questions/22879669: 142581 viewshttps://stackoverflow.com/questions/10604135: 132406 viewshttps://stackoverflow.com/questions/44564887: 128781 viewshttps://stackoverflow.com/questions/27060396: 127008 viewshttps://stackoverflow.com/questions/12482637: 120766 viewshttps://stackoverflow.com/questions/20673986: 115720 viewshttps://stackoverflow.com/questions/39109817: 108368 viewshttps://stackoverflow.com/questions/11057219: 105175 viewshttps://stackoverflow.com/questions/43195143: 101878 views
You have successfully queried a public dataset with theBigQuery Ruby client library.
Clean up
To avoid incurring charges to your Google Cloud account, either deleteyour Google Cloud project, or delete the resources that you created inthis walkthrough.
Delete the project
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
Delete the resources
If you used an existing project, delete the resources that you created:
C#
In Cloud Shell, move up a directory:
cd..Delete the
BigQueryCsharpDemofolder that you created:rm-RBigQueryCsharpDemo
The
-Rflag deletes all assets in a folder.
Go
In Cloud Shell, move up a directory:
cd..Delete the
bigquery-go-quickstartfolder that you created:rm-Rbigquery-go-quickstart
The
-Rflag deletes all assets in a folder.
Java
In Cloud Shell, move up a directory:
cd..Delete the
bigquery-java-quickstartfolder that you created:rm-Rbigquery-java-quickstart
The
-Rflag deletes all assets in a folder.
Node.js
In Cloud Shell, move up a directory:
cd..Delete the
bigquery-node-quickstartfolder that you created:rm-Rbigquery-node-quickstart
The
-Rflag deletes all assets in a folder.
PHP
In Cloud Shell, move up a directory:
cd..Delete the
bigquery-php-quickstartfolder that you created:rm-Rbigquery-php-quickstart
The
-Rflag deletes all assets in a folder.
Python
In Cloud Shell, move up a directory:
cd..Delete the
bigquery-python-quickstartfolder that you created:rm-Rbigquery-python-quickstart
The
-Rflag deletes all assets in a folder.
Ruby
In Cloud Shell, move up a directory:
cd..Delete the
bigquery-ruby-quickstartfolder that you created:rm-Rbigquery-ruby-quickstart
The
-Rflag deletes all assets in a folder.
What's next
- Learn more about using theBigQuery client libraries.
- Learn more aboutBigQuery public datasets.
- Learn how toload data into BigQuery.
- Learn more aboutquerying data in BigQuery.
- Getupdates about BigQuery.
- Learn aboutBigQuery pricing.
- Learn aboutBigQuery quotas and limits.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.