在大型数据库上使用 smart_open 连接以使用 python 写入 s3
using smart_open on a large database connect to write to s3 with python
我正在尝试使用 smart_open
从数据库连接中将一个非常大的 table 转储到 s3
cur = con.cursor().execute(sql_query)
ret = cur.fetchmany(3)
with open(s3_path, 'wb', transport_params=transport_params) as fout:
while len(ret) > 0:
lines=ret = cur.fetchmany(10000)
for line in lines:
fout.write(line)
这似乎可行,只要确保将行转换为
str(line)
处理 ( ) 并添加换行符
还有,你必须
fout.write(bytes(row,'utf-8'))
我正在尝试使用 smart_open
从数据库连接中将一个非常大的 table 转储到 s3 cur = con.cursor().execute(sql_query)
ret = cur.fetchmany(3)
with open(s3_path, 'wb', transport_params=transport_params) as fout:
while len(ret) > 0:
lines=ret = cur.fetchmany(10000)
for line in lines:
fout.write(line)
这似乎可行,只要确保将行转换为
str(line)
处理 ( ) 并添加换行符
还有,你必须
fout.write(bytes(row,'utf-8'))