[英]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 正在检查两个参数并仅在两者都是None
或False
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.