使用 Google Cloud 控制台查询公共数据集

了解如何使用 Google Cloud 控制台在 BigQuery 中查找和查询公共数据集。


如需在 Google Cloud 控制台中直接遵循有关此任务的分步指导,请点击操作演示

操作演示


准备工作

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

    4. 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

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 选择项目。
    3. 点击 授予访问权限
    4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

    5. 选择角色列表中,选择一个角色。
    6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
    7. 点击 Save(保存)。
  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

    4. 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

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 选择项目。
    3. 点击 授予访问权限
    4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

    5. 选择角色列表中,选择一个角色。
    6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
    7. 点击 Save(保存)。
  6. Make sure that billing is enabled for your Google Cloud project.

  7. 如果您没有为本教程中使用的 Google Cloud 项目启用结算功能,则需要在 BigQuery 沙盒中上传和处理数据。借助 BigQuery 沙盒,您可以免费使用限定的 BigQuery 功能,了解 BigQuery。

  8. 确保已启用 BigQuery API。

    启用 API

    如果您创建了一个新项目,则系统会自动启用 BigQuery API。

打开公共数据集

默认情况下,BigQuery 公共数据集可以通过Google Cloud 控制台使用。

在以下示例中,您可以访问公共项目 bigquery-public-data 中的数据集。

  1. 在 Google Cloud 控制台中,前往 BigQuery 页面。

    转到 BigQuery

  2. 探索器窗格中,点击 +添加数据

  3. 添加数据对话框中的过滤条件窗格中,点击 公共数据集图标。 公共数据集

  4. 您可以使用搜索 Marketplace 字段或过滤条件来缩小搜索范围。

  5. 选择一个数据集,然后点击查看数据集

    探索器窗格中,您的数据集处于选中状态,您可以查看其详细信息。

  6. 可选:点击数据集旁边的 查看操作可查看更多选项。

    每个数据集都包含一些表,您可以通过点击任何数据集旁边的 切换节点来查看这些表。

查询公共数据集

在以下步骤中,您将查询“USA Names”(美国人名)公共数据集,以确定 1910 年至 2013 年期间美国最常用的名字:

  1. 在 Google Cloud 控制台中,前往 BigQuery 页面。

    转到 BigQuery

  2. 点击 SQL 查询

  3. 查询编辑器中,复制以下查询:

    SELECT
      name,
      SUM(number) AS total
    FROM
      `bigquery-public-data.usa_names.usa_1910_2013`
    GROUP BY
      name
    ORDER BY
      total DESC
    LIMIT
      10;
    

    如果查询有效,则会显示一个对勾标记以及查询处理的数据量。如果查询无效,则会显示一个感叹号,并会显示错误消息。

    查询验证器。

  4. 点击运行

    查询结果部分列出了最常见的名字。该表的标题行包含您在查询中选择的每个列名称。

     Google Cloud 控制台中的查询结果。

  5. 可选:如需显示查询处理的时长和数据量,请点击查询结果部分中的作业信息标签页。

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。

删除项目

如果您使用 BigQuery 沙盒查询公共数据集,则您的项目不会启用结算功能。

为了避免产生费用,最简单的方法是删除您为本教程创建的项目。

要删除项目,请执行以下操作:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

后续步骤