gpt4 book ai didi

python - 从 BigQuery 获取数据需要很长时间

转载 作者:行者123 更新时间:2023-12-05 08:39:23 24 4
gpt4 key购买 nike

我正在尝试从 BigQuery 获取数据。当我获取小数据时一切正常,但是当我尝试获取大数据时它会永远消失。有什么有效的方法吗?

到目前为止我正在使用这个:

import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'cred.json'
import google.auth
from google.cloud import bigquery

%load_ext google.cloud.bigquery

import google.datalab.bigquery as bq
from google.cloud.bigquery import Client

client = bigquery.Client()

这是我的 SQL 命令:

sql = """
SELECT bla, bla1, bla2
FROM table
"""
df = client.query(sql)
df.to_dataframe()

最佳答案

通过更改方法,您可以更快地将 BigQuery 数据放入数据框数量级。

检查这些选项如何反射(reflect)在图表中:

  • A:to_dataframe() - 使用 BigQuery tabledata.list API。
  • B:to_dataframe(bqstorage_client=bqstorage_client),包版本 1.16.0 - 使用具有 Avro 数据格式的 BigQuery Storage API。
  • C: to_dataframe(bqstorage_client=bqstorage_client),包版本 1.17.0 - 使用 Arrow 数据格式的 BigQuery Storage API。
  • D:to_arrow(bqstorage_client=bqstorage_client).to_pandas(),包版本 1.17.0 - 使用 Arrow 数据格式的 BigQuery Storage API。

enter image description here

请注意如何使用 to_arrow(bqstorage_client=bqstorage_client).to_pandas() 从 >500 秒减少到 ~20 秒。

参见 https://medium.com/google-cloud/announcing-google-cloud-bigquery-version-1-17-0-1fc428512171

关于python - 从 BigQuery 获取数据需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59749359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com