简体   繁体   English

使用 to_dataframe() 作为 BigQuery 管理员角色时出现 BigQuery 权限错误

[英]BigQuery Permission error when using to_dataframe() as BigQuery Admin role

I'm having a similar problem to the one stated in Google BigQuery query in Python works when using result(), but Permission issue when using to_dataframe() in that.result() works fine but to_dataframe() throws an error, but my problem shouldn't be connected to lack of permissions if my role is BigQuery Admin.我遇到了与 Python 中的Google BigQuery 查询中所述的问题类似的问题,使用 result() 时有效,但是在 that.result() 中使用 to_dataframe() 时的权限问题可以正常工作,但 to_dataframe() 会引发错误,但我的如果我的角色是 BigQuery 管理员,则问题不应与缺少权限有关。 I also have a role Editor, could that perhaps obstruct the way permissions work?我还有一个角色编辑器,这可能会妨碍权限的工作方式吗?

The answer turned out to be quite simple, though not obvious.答案很简单,虽然并不明显。 One should set create_bqstorage_client to False .应该将create_bqstorage_client设置为False

.to_dataframe(create_bqstorage_client=False)

As in the linked issue, the problem was in regards to bqstorage, however uninstalling google-cloud-bigquery-storage was not enough, as _validate_bqstorage function is checking both parameters and returns False only if both are either None or False .与链接的问题一样,问题出在 bqstorage 方面,但是卸载google-cloud-bigquery-storage还不够,因为_validate_bqstorage function 正在检查两个参数并仅在两者都是NoneFalse False

using_bqstorage_api = bqstorage_client or create_bqstorage_client
if not using_bqstorage_api:
    return False

On the side note, I've created a custom function that takes virtually the same amount of time.在旁注中,我创建了一个自定义 function,它需要几乎相同的时间。 If, for some reason, reader is still unable to use .to_dataframe , this function may be helpful如果由于某种原因,读者仍然无法使用.to_dataframe ,这个 function 可能会有所帮助

def sql_to_df(query):
    query_job = client.query(query) # API request
    results = query_job.result() # Waits for query to finish
    data = []
    for i, row in enumerate(results):
        if i==0:
            columns = list(row.keys())
        data.append(list(row.values()))
    df = pd.DataFrame(data=data, columns=columns)
    df.index += 1
    return df

在此处输入图像描述

暂无
暂无

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

相关问题 Python 中的 Google BigQuery 查询在使用 result() 时有效,但在使用 to_dataframe() 时出现权限问题 - Google BigQuery query in Python works when using result(), but Permission issue when using to_dataframe() 使用 BigQuery 存储时 golang 中的 BigQuery 可为空类型写入 API - BigQuery nullable types in golang when using BigQuery storage write API 权限被拒绝使用 API 密钥从 GAE 使用 Go 访问 Bigquery - Permission denied accessing Bigquery with Go from GAE using the API key 使用 PySpark 从 BigQuery 读取和写入数据:错误 `Failed to find data source: bigquery` - Reading and writing data from BigQuery, using PySpark: ERROR `Failed to find data source: bigquery` 在 Grafana 中使用 BigQuery 插件 - Using BigQuery plugin in Grafana 从 Google Cloud Storage 加载 csv 文件时出现 BigQuery 错误 - BigQuery error when loading csv file from Google Cloud Storage 尝试在 BigQuery 上创建表时收到“意外错误”消息 - Getting "unexpected error" message when trying to create table on BigQuery 从 Databricks 将 pyspark df 写入 BigQuery 时出错 - Error when writing pyspark df to BigQuery from Databricks 使用 Dataform 表创建时,我收到错误消息“BigQuery:获取驱动器凭据时权限被拒绝” - With Dataform table creation I get an error "BigQuery: Permission denied while getting Drive credentials" 避免 BigQuery 中的相关子查询错误 - Avoid correlated subqueries error in BigQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM