pyarrow 可以像 fastparquet 的 file_scheme='hive' 选项一样将多个 parquet 文件写入一个文件夹吗?

Can pyarrow write multiple parquet files to a folder like fastparquet's file_scheme='hive' option?

我有一条数百万条记录 SQL table,我打算使用 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 进行多文件输出吗?

试试 pyarrow.parquet.write_to_dataset https://github.com/apache/arrow/blob/master/python/pyarrow/parquet.py#L938

我打开了 https://issues.apache.org/jira/browse/ARROW-1858 关于添加更多关于此的文档。

我建议在邮件列表 dev@arrow.apache.org 上寻求对 Apache Arrow 的支持。谢谢!