繁体   English   中英

使用 google-cloud-bigquery 客户端库 (Python) 从 BigQuery 读取时发生 ArrowIOError

[英]ArrowIOError occurred reading from BigQuery with google-cloud-bigquery client library (Python)

我有一个 function 来检索 pandas dataframe 从对 BigQuery 的查询中检索到,这在过去几个月中运行良好。 今天,在没有任何更改的情况下,它在 GoogleColab Notebooks 中停止工作并抛出此异常:

从 BigQuery 读取时发生了 ArrowIOError 类型的异常。 Arguments:('无法从 BufferReader 读取负数字节。',)

我的代码:

def read_from_bigquery_client(bq_client, project_id, sql, curr_func):
  try:
    df = bq_client.query(sql, project=project_id).to_dataframe()
    return df
  except Exception as ex:
    template = "An exception of type {0} occurred reading from BigQuery. Arguments:\n{1!r}\nFunction: {2}"
    message = template.format(type(ex).__name__, ex.args, curr_func)
    print(message)
    return None

客户端认证:

credentials = service_account.Credentials.from_service_account_file(local_cred_filename)
bq_client = bigquery.Client(credentials=credentials,
                            project=credentials.project_id)

当直接应用于 BigQuery 时,我尝试过的查询可以完美地工作,而且它们之前也可以像上面提到的那样工作。

谢谢您的帮助。

google-cloud-bigquery Python 库的新版本(1.26.0) 已于 7 月 22 日发布。 可能会出现尚未检测到的问题。 Github已经报告了相应版本的类似问题,您可以在其中关注更新。 此外,请同时报告您遇到的错误。

就目前而言, ArrowIOError的解决方法是降级google-cloud-bigquery库的版本。

我将google-cloud-bigquery的版本降级为 1.24.0,但错误仍然完好无损。 其他版本是:

pyarrow==0.11.1
pandas==0.23.4
pandas-gbq==0.7.0
google-cloud-bigquery==1.24.0

在升级我的 pandas package 之前,我遇到了同样的问题,这显然是我从文档中看到的, google-cloud-bigquery的版本高于 0.29。

更新 pandas 的最佳方法是:

pip3 install --upgrade pandas

暂无
暂无

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

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