gpt4 book ai didi

python - 迭代 pyarrow._flight.FlightStreamReader

转载 作者:行者123 更新时间:2023-12-04 07:43:12 26 4
gpt4 key购买 nike

我如何遍历 reader ,假设它是 pyarrow._flight.FlightStreamReader目的。
可以从

reader = client.do_get(flight_info.endpoints[0].ticket, options)
整个 example.py脚本来自 https://github.com/dremio-hub/arrow-flight-client-examples/blob/main/python/example.py
目前我尝试 reader.read_pandas()这样它就会为整个 Dremio 结果生成一个数据框。不幸的是,如果查询有超过 5000 万行左右,它可能不适合数据帧/或可能没有足够的内存,我的进程就会被终止。如何遍历 reader 对象并获取块,以便我可以为每个块生成数据帧。
当我使用
for chunk in reader.read_chunk():
print(chunk.to_pandas())
对于第一个块,它只会从结果中转换/提取 3968 行并将其放入数据帧中,但对于第二个块,它是 None目的。我的例子真的有一百万行。
简而言之,我如何按照指定的块大小遍历读取器?是否可以在不将其转换为数据帧的情况下每行打印这些块?

最佳答案

我写了以下内容,效果很好

while True:
try:
batch, buf = reader.read_chunk()
yield batch
except StopIteration:
break
执行 batch.to_pandas() 的消费者函数
缺少的部分是如何配置块大小

关于python - 迭代 pyarrow._flight.FlightStreamReader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67339626/

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