python - 将 BQ 查询结果下载到 Python 数据框时出现 504 Deadline Exceeded 错误
问题描述
我正在使用 Python 在 BigQuery 数据集上运行查询,然后将结果放入 Python 数据集中。查询运行正常;我可以看到在 BQ 中为数据集中的结果创建了一个临时表,但是当使用查询客户端的 to_dataset 方法时,它会因 504 Deadline Exceeded 错误而失败
client = bigquery.Client( credentials=credentials, project= projectID )
dataset = client.dataset('xxx')
table_ref = dataset.table('xxx')
JobConfig = bigquery.QueryJobConfig(destination = table_ref)
client.delete_table(table_ref, not_found_ok=True)
QueryJob = client.query(queryString, location='EU', job_config=JobConfig)
QueryJob.result()
results = client.list_rows(table_ref, timeout =100).to_dataframe()
直到最后一行,一切都运行良好。我在 list_rows 方法中添加了一个超时参数,但它没有帮助。我在安装了 Python 3.8 的 Windows 虚拟机上运行它。
(我还在我的笔记本电脑上测试了相同的代码,它工作得很好——不知道有什么不同。)
解决方案
看看: https ://github.com/googleapis/python-bigquery-storage/issues/4
这是 Windows 中的一个已知错误,“解决方案”是:
import google.cloud.bigquery_storage_v1.client
from functools import partialmethod
# Set a two hours timeout
google.cloud.bigquery_storage_v1.client.BigQueryReadClient.read_rows = partialmethod(google.cloud.bigquery_storage_v1.client.BigQueryReadClient.read_rows, timeout=3600*2)
前提是您将使用:
bqClient = bigquery.Client(credentials=credentials, project=project_id)
bq_storage_client = bigquery_storage_v1.BigQueryReadClient(credentials=credentials)
raw_training_data = bqClient.query(SOME_QUERY).to_arrow(bqstorage_client=bq_storage_client).to_pandas()
推荐阅读
- google-cloud-platform - 谷歌云 SDK 安装错误:无法更新 [/Users/username/.bash_profile]。确保您对此位置具有写入权限
- javascript - npm 不断在全球范围内安装
- python - [0,0] 表达式有什么作用?
- python - 循环列以一次比较数据框中的两列,并根据每个比较结果添加一个汇总列
- ios - 构建失败并显示“命令 PrecompileSwiftBridgingHeader 失败,退出代码为非零”
- laravel - 如何在 Laravel 中使非数据库模型具有两个属性
- android - 使用 react-native init 后如何在 expo 上运行 React-Native 应用程序?
- google-apis-explorer - 如何通过 Youtube Data API 获取 Youtube 频道页面上的“关于”部分详细信息?
- ios - 在 Apple Watch 模拟器中打开网页
- corda - 如何在通过 IntelliJ 运行 cordapp 时配置公证节点