File size: 487 Bytes
7034f7f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import pyarrow.parquet as pq
import pyarrow as pa
from pathlib import Path
import numpy as np
input_dir = Path("data/")
output_dir = Path("data_sharded/")
output_dir.mkdir(exist_ok=True)
# Read all shards
table = pq.read_table(input_dir)
# Split into 64 shards
indices = np.array_split(range(len(table)), 64)
for i, idx in enumerate(indices):
if len(idx) > 0:
shard = table.slice(int(idx[0]), len(idx))
pq.write_table(shard, output_dir / f"shard_{i:04d}.parquet")
|