首页 文章

pyarrow可以将多个镶木地板文件写入fastparquet 's file_scheme=' hive'选项这样的文件夹吗?

提问于
浏览
3

我有一个数百万的记录SQL表,我打算使用pyarrow库写出文件夹中的许多镶木地板文件 . 数据内容似乎太大而无法存储在单个拼花文件中 .

但是,我似乎无法找到pyarrow库的API或参数,允许我指定类似的东西:

file_scheme="hive"

由fastparquet python库支持 .

这是我的示例代码:

#!/usr/bin/python

import pyodbc
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq

conn_str = 'UID=username;PWD=passwordHere;' + 
    'DRIVER=FreeTDS;SERVERNAME=myConfig;DATABASE=myDB'

#----> Query the SQL database into a Pandas dataframe
conn = pyodbc.connect( conn_str, autocommit=False)
sql = "SELECT * FROM ClientAccount (NOLOCK)"
df = pd.io.sql.read_sql(sql, conn)


#----> Convert the dataframe to a pyarrow table and write it out
table = pa.Table.from_pandas(df)
pq.write_table(table, './clients/' )

这会引发错误:

File "/usr/local/lib/python2.7/dist-packages/pyarrow/parquet.py", line 912, in write_table
    os.remove(where)
OSError: [Errno 21] Is a directory: './clients/'

如果我用以下内容替换最后一行,它可以正常工作,但只写一个大文件:

pq.write_table(table, './clients.parquet' )

有什么想法我怎么能用pyarrow做多文件输出的东西?

1 回答

相关问题