简体   繁体   English

如何在 Databricks/Spark 中读取 Google BigQuery 查看数据

[英]How can I read Google BigQuery View data in Databricks/Spark

How can I read Google BigQuery view data in spark?如何在 Spark 中读取 Google BigQuery 视图数据? I am able to read data from Google BigQuery tables using Service Account Authentication by using below query我可以使用以下查询使用服务帐户身份验证从 Google BigQuery 表中读取数据

df = (spark.read.format("bigquery").option("credentialsFile",credentialfilepath)
      .option("parentProject",projectName)
      .option("table",ViewName)
      .load())

But I am not able to read view data by using this, also I have applies other options as well like .option("viewsEnabled", "true") and .option("materializationDataset","dataplatform") but It is giving the error:但是我无法通过使用它来读取视图数据,而且我还应用了其他选项,例如.option("viewsEnabled", "true").option("materializationDataset","dataplatform")但它给出了错误:

com.google.cloud.spark.bigquery.repackaged.com.google.cloud.bigquery.BigQueryException: Access Denied: Project projectname: User does not have bigquery.jobs.create permission in project projectname com.google.cloud.spark.bigquery.repackaged.com.google.cloud.bigquery.BigQueryException:访问被拒绝:项目项目名称:用户在项目项目名称中没有 bigquery.jobs.create 权限

Can anyone suggest the way to read view data?任何人都可以建议读取视图数据的方法吗?

Providing the proper roles for the service account used for authentication solved the problem.为用于身份验证的服务帐户提供适当的角色解决了这个问题。 See steps below on adding the roles to the service account used for authentication:请参阅以下有关将角色添加到用于身份验证的服务帐户的步骤:

  1. Open Google Cloud Console打开谷歌云控制台

  2. Go to IAM & Admin > IAM.转到 IAM 和管理 > IAM。 Look for the service account to be used.查找要使用的服务帐户。

  3. When a service account is identified, click the edit button (pencil icon) at the right side.识别出服务帐户后,单击右侧的编辑按钮(铅笔图标)。

  4. Click "+ Add Another Role" and add the following roles点击“+ 添加另一个角色”,添加以下角色

    • BigQuery Data editor BigQuery 数据编辑器
    • BigQuery Job User BigQuery 作业用户
    • BigQuery Data Viewer BigQuery 数据查看器
    • BigQuery Read Session User BigQuery 读取会话用户
    • Storage Object Admin存储对象管理员

    在此处输入图像描述

  5. Click Save点击保存

  6. Run the spark code provided in the question运行问题中提供的火花代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM