使用 Google Cloud 控制台查询公共数据集
了解如何使用 Google Cloud 控制台在 BigQuery 中查找和查询公共数据集。
如需在 Google Cloud 控制台中直接遵循有关此任务的分步指导,请点击操作演示:
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往 IAM - 选择项目。
- 点击 授予访问权限。
-
在新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。
- 在选择角色列表中,选择一个角色。
- 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
- 点击 Save(保存)。
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往 IAM - 选择项目。
- 点击 授予访问权限。
-
在新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。
- 在选择角色列表中,选择一个角色。
- 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
- 点击 Save(保存)。
-
-
Verify that billing is enabled for your Google Cloud project.
确保已启用 BigQuery API。
如果您创建了一个新项目,则系统会自动启用 BigQuery API。
在 Google Cloud 控制台中,前往 BigQuery 页面。
在探索器窗格中,点击
+添加数据 。在添加数据对话框中的过滤条件窗格中,点击
公共数据集。
您可以使用搜索 Marketplace 字段或过滤条件来缩小搜索范围。
选择一个数据集,然后点击查看数据集。
在探索器窗格中,您的数据集处于选中状态,您可以查看其详细信息。
可选:点击数据集旁边的
查看操作可查看更多选项。每个数据集都包含一些表,您可以通过点击任何数据集旁边的
切换节点来查看这些表。在 Google Cloud 控制台中,前往 BigQuery 页面。
点击
SQL 查询 。在
查询编辑器 中,复制以下查询:SELECT name, SUM(number) AS total FROM `bigquery-public-data.usa_names.usa_1910_2013` GROUP BY name ORDER BY total DESC LIMIT 10;
如果查询有效,则会显示一个对勾标记以及查询处理的数据量。如果查询无效,则会显示一个感叹号,并会显示错误消息。
点击
运行 。查询结果部分列出了最常见的名字。该表的标题行包含您在查询中选择的每个列名称。
可选:如需显示查询处理的时长和数据量,请点击
查询结果 部分中的作业信息标签页。- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- 了解 BigQuery 沙盒。
- 了解如何在Google Cloud 控制台中创建数据集和查询表。
- 了解 BigQuery 动态。
- 了解 BigQuery 定价。
- 了解 BigQuery 配额和限制。
如果您没有为本教程中使用的 Google Cloud 项目启用结算功能,则需要在 BigQuery 沙盒中上传和处理数据。借助 BigQuery 沙盒,您可以免费使用限定的 BigQuery 功能,了解 BigQuery。
打开公共数据集
默认情况下,BigQuery 公共数据集可以通过Google Cloud 控制台使用。
在以下示例中,您可以访问公共项目 bigquery-public-data
中的数据集。
查询公共数据集
在以下步骤中,您将查询“USA Names”(美国人名)公共数据集,以确定 1910 年至 2013 年期间美国最常用的名字:
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
删除项目
如果您使用 BigQuery 沙盒查询公共数据集,则您的项目不会启用结算功能。
为了避免产生费用,最简单的方法是删除您为本教程创建的项目。
要删除项目,请执行以下操作: