【发布时间】:2021-03-18 04:27:08
【问题描述】:
假设我有一个非常大的表,我想使用 pd.read_sql 和 chunksize = 10000。
我现在的处理方式是:
from sqlalchemy import create_engine
import pandas as pd
engine = create_engine('dialect://user:pass@host:port/schema')
with engine.connect() as conn:
for df in pd.read_sql('SELECT * FROM VERY_LARGE_TABLE', con=conn, chunksize=10000):
do stuff
我的问题(使用雪花作为数据源)是连接将在“做事”中途过期。
是否可以这样做:
engine = create_engine('dialect://user:pass@host:port/schema', echo=False)
# chunk 1
with engine.connect() as conn:
df = pd.read_sql('SELECT * FROM VERY_LARGE_TABLE', con=conn)
do stuff
# chunk 2
with engine.connect() as conn:
df = pd.read_sql('SELECT * FROM VERY_LARGE_TABLE', con=conn)
do stuff
我现在正在探索的替代方法是在引擎中设置connect_args={"client_session_keep_alive": True}
【问题讨论】:
标签: pandas sqlalchemy snowflake-cloud-data-platform