如需获得查询 INFORMATION_SCHEMA.SHARED_DATASET_USAGE 视图所需的权限,请让管理员在源项目上为您授予 BigQuery Data Owner (roles/bigquery.dataOwner) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThe \u003ccode\u003eINFORMATION_SCHEMA.SHARED_DATASET_USAGE\u003c/code\u003e view provides near real-time metadata about the consumption of shared dataset tables.\u003c/p\u003e\n"],["\u003cp\u003eQuerying this view requires the \u003ccode\u003ebigquery.datasets.listSharedDatasetUsage\u003c/code\u003e permission, typically granted through the BigQuery Data Owner role.\u003c/p\u003e\n"],["\u003cp\u003eThe schema includes information like project and dataset IDs, job details, subscriber information, and metrics such as rows and bytes processed.\u003c/p\u003e\n"],["\u003cp\u003eData in the view is partitioned by \u003ccode\u003ejob_start_time\u003c/code\u003e and clustered by \u003ccode\u003eproject_id\u003c/code\u003e and \u003ccode\u003edataset_id\u003c/code\u003e, with a retention period of 180 days.\u003c/p\u003e\n"],["\u003cp\u003eQueries must include a region qualifier to specify the location of the metadata, with the query execution location matching the \u003ccode\u003eINFORMATION_SCHEMA\u003c/code\u003e view's region.\u003c/p\u003e\n"]]],[],null,["# INFORMATION_SCHEMA.SHARED_DATASET_USAGE view\n============================================\n\nThe `INFORMATION_SCHEMA.SHARED_DATASET_USAGE` view contains the near real-time\nmetadata about consumption of your shared dataset tables. To get started with\nsharing your data across organizations, see [BigQuery sharing (formerly Analytics Hub)](/bigquery/docs/analytics-hub-introduction).\n\nRequired roles\n--------------\n\n\nTo get the permission that\nyou need to query the `INFORMATION_SCHEMA.SHARED_DATASET_USAGE` view,\n\nask your administrator to grant you the\n\n\n[BigQuery Data Owner](/iam/docs/roles-permissions/bigquery#bigquery.dataOwner) (`roles/bigquery.dataOwner`)\nIAM role on your source project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThis predefined role contains the\n` bigquery.datasets.listSharedDatasetUsage`\npermission,\nwhich is required to\nquery the `INFORMATION_SCHEMA.SHARED_DATASET_USAGE` view.\n\n\nYou might also be able to get\nthis permission\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nSchema\n------\n\nThe underlying data is partitioned by the `job_start_time` column and clustered by `project_id` and `dataset_id`.\n\n\nThe `INFORMATION_SCHEMA.SHARED_DATASET_USAGE` has the following schema:\n\nData retention\n--------------\n\nThe `INFORMATION_SCHEMA.SHARED_DATASET_USAGE` view contains running\njobs and the job history of the past 180 days.\n\nScope and syntax\n----------------\n\nQueries against this view must include a [region qualifier](/bigquery/docs/information-schema-intro#syntax).\nIf you don't specify a regional qualifier, metadata is retrieved from the US\nregion. The following table explains the region scope for this view:\n\nReplace the following:\n\n- Optional: \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Google Cloud project. If not specified, the default project is used.\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: any [dataset region name](/bigquery/docs/locations). For example, ```region-us```.\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n | **Note:** You must use [a region qualifier](/bigquery/docs/information-schema-intro#region_qualifier) to query `INFORMATION_SCHEMA` views. The location of the query execution must match the region of the `INFORMATION_SCHEMA` view.\n\n\u003cbr /\u003e\n\nExamples\n--------\n\nTo run the query against a project other than your default project, add the\nproject ID in the following format:\n\n`PROJECT_ID``.``region-REGION_NAME``.INFORMATION_SCHEMA.SHARED_DATASET_USAGE`\n\nFor example, `myproject.region-us.INFORMATION_SCHEMA.SHARED_DATASET_USAGE`.\n\n### Get the total number of jobs executed on all shared tables\n\nThe following example calculates total jobs run by [subscribers](/bigquery/docs/analytics-hub-view-subscribe-listings) for a project: \n\n```googlesql\nSELECT\n COUNT(DISTINCT job_id) AS num_jobs\nFROM\n `region-us`.INFORMATION_SCHEMA.SHARED_DATASET_USAGE\n```\n\nThe result is similar to the following: \n\n```\n+------------+\n| num_jobs |\n+------------+\n| 1000 |\n+------------+\n```\n\nTo check the total jobs run by subscribers, use the `WHERE` clause:\n\n- For datasets, use `WHERE dataset_id = \"...\"`.\n- For tables, use `WHERE dataset_id = \"...\" AND table_id = \"...\"`.\n\n### Get the most used table based on the number of rows processed\n\nThe following query calculates the most used table based on the number of rows\nprocessed by subscribers. \n\n```googlesql\nSELECT\n dataset_id,\n table_id,\n SUM(num_rows_processed) AS usage_rows\nFROM\n `region-us`.INFORMATION_SCHEMA.SHARED_DATASET_USAGE\nGROUP BY\n 1,\n 2\nORDER BY\n 3 DESC\nLIMIT\n 1\n```\n\nThe output is similar to the following: \n\n```\n+---------------+-------------+----------------+\n| dataset_id | table_id | usage_rows |\n+---------------+-------------+----------------+\n| mydataset | mytable | 15 |\n+---------------+-------------+----------------+\n```\n\n### Find the top organizations that consume your tables\n\nThe following query calculates the top subscribers based on the number of bytes\nprocessed from your tables. You can also use the `num_rows_processed` column as\na metric. \n\n```googlesql\nSELECT\n subscriber_org_number,\n ANY_VALUE(subscriber_org_display_name) AS subscriber_org_display_name,\n SUM(total_bytes_processed) AS usage_bytes\nFROM\n `region-us`.INFORMATION_SCHEMA.SHARED_DATASET_USAGE\nGROUP BY\n 1\n```\n\nThe output is similar to the following: \n\n```\n+--------------------------+--------------------------------+----------------+\n|subscriber_org_number | subscriber_org_display_name | usage_bytes |\n+-----------------------------------------------------------+----------------+\n| 12345 | myorganization | 15 |\n+--------------------------+--------------------------------+----------------+\n```\n\nFor subscribers without an organization, you can use `job_project_number`\ninstead of `subscriber_org_number`.\n\n### Get usage metrics for your data exchange\n\nIf your [data exchange](/bigquery/docs/analytics-hub-introduction#data_exchanges)\nand source dataset are in different projects, follow\nthese step to view the usage metrics for your data exchange:\n\n1. Find all [listings](/bigquery/docs/analytics-hub-introduction#listings) that belong to your data exchange.\n2. Retrieve the source dataset attached to the listing.\n3. To view the usage metrics for your data exchange, use the following query:\n\n```googlesql\nSELECT\n *\nFROM\n source_project_1.`region-us`.INFORMATION_SCHEMA.SHARED_DATASET_USAGE\nWHERE\n dataset_id='source_dataset_id'\nAND data_exchange_id=\"projects/4/locations/us/dataExchanges/x1\"\nUNION ALL\nSELECT\n *\nFROM\n source_project_2.`region-us`.INFORMATION_SCHEMA.SHARED_DATASET_USAGE\nWHERE\n dataset_id='source_dataset_id'\nAND data_exchange_id=\"projects/4/locations/us/dataExchanges/x1\"\n```"]]