在DataWorks上使用PyODPS查询只出一万条数据的限制:
阿里云的DataWorks,使用pyodps链接,并查询数据,会有只能查询一万条数据的限制。通过已下方法可以解决。
Dataworks上默认未开启instance tunnel,即instance.open_reader默认使用Result接口(最多一万条记录)。
您可以通过reader.count获取记录数。如果您需要迭代获取全部数据,则需要关闭limit
限制。您可以通过下列语句在全局范围内打开Instance Tunnel并关闭limit
限制。
在py文件开头配置上如图示代码配置:
from odps import options
options.tunnel.use_instance_tunnel = True
options.tunnel.limit_instance_tunnel = False # 关闭limit限制,读取全部数据。
with instance.open_reader() as reader:
# 通过Instance Tunnel可读取全部数据。
您也可以通过在open_reader上添加tunnel=True
,实现仅对本次open_reader开启instance tunnel。同时,您还可以添加 limit=False
,实现仅对本次关闭limit
限制。
with instance.open_reader(tunnel=True, limit=False) as reader:
# 本次open_reader使用Instance Tunnel接口,且能读取全部数据。