7

是否可以在将镶木地板文件写入时使用表中的时间戳字段通过“”对文件系统pyarrow进行分区?s3fsYYYY/MM/DD/HHs3

4

2 回答 2

5

我能够使用 pyarrow write_to_dataset 函数来实现,该函数允许您指定分区列来创建子目录。

例子:

import os
import s3fs
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
from pyarrow.filesystem import S3FSWrapper

access_key = <access_key>
secret_key = <secret_key>
bucket_name = <bucket_name>

fs = s3fs.S3FileSystem(key=access_key, secret=secret_key)

bucket_uri = 's3://{0}/{1}'.format(bucket_name, "data")

data = {'date': ['2018-03-04T14:12:15.653Z', '2018-03-03T14:12:15.653Z', '2018-03-02T14:12:15.653Z', '2018-03-05T14:12:15.653Z'],
        'battles': [34, 25, 26, 57],
        'citys': ['london', 'newyork', 'boston', 'boston']}
df = pd.DataFrame(data, columns=['date', 'battles', 'citys'])
df['date'] = df['date'].map(lambda t: pd.to_datetime(t, format="%Y-%m-%dT%H:%M:%S.%fZ"))
df['year'], df['month'], df['day'] = df['date'].apply(lambda x: x.year), df['date'].apply(lambda x: x.month), df['date'].apply(lambda x: x.day)
df.groupby(by=['citys'])
table = pa.Table.from_pandas(df)
pq.write_to_dataset(table, bucket_uri, filesystem=fs, partition_cols=['year', 'month', 'day'], use_dictionary=True,  compression='snappy', use_deprecated_int96_timestamps=True)
于 2018-03-05T13:36:29.390 回答
0

据我所知:没有。

它可以读取分区数据,但与写入无关。

有几个地方记录了写入功能,但没有一个地方采用分区选项。

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

https://github.com/apache/arrow/blob/master/python/pyarrow/parquet.py#L941

https://issues.apache.org/jira/browse/ARROW-1858

于 2018-03-04T00:17:25.800 回答