【发布时间】:2023-03-26 19:21:01
【问题描述】:
from google.cloud import bigquery as bq
import google_auth_oauthlib.flow
query = '''select ... from ...'''
bigquery_client = bq.Client()
table = bq.query.QueryResults(query=query,client=bigquery_client)
table.use_legacy_sql = False
table.run()
# transfer bigquery data to pandas dataframe
columns=[field.name for field in table.schema]
rows = table.fetch_data()
data = []
for row in rows:
data.append(row)
df = pd.DataFrame(data=data[0],columns=columns)
我想将超过 1000 万行加载到 python 中,几周前它运行良好,但现在它只返回 100,000 行。有人知道这样做的可靠方法吗?
【问题讨论】:
-
我也尝试了 async_query.py,并使用 rows = query_job.results().fetch_data(max_results=1000000)。但似乎他们在某个地方设置了 100,000 的上限。有没有办法覆盖上限?或更有效的方式来执行大查询到 python 计算。
-
只是想知道,您是否在 WebUI 或 CLI 中运行此查询以查看它是否返回您期望的总行数?
-
我在 CLI 中运行过,行数只有 100,000。所以截止点可能在 table.run() 或 table.fetch_data()。
-
如果 CLI 也返回 100k,那么看起来这实际上就是您的表中的所有内容。看起来问题出在您的表格中,而不是在带来数据时达到某个阈值。
-
我在 UI 中运行了相同的查询,它返回超过 3900 万。但是使用 python 程序,更难诊断截止发生的位置。
标签: python google-bigquery google-cloud-platform google-python-api